|
|
|
@ -25,8 +25,15 @@ public partial class ImageTests |
|
|
|
|
|
|
|
private IImageFormat LocalImageFormat => this.localImageFormatMock.Object; |
|
|
|
|
|
|
|
private static readonly IImageFormat ExpectedGlobalFormat = |
|
|
|
Configuration.Default.ImageFormatsManager.FindFormatByFileExtension("bmp"); |
|
|
|
private static IImageFormat ExpectedGlobalFormat |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
Configuration.Default.ImageFormatsManager.TryFindFormatByFileExtension("bmp", out var format); |
|
|
|
return format!; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void FromBytes_GlobalConfiguration() |
|
|
|
@ -40,10 +47,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public void FromBytes_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
IImageInfo info = Image.Identify(options, this.ByteArray, out IImageFormat type); |
|
|
|
|
|
|
|
@ -63,10 +67,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public void FromFileSystemPath_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
IImageInfo info = Image.Identify(options, this.MockFilePath, out IImageFormat type); |
|
|
|
|
|
|
|
@ -119,10 +120,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public void FromStream_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
IImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); |
|
|
|
|
|
|
|
@ -133,10 +131,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public void FromStream_CustomConfiguration_NoFormat() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
IImageInfo info = Image.Identify(options, this.DataStream); |
|
|
|
|
|
|
|
@ -146,10 +141,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public void WhenNoMatchingFormatFound_ReturnsNull() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = new() |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = new() }; |
|
|
|
|
|
|
|
IImageInfo info = Image.Identify(options, this.DataStream, out IImageFormat type); |
|
|
|
|
|
|
|
@ -164,18 +156,15 @@ public partial class ImageTests |
|
|
|
using var zipFile = new ZipArchive(new MemoryStream( |
|
|
|
new byte[] |
|
|
|
{ |
|
|
|
0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0xAF, |
|
|
|
0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x6D, 0x79, 0x73, 0x74, 0x65, 0x72, |
|
|
|
0x79, 0x50, 0x4B, 0x01, 0x02, 0x3F, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6D, |
|
|
|
0x79, 0x73, 0x74, 0x65, 0x72, 0x79, 0x0A, 0x00, 0x20, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x46, 0x82, 0xFF, 0x91, 0x27, 0xF6, |
|
|
|
0xD7, 0x01, 0x55, 0xA1, 0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, |
|
|
|
0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x50, 0x4B, 0x05, 0x06, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x59, 0x00, 0x00, 0x00, 0x25, 0x00, |
|
|
|
0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x6D, 0x79, |
|
|
|
0x73, 0x74, 0x65, 0x72, 0x79, 0x50, 0x4B, 0x01, 0x02, 0x3F, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x07, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x6D, 0x79, 0x73, 0x74, 0x65, 0x72, 0x79, 0x0A, 0x00, 0x20, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x46, 0x82, 0xFF, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, |
|
|
|
0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, 0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x50, 0x4B, |
|
|
|
0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x59, 0x00, 0x00, 0x00, 0x25, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00 |
|
|
|
})); |
|
|
|
using Stream stream = zipFile.Entries[0].Open(); |
|
|
|
@ -236,18 +225,15 @@ public partial class ImageTests |
|
|
|
using var zipFile = new ZipArchive(new MemoryStream( |
|
|
|
new byte[] |
|
|
|
{ |
|
|
|
0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0xAF, |
|
|
|
0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x6D, 0x79, 0x73, 0x74, 0x65, 0x72, |
|
|
|
0x79, 0x50, 0x4B, 0x01, 0x02, 0x3F, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6D, |
|
|
|
0x79, 0x73, 0x74, 0x65, 0x72, 0x79, 0x0A, 0x00, 0x20, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x46, 0x82, 0xFF, 0x91, 0x27, 0xF6, |
|
|
|
0xD7, 0x01, 0x55, 0xA1, 0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, |
|
|
|
0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x50, 0x4B, 0x05, 0x06, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x59, 0x00, 0x00, 0x00, 0x25, 0x00, |
|
|
|
0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x6D, 0x79, |
|
|
|
0x73, 0x74, 0x65, 0x72, 0x79, 0x50, 0x4B, 0x01, 0x02, 0x3F, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x77, 0xAF, 0x94, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x07, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x6D, 0x79, 0x73, 0x74, 0x65, 0x72, 0x79, 0x0A, 0x00, 0x20, 0x00, 0x00, 0x00, |
|
|
|
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x46, 0x82, 0xFF, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, |
|
|
|
0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x55, 0xA1, 0xF9, 0x91, 0x27, 0xF6, 0xD7, 0x01, 0x50, 0x4B, |
|
|
|
0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x59, 0x00, 0x00, 0x00, 0x25, 0x00, |
|
|
|
0x00, 0x00, 0x00, 0x00 |
|
|
|
})); |
|
|
|
using Stream stream = zipFile.Entries[0].Open(); |
|
|
|
@ -258,10 +244,7 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public async Task FromPathAsync_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
IImageInfo info = await Image.IdentifyAsync(options, this.MockFilePath); |
|
|
|
Assert.Equal(this.LocalImageInfo, info); |
|
|
|
@ -270,12 +253,10 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public async Task IdentifyWithFormatAsync_FromPath_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, this.MockFilePath); |
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) info = |
|
|
|
await Image.IdentifyWithFormatAsync(options, this.MockFilePath); |
|
|
|
Assert.NotNull(info.ImageInfo); |
|
|
|
Assert.Equal(this.LocalImageFormat, info.Format); |
|
|
|
} |
|
|
|
@ -300,13 +281,11 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public async Task FromStreamAsync_CustomConfiguration() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = this.LocalConfiguration |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = this.LocalConfiguration }; |
|
|
|
|
|
|
|
var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); |
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, asyncStream); |
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) |
|
|
|
info = await Image.IdentifyWithFormatAsync(options, asyncStream); |
|
|
|
|
|
|
|
Assert.Equal(this.LocalImageInfo, info.ImageInfo); |
|
|
|
Assert.Equal(this.LocalImageFormat, info.Format); |
|
|
|
@ -315,13 +294,11 @@ public partial class ImageTests |
|
|
|
[Fact] |
|
|
|
public async Task WhenNoMatchingFormatFoundAsync_ReturnsNull() |
|
|
|
{ |
|
|
|
DecoderOptions options = new() |
|
|
|
{ |
|
|
|
Configuration = new() |
|
|
|
}; |
|
|
|
DecoderOptions options = new() { Configuration = new() }; |
|
|
|
|
|
|
|
var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); |
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) info = await Image.IdentifyWithFormatAsync(options, asyncStream); |
|
|
|
(IImageInfo ImageInfo, IImageFormat Format) |
|
|
|
info = await Image.IdentifyWithFormatAsync(options, asyncStream); |
|
|
|
|
|
|
|
Assert.Null(info.ImageInfo); |
|
|
|
} |
|
|
|
|