Browse Source
Assert the result stream is positioned at the start in SkiaSharp tests
Existing tests only checked Result.Length which doesn't depend on
Position, so a contributor that forgot to seek the result stream back
to 0 would still pass. Add an explicit Position == 0 assertion plus a
CopyToAsync round-trip that compares the copied length against the
result stream length, so the same regression cannot slip in again.
pull/25427/head
maliming
5 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
34 additions and
0 deletions
framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs
framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs
@ -93,6 +93,23 @@ public class SkiaSharpImageCompressorTests : AbpImagingSkiaSharpTestBase
compressedImage1 . Result . Dispose ( ) ;
compressedImage1 . Result . Dispose ( ) ;
}
}
[Fact]
public async Task Should_Return_Compressed_Stream_Positioned_At_Start ( )
{
await using var jpegImage = ImageFileHelper . GetJpgTestFileStream ( ) ;
var compressedImage = await ImageCompressor . CompressAsync ( jpegImage ) ;
compressedImage . ShouldNotBeNull ( ) ;
compressedImage . State . ShouldBe ( ImageProcessState . Done ) ;
compressedImage . Result . Position . ShouldBe ( 0 ) ;
using var copy = new MemoryStream ( ) ;
await compressedImage . Result . CopyToAsync ( copy ) ;
copy . Length . ShouldBe ( compressedImage . Result . Length ) ;
compressedImage . Result . Dispose ( ) ;
}
[Fact]
[Fact]
public async Task Should_Return_Unsupported_For_Gif_Stream ( )
public async Task Should_Return_Unsupported_For_Gif_Stream ( )
{
{
@ -73,6 +73,23 @@ public class SkiaSharpImageResizerTests : AbpImagingSkiaSharpTestBase
resizedImage1 . Result . Dispose ( ) ;
resizedImage1 . Result . Dispose ( ) ;
}
}
[Fact]
public async Task Should_Return_Resized_Stream_Positioned_At_Start ( )
{
await using var jpegImage = ImageFileHelper . GetJpgTestFileStream ( ) ;
var resizedImage = await ImageResizer . ResizeAsync ( jpegImage , new ImageResizeArgs ( 1 0 0 , 1 0 0 ) ) ;
resizedImage . ShouldNotBeNull ( ) ;
resizedImage . State . ShouldBe ( ImageProcessState . Done ) ;
resizedImage . Result . Position . ShouldBe ( 0 ) ;
using var copy = new MemoryStream ( ) ;
await resizedImage . Result . CopyToAsync ( copy ) ;
copy . Length . ShouldBe ( resizedImage . Result . Length ) ;
resizedImage . Result . Dispose ( ) ;
}
[Fact]
[Fact]
public async Task Should_Return_Unsupported_For_Gif_Stream ( )
public async Task Should_Return_Unsupported_For_Gif_Stream ( )
{
{