mirror of https://github.com/abpframework/abp.git
15 changed files with 516 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||
{ |
|||
"role": "lib.test" |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.test.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net7.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Imaging.Abstractions\Volo.Abp.Imaging.Abstractions.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Imaging.ImageSharp\Volo.Abp.Imaging.ImageSharp.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Imaging.MagickNet\Volo.Abp.Imaging.MagickNet.csproj" /> |
|||
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="Volo\Abp\Imaging\Files\**" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -0,0 +1,105 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Testing; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public abstract class AbpImagingAbstractionsTestBase : AbpIntegratedTest<AbpImagingAbstractionsTestModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
|
|||
public class IIImageResizer_Tests : AbpImagingAbstractionsTestBase |
|||
{ |
|||
protected IImageResizer ImageResizer { get; } |
|||
|
|||
public IIImageResizer_Tests() |
|||
{ |
|||
ImageResizer = GetRequiredService<IImageResizer>(); |
|||
} |
|||
[Fact] |
|||
public async Task Should_Resize_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(jpegImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
resizedImage.Result.ShouldBe(jpegImage); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(pngImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
resizedImage.Result.ShouldBe(pngImage); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(webpImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
resizedImage.Result.ShouldBe(webpImage); |
|||
} |
|||
} |
|||
|
|||
public class IIImageCompressor_Tests : AbpImagingAbstractionsTestBase |
|||
{ |
|||
protected IImageCompressor ImageCompressor { get; } |
|||
|
|||
public IIImageCompressor_Tests() |
|||
{ |
|||
ImageCompressor = GetRequiredService<IImageCompressor>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(jpegImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
compressedImage.Result.ShouldBe(jpegImage); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(pngImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
compressedImage.Result.ShouldBe(pngImage); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(webpImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
|
|||
compressedImage.Result.ShouldBe(webpImage); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpImagingAbstractionsModule), |
|||
typeof(AbpTestBaseModule) |
|||
)] |
|||
public class AbpImagingAbstractionsTestModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,139 @@ |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public abstract class AbpImagingImageSharpProviderTestBase : AbpImagingImageSharpTestBase |
|||
{ |
|||
protected IImageCompressor ImageCompressor { get; } |
|||
protected IImageResizer ImageResizer { get; } |
|||
|
|||
public AbpImagingImageSharpProviderTestBase() |
|||
{ |
|||
ImageCompressor = GetRequiredService<IImageCompressor>(); |
|||
ImageResizer = GetRequiredService<IImageResizer>(); |
|||
} |
|||
} |
|||
|
|||
public class ImageSharpImageCompressor_Tests : AbpImagingImageSharpProviderTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Compress_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(jpegImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Done); |
|||
compressedImage.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
compressedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(pngImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Done); |
|||
compressedImage.Result.Length.ShouldBeLessThan(pngImage.Length); |
|||
compressedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(webpImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Done); |
|||
compressedImage.Result.Length.ShouldBeLessThan(webpImage.Length); |
|||
compressedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Stream_And_Byte_Array_The_Same() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var byteArr = await jpegImage.GetAllBytesAsync(); |
|||
|
|||
var compressedImage1 = await ImageCompressor.CompressAsync(jpegImage); |
|||
var compressedImage2 = await ImageCompressor.CompressAsync(byteArr); |
|||
|
|||
compressedImage1.ShouldNotBeNull(); |
|||
compressedImage1.State.ShouldBe(ProcessState.Done); |
|||
|
|||
compressedImage2.ShouldNotBeNull(); |
|||
compressedImage2.State.ShouldBe(ProcessState.Done); |
|||
|
|||
compressedImage1.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
compressedImage2.Result.LongLength.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
compressedImage1.Result.Length.ShouldBe(compressedImage2.Result.LongLength); |
|||
|
|||
compressedImage1.Result.Dispose(); |
|||
} |
|||
} |
|||
|
|||
public class ImageSharpImageResizer_Tests : AbpImagingImageSharpProviderTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Resize_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(jpegImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(pngImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(pngImage.Length); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(webpImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(webpImage.Length); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Stream_And_Byte_Array_The_Same() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var byteArr = await jpegImage.GetAllBytesAsync(); |
|||
|
|||
var resizedImage1 = await ImageResizer.ResizeAsync(jpegImage, new ImageResizeArgs(100, 100)); |
|||
var resizedImage2 = await ImageResizer.ResizeAsync(byteArr, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage1.ShouldNotBeNull(); |
|||
resizedImage1.State.ShouldBe(ProcessState.Done); |
|||
|
|||
resizedImage2.ShouldNotBeNull(); |
|||
resizedImage2.State.ShouldBe(ProcessState.Done); |
|||
|
|||
resizedImage1.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
resizedImage2.Result.LongLength.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
resizedImage1.Result.Length.ShouldBe(resizedImage2.Result.LongLength); |
|||
|
|||
resizedImage1.Result.Dispose(); |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public abstract class AbpImagingImageSharpTestBase : AbpIntegratedTest<AbpImagingImageSharpTestModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpImagingImageSharpModule), |
|||
typeof(AbpTestBaseModule) |
|||
)] |
|||
|
|||
public class AbpImagingImageSharpTestModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,141 @@ |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public abstract class AbpImagingMagickNetProviderTestBase : AbpImagingMagickNetTestBase |
|||
{ |
|||
protected IImageCompressor ImageCompressor { get; } |
|||
protected IImageResizer ImageResizer { get; } |
|||
|
|||
public AbpImagingMagickNetProviderTestBase() |
|||
{ |
|||
ImageCompressor = GetRequiredService<IImageCompressor>(); |
|||
ImageResizer = GetRequiredService<IImageResizer>(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public class MagickNetImageCompressor_Tests : AbpImagingMagickNetProviderTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Compress_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(jpegImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Done); |
|||
compressedImage.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
compressedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(pngImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Done); |
|||
compressedImage.Result.Length.ShouldBeLessThan(pngImage.Length); |
|||
|
|||
compressedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var compressedImage = await ImageCompressor.CompressAsync(webpImage); |
|||
|
|||
compressedImage.ShouldNotBeNull(); |
|||
compressedImage.State.ShouldBe(ProcessState.Unsupported); |
|||
compressedImage.Result.ShouldBe(webpImage); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Compress_Stream_And_Byte_Array_The_Same() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var compressedImage1 = await ImageCompressor.CompressAsync(jpegImage); |
|||
var compressedImage2 = await ImageCompressor.CompressAsync(await jpegImage.GetAllBytesAsync()); |
|||
|
|||
compressedImage1.ShouldNotBeNull(); |
|||
compressedImage1.State.ShouldBe(ProcessState.Done); |
|||
compressedImage1.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
compressedImage2.ShouldNotBeNull(); |
|||
compressedImage2.State.ShouldBe(ProcessState.Done); |
|||
compressedImage2.Result.LongLength.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
compressedImage1.Result.Length.ShouldBe(compressedImage2.Result.LongLength); |
|||
|
|||
compressedImage1.Result.Dispose(); |
|||
} |
|||
} |
|||
|
|||
public class MagickNetImageResizer_Tests : AbpImagingMagickNetProviderTestBase |
|||
{ |
|||
[Fact] |
|||
public async Task Should_Resize_Jpg() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(jpegImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
resizedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Png() |
|||
{ |
|||
await using var pngImage = ImageFileHelper.GetPngTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(pngImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(pngImage.Length); |
|||
|
|||
resizedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Webp() |
|||
{ |
|||
await using var webpImage = ImageFileHelper.GetWebpTestFileStream(); |
|||
var resizedImage = await ImageResizer.ResizeAsync(webpImage, new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage.ShouldNotBeNull(); |
|||
resizedImage.State.ShouldBe(ProcessState.Done); |
|||
resizedImage.Result.Length.ShouldBeLessThan(webpImage.Length); |
|||
|
|||
resizedImage.Result.Dispose(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Resize_Stream_And_Byte_Array_The_Same() |
|||
{ |
|||
await using var jpegImage = ImageFileHelper.GetJpgTestFileStream(); |
|||
var resizedImage1 = await ImageResizer.ResizeAsync(jpegImage, new ImageResizeArgs(100, 100)); |
|||
var resizedImage2 = await ImageResizer.ResizeAsync(await jpegImage.GetAllBytesAsync(), new ImageResizeArgs(100, 100)); |
|||
|
|||
resizedImage1.ShouldNotBeNull(); |
|||
resizedImage1.State.ShouldBe(ProcessState.Done); |
|||
resizedImage1.Result.Length.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
resizedImage2.ShouldNotBeNull(); |
|||
resizedImage2.State.ShouldBe(ProcessState.Done); |
|||
resizedImage2.Result.LongLength.ShouldBeLessThan(jpegImage.Length); |
|||
|
|||
resizedImage1.Result.Length.ShouldBe(resizedImage2.Result.LongLength); |
|||
|
|||
resizedImage1.Result.Dispose(); |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.Testing; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public abstract class AbpImagingMagickNetTestBase : AbpIntegratedTest<AbpImagingMagickNetTestModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpImagingMagickNetModule), |
|||
typeof(AbpTestBaseModule) |
|||
)] |
|||
public class AbpImagingMagickNetTestModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 464 KiB |
|
After Width: | Height: | Size: 66 KiB |
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace Volo.Abp.Imaging; |
|||
|
|||
public static class ImageFileHelper |
|||
{ |
|||
public static Stream GetJpgTestFileStream() |
|||
{ |
|||
return GetTestFileStream("abp.jpg"); |
|||
} |
|||
|
|||
public static Stream GetPngTestFileStream() |
|||
{ |
|||
return GetTestFileStream("abp.png"); |
|||
} |
|||
|
|||
public static Stream GetWebpTestFileStream() |
|||
{ |
|||
return GetTestFileStream("abp.webp"); |
|||
} |
|||
|
|||
private static Stream GetTestFileStream(string fileName) |
|||
{ |
|||
var assembly = typeof(ImageFileHelper).Assembly; |
|||
var resourceStream = assembly.GetManifestResourceStream("Volo.Abp.Imaging.Files." + fileName); |
|||
if (resourceStream == null) |
|||
{ |
|||
throw new Exception($"File {fileName} does not exists!"); |
|||
} |
|||
|
|||
return resourceStream; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue