diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs index 641b0c8109..83aeed5bdc 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.Identify.cs @@ -21,12 +21,6 @@ public partial class ImageTests private static byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; - private ImageInfo LocalImageInfo => new( - this.localImageInfoMock.Object.PixelType, - this.localImageInfoMock.Object.Width, - this.localImageInfoMock.Object.Height, - this.localImageInfoMock.Object.Metadata); - private IImageFormat LocalImageFormat => this.localImageFormatMock.Object; private static IImageFormat ExpectedGlobalFormat @@ -61,7 +55,7 @@ public partial class ImageTests [Fact] public void FromFileSystemPath_GlobalConfiguration() { - ImageInfo info = Image.Identify(ActualImagePath, out IImageFormat type); + ImageInfo info = Image.TryIdentify(ActualImagePath, out IImageFormat type); Assert.NotNull(info); Assert.Equal(ExpectedGlobalFormat, type); @@ -136,7 +130,7 @@ public partial class ImageTests { DecoderOptions options = new() { Configuration = this.LocalConfiguration }; - ImageInfo info = Image.Identify(options, this.DataStream); + ImageInfo info = Image.TryIdentify(options, this.DataStream); Assert.Equal(this.LocalImageInfo, info); } @@ -190,7 +184,7 @@ public partial class ImageTests { using var stream = new MemoryStream(ActualImageBytes); var asyncStream = new AsyncStreamWrapper(stream, () => false); - (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.TryIdentifyAsync(asyncStream); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -215,7 +209,7 @@ public partial class ImageTests using var nonSeekableStream = new NonSeekableStream(stream); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); - (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.TryIdentifyAsync(asyncStream); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -259,7 +253,7 @@ public partial class ImageTests DecoderOptions options = new() { Configuration = this.LocalConfiguration }; (ImageInfo ImageInfo, IImageFormat Format) info = - await Image.IdentifyWithFormatAsync(options, this.MockFilePath); + await Image.TryIdentifyAsync(options, this.MockFilePath); Assert.NotNull(info.ImageInfo); Assert.Equal(this.LocalImageFormat, info.Format); } @@ -267,7 +261,7 @@ public partial class ImageTests [Fact] public async Task IdentifyWithFormatAsync_FromPath_GlobalConfiguration() { - (ImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(ActualImagePath); + (ImageInfo ImageInfo, IImageFormat Format) res = await Image.TryIdentifyAsync(ActualImagePath); Assert.Equal(ExpectedImageSize, res.ImageInfo.Size()); Assert.Equal(ExpectedGlobalFormat, res.Format); @@ -288,7 +282,7 @@ public partial class ImageTests var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); (ImageInfo ImageInfo, IImageFormat Format) - info = await Image.IdentifyWithFormatAsync(options, asyncStream); + info = await Image.TryIdentifyAsync(options, asyncStream); Assert.Equal(this.LocalImageInfo, info.ImageInfo); Assert.Equal(this.LocalImageFormat, info.Format); @@ -301,7 +295,7 @@ public partial class ImageTests var asyncStream = new AsyncStreamWrapper(this.DataStream, () => false); (ImageInfo ImageInfo, IImageFormat Format) - info = await Image.IdentifyWithFormatAsync(options, asyncStream); + info = await Image.TryIdentifyAsync(options, asyncStream); Assert.Null(info.ImageInfo); } diff --git a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs index 203f132797..235ea2d92c 100644 --- a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs +++ b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs @@ -51,6 +51,12 @@ public partial class ImageTests protected byte[] ByteArray => ((MemoryStream)this.DataStream).ToArray(); + protected ImageInfo LocalImageInfo => new( + this.localImageInfoMock.Object.PixelType, + this.localImageInfoMock.Object.Width, + this.localImageInfoMock.Object.Height, + this.localImageInfoMock.Object.Metadata); + protected ImageLoadTestBase() { this.localStreamReturnImageRgba32 = new Image(1, 1); @@ -61,18 +67,10 @@ public partial class ImageTests this.localDecoder = new Mock(); this.localDecoder.Setup(x => x.Identify(It.IsAny(), It.IsAny())) - .Returns(() => - { - IImageInfo info = this.localImageInfoMock.Object; - return new ImageInfo(info.PixelType, info.Width, info.Height, info.Metadata); - }); + .Returns(this.LocalImageInfo); this.localDecoder.Setup(x => x.IdentifyAsync(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(() => - { - IImageInfo info = this.localImageInfoMock.Object; - return Task.FromResult(new ImageInfo(info.PixelType, info.Width, info.Height, info.Metadata)); - }); + .Returns(Task.FromResult(this.LocalImageInfo)); this.localDecoder .Setup(x => x.Decode(It.IsAny(), It.IsAny()))