public DiscoverImageFormatTests() { this.localImageFormatMock = new Mock <IImageFormat>(); this.localMimeTypeDetector = new Mock <IImageFormatDetector>(); this.localMimeTypeDetector.Setup(x => x.HeaderSize).Returns(1); this.localMimeTypeDetector.Setup(x => x.DetectFormat(It.IsAny <ReadOnlySpan <byte> >())).Returns(localImageFormatMock.Object); this.fileSystem = new Mock <IFileSystem>(); this.LocalConfiguration = new Configuration() { FileSystem = this.fileSystem.Object }; this.LocalConfiguration.AddImageFormatDetector(this.localMimeTypeDetector.Object); TestFormat.RegisterGloablTestFormat(); this.Marker = Guid.NewGuid().ToByteArray(); this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); this.FilePath = Guid.NewGuid().ToString(); this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); TestFileSystem.RegisterGloablTestFormat(); TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); }
public void TestAddImageFormatThrowsWithNullEncoder() { TestFormat format = new TestFormat { Encoder = null }; Assert.Throws <ArgumentNullException>(() => { Configuration.Default.AddImageFormat(format); }); }
public void TestAddImageFormatThrowsWithoutDefaultExtension() { TestFormat format = new TestFormat { Extension = "test" }; Assert.Throws <ArgumentException>(() => { Configuration.Default.AddImageFormat(format); }); }
public void TestAddImageFormatThrowsWithEmptySupportedExtension() { TestFormat format = new TestFormat { Extension = "test", SupportedExtensions = new[] { "test", string.Empty } }; Assert.Throws <ArgumentException>(() => { Configuration.Default.AddImageFormat(format); }); }
public ImageLoadTests() { this.returnImage = new Image(1, 1); this.localDecoder = new Mock <IImageDecoder>(); this.localFormat = new Mock <IImageFormat>(); this.localFormat.Setup(x => x.Decoder).Returns(this.localDecoder.Object); this.localFormat.Setup(x => x.Encoder).Returns(new Mock <IImageEncoder>().Object); this.localFormat.Setup(x => x.MimeType).Returns("img/test"); this.localFormat.Setup(x => x.Extension).Returns("png"); this.localFormat.Setup(x => x.HeaderSize).Returns(1); this.localFormat.Setup(x => x.IsSupportedFileFormat(It.IsAny <byte[]>())).Returns(true); this.localFormat.Setup(x => x.SupportedExtensions).Returns(new string[] { "png", "jpg" }); this.localDecoder.Setup(x => x.Decode <Rgba32>(It.IsAny <Configuration>(), It.IsAny <Stream>(), It.IsAny <IDecoderOptions>())) .Callback <Configuration, Stream, IDecoderOptions>((c, s, o) => { using (var ms = new MemoryStream()) { s.CopyTo(ms); this.DecodedData = ms.ToArray(); } }) .Returns(this.returnImage); this.fileSystem = new Mock <IFileSystem>(); this.LocalConfiguration = new Configuration(this.localFormat.Object) { FileSystem = this.fileSystem.Object }; TestFormat.RegisterGloablTestFormat(); this.Marker = Guid.NewGuid().ToByteArray(); this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); this.decoderOptions = new Mock <IDecoderOptions>().Object; this.FilePath = Guid.NewGuid().ToString(); this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); TestFileSystem.RegisterGloablTestFormat(); TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); }
public ImageLoadTests() { this.returnImage = new Image <Rgba32>(1, 1); this.localImageFormatMock = new Mock <IImageFormat>(); this.localDecoder = new Mock <IImageDecoder>(); this.localMimeTypeDetector = new Mock <IImageFormatDetector>(); this.localMimeTypeDetector.Setup(x => x.HeaderSize).Returns(1); this.localMimeTypeDetector.Setup(x => x.DetectFormat(It.IsAny <ReadOnlySpan <byte> >())).Returns(localImageFormatMock.Object); this.localDecoder.Setup(x => x.Decode <Rgba32>(It.IsAny <Configuration>(), It.IsAny <Stream>())) .Callback <Configuration, Stream>((c, s) => { using (var ms = new MemoryStream()) { s.CopyTo(ms); this.DecodedData = ms.ToArray(); } }) .Returns(this.returnImage); this.fileSystem = new Mock <IFileSystem>(); this.LocalConfiguration = new Configuration() { FileSystem = this.fileSystem.Object }; this.LocalConfiguration.AddImageFormatDetector(this.localMimeTypeDetector.Object); this.LocalConfiguration.SetDecoder(localImageFormatMock.Object, this.localDecoder.Object); TestFormat.RegisterGloablTestFormat(); this.Marker = Guid.NewGuid().ToByteArray(); this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); this.FilePath = Guid.NewGuid().ToString(); this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); TestFileSystem.RegisterGloablTestFormat(); TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); }
public void TestAddImageFormatThrowsWenSupportedExtensionsIsNullOrEmpty() { TestFormat format = new TestFormat { SupportedExtensions = null }; Assert.Throws <ArgumentNullException>(() => { Configuration.Default.AddImageFormat(format); }); format = new TestFormat { SupportedExtensions = Enumerable.Empty <string>() }; Assert.Throws <ArgumentException>(() => { Configuration.Default.AddImageFormat(format); }); }
public void TestAddImageFormatThrowsWithNullOrEmptyExtension() { TestFormat format = new TestFormat { Extension = null }; Assert.Throws <ArgumentNullException>(() => { Configuration.Default.AddImageFormat(format); }); format = new TestFormat { Extension = string.Empty }; Assert.Throws <ArgumentException>(() => { Configuration.Default.AddImageFormat(format); }); }
public void TestAddImageFormatThrowsWithNullOrEmptyMimeType() { var format = new TestFormat { MimeType = null }; Assert.Throws <ArgumentNullException>(() => { Configuration.Default.AddImageFormat(format); }); format = new TestFormat { MimeType = string.Empty }; Assert.Throws <ArgumentException>(() => { Configuration.Default.AddImageFormat(format); }); }
public TestEncoder(TestFormat testFormat) { this.testFormat = testFormat; }
public TestHeader(TestFormat testFormat) { this.testFormat = testFormat; }