public void TestLoadImageFromFile([ValueSource(nameof(samples))] ImageSample sample) { string testFolder = Path.Combine("Temp", "Test"); Directory.CreateDirectory(testFolder); string fileName = Path.Combine(testFolder, sample.ResourceName); using (var stream = sample.CreateResourceStream()) { CopyToFile(stream, fileName); } using (var image = app.ImageCodec.LoadImageFromFile(fileName)) { Assert.That(image.Width, Is.EqualTo(sample.Width), () => $"{sample.ResourceName}, {nameof(image.Width)}"); Assert.That(image.Height, Is.EqualTo(sample.Height), () => $"{sample.ResourceName}, {nameof(image.Height)}"); NBitmap bitmap = new NBitmap(image.Width, image.Height); image.CopyToBitmap(Point.Empty, bitmap, Point.Empty, new Size(image.Width, image.Height)); Assert.That(bitmap.GetColor(0, 0), Is.EqualTo(sample.TopLeftColor), nameof(sample.TopLeftColor)); Assert.That(bitmap.GetColor(bitmap.Width - 1, 0), Is.EqualTo(sample.TopRightColor), nameof(sample.TopRightColor)); Assert.That(bitmap.GetColor(0, bitmap.Height - 1), Is.EqualTo(sample.BottomLeftColor), nameof(sample.BottomLeftColor)); Assert.That(bitmap.GetColor(bitmap.Width - 1, bitmap.Height - 1), Is.EqualTo(sample.BottomRightColor), nameof(sample.BottomRightColor)); } }
public void TestLoadBitmapFromStream([ValueSource(nameof(samples))] ImageSample sample) { NBitmap bitmap; using (var stream = sample.CreateResourceStream()) { bitmap = app.ImageCodec.LoadBitmapFromStream(stream); } Assert.That(bitmap.Width, Is.EqualTo(sample.Width), () => $"{sample.ResourceName}, {nameof(bitmap.Width)}"); Assert.That(bitmap.Height, Is.EqualTo(sample.Height), () => $"{sample.ResourceName}, {nameof(bitmap.Height)}"); Assert.That(bitmap.GetColor(0, 0), Is.EqualTo(sample.TopLeftColor), nameof(sample.TopLeftColor)); Assert.That(bitmap.GetColor(bitmap.Width - 1, 0), Is.EqualTo(sample.TopRightColor), nameof(sample.TopRightColor)); Assert.That(bitmap.GetColor(0, bitmap.Height - 1), Is.EqualTo(sample.BottomLeftColor), nameof(sample.BottomLeftColor)); Assert.That(bitmap.GetColor(bitmap.Width - 1, bitmap.Height - 1), Is.EqualTo(sample.BottomRightColor), nameof(sample.BottomRightColor)); }