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
parent
commit
d1e003833d
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 17
      framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs
  2. 17
      framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs

17
framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.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()
{ {

17
framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs

@ -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(100, 100));
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()
{ {

Loading…
Cancel
Save