From b27abda2df1132fdf9d0df002f8a601a3300a66e Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sat, 28 Jun 2014 18:03:26 +0200 Subject: [PATCH] Loads all the test images + tests a few filters as well (failing for gif images) Former-commit-id: cc2bdbacd4fc865d321f67a57588e09c94480c68 --- .../ImageFactoryUnitTests.cs | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 1fc782073..7cd124b19 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -12,6 +12,7 @@ namespace ImageProcessor.UnitTests { using System; using System.IO; + using System.Collections.Generic; using NUnit.Framework; /// @@ -25,62 +26,89 @@ namespace ImageProcessor.UnitTests /// private readonly string localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } + /// /// Tests the loading of image from a file /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromFile(string fileName, string expectedMime) + public void TestLoadImageFromFile() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - using (ImageFactory imageFactory = new ImageFactory()) + foreach (var fileName in ListInputFiles()) { - imageFactory.Load(testPhoto); - Assert.AreEqual(testPhoto, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + Assert.AreEqual(fileName, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } } + } /// > /// Tests the loading of image from a memory stream /// - /// - /// The file Name. - /// - /// - /// The expected mime type. - /// [Test] - [TestCase("Chrysanthemum.jpg", "image/jpeg")] - [TestCase("Desert.jpg", "image/jpeg")] - [TestCase("cmyk.png", "image/png")] - [TestCase("Penguins.bmp", "image/bmp")] - [TestCase("Penguins.gif", "image/gif")] - public void TestLoadImageFromMemory(string fileName, string expectedMime) + public void TestLoadImageFromMemory() { - string testPhoto = Path.Combine(this.localPath, string.Format("../../Images/{0}", fileName)); - byte[] photoBytes = File.ReadAllBytes(testPhoto); + foreach (var fileName in ListInputFiles()) + { + byte[] photoBytes = File.ReadAllBytes(fileName); - // ImageProcessor - using (MemoryStream inStream = new MemoryStream(photoBytes)) + using (var inStream = new MemoryStream(photoBytes)) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(inStream); + Assert.AreEqual(null, imageFactory.ImagePath); + Assert.IsNotNull(imageFactory.Image); + } + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectAlpha() + { + foreach (var fileName in ListInputFiles()) { - using (ImageFactory imageFactory = new ImageFactory()) + using (var imageFactory = new ImageFactory()) { - imageFactory.Load(inStream); - Assert.AreEqual(null, imageFactory.ImagePath); - Assert.AreEqual(expectedMime, imageFactory.CurrentImageFormat.MimeType); - Assert.IsNotNull(imageFactory.Image); + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Alpha(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void ApplyEffectBrightness() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Brightness(50); + var modified = imageFactory.Image.Clone(); + Assert.AreNotEqual(original, modified); } } }