From d1e003833df0e60e0e5f5af38b32bdfb98dea5a1 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 14 May 2026 14:32:01 +0800 Subject: [PATCH] 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. --- .../Imaging/SkiaSharpImageCompressorTests.cs | 17 +++++++++++++++++ .../Abp/Imaging/SkiaSharpImageResizerTests.cs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs b/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs index dcc1427d55..0f72658148 100644 --- a/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs +++ b/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageCompressorTests.cs @@ -93,6 +93,23 @@ public class SkiaSharpImageCompressorTests : AbpImagingSkiaSharpTestBase 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] public async Task Should_Return_Unsupported_For_Gif_Stream() { diff --git a/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs b/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs index 38cdf34059..ecc2c2dd79 100644 --- a/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs +++ b/framework/test/Volo.Abp.Imaging.SkiaSharp.Tests/Volo/Abp/Imaging/SkiaSharpImageResizerTests.cs @@ -73,6 +73,23 @@ public class SkiaSharpImageResizerTests : AbpImagingSkiaSharpTestBase 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] public async Task Should_Return_Unsupported_For_Gif_Stream() {