namespace SixLabors.ImageSharp.Tests { using System; using System.IO; using Moq; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.PixelFormats; public partial class ImageTests { public abstract class ImageLoadTestBase : IDisposable { protected Image returnImage; protected Mock localDecoder; protected IImageFormatDetector localMimeTypeDetector; protected Mock localImageFormatMock; public Configuration LocalConfiguration { get; } public TestFormat TestFormat { get; } = new TestFormat(); /// /// Gets the top-level configuration in the context of this test case. /// It has registered. /// public Configuration TopLevelConfiguration { get; } public byte[] Marker { get; private set; } public MemoryStream DataStream { get; private set; } public byte[] DecodedData { get; private set; } protected ImageLoadTestBase() { this.returnImage = new Image(1, 1); this.localImageFormatMock = new Mock(); this.localDecoder = new Mock(); this.localMimeTypeDetector = new MockImageFormatDetector(this.localImageFormatMock.Object); this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny())) .Callback((c, s) => { using (var ms = new MemoryStream()) { s.CopyTo(ms); this.DecodedData = ms.ToArray(); } }) .Returns(this.returnImage); this.LocalConfiguration = new Configuration { }; this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); this.LocalConfiguration.ImageFormatsManager.SetDecoder(this.localImageFormatMock.Object, this.localDecoder.Object); this.TopLevelConfiguration = new Configuration(this.TestFormat); this.Marker = Guid.NewGuid().ToByteArray(); this.DataStream = this.TestFormat.CreateStream(this.Marker); } public void Dispose() { // clean up the global object; this.returnImage?.Dispose(); } } } }