From e4a74e2e5aa23ac8a2578670cbd34d34463ff517 Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Sun, 29 Jun 2014 00:37:38 +0200 Subject: [PATCH] Yet a few other unit tests Former-commit-id: bd37755a47b8159d62b6eeb906fe8514ec51aad2 --- .../ImageFactoryUnitTests.cs | 182 ++++++++++++++---- 1 file changed, 146 insertions(+), 36 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index 60db9a8ee..d868b2245 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -11,8 +11,8 @@ namespace ImageProcessor.UnitTests { using System; - using System.IO; using System.Collections.Generic; + using System.IO; using NUnit.Framework; /// @@ -21,15 +21,6 @@ namespace ImageProcessor.UnitTests [TestFixture] public class ImageFactoryUnitTests { - /// - /// 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 /// @@ -45,10 +36,9 @@ namespace ImageProcessor.UnitTests Assert.IsNotNull(imageFactory.Image); } } - } - /// > + /// /// Tests the loading of image from a memory stream /// [Test] @@ -124,6 +114,84 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectSaturation() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Saturation(50); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectTint() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Tint(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectVignette() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Vignette(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.AliceBlue)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestApplyEffectWatermark() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.Watermark(new Imaging.TextLayer + { + Font = "Arial", + FontSize = 10, + Position = new System.Drawing.Point(10, 10), + Text = "Lorem ipsum dolor" + }); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that a filter is really applied by checking that the image is modified /// @@ -252,21 +320,39 @@ namespace ImageProcessor.UnitTests } } + /// + /// Tests that a filter is really applied by checking that the image is modified + /// + [Test] + public void TestRoundedCorners() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = imageFactory.Image.Clone(); + imageFactory.RoundedCorners(new Imaging.RoundedCornerLayer(5, true, true, true, true)); + Assert.AreNotEqual(original, imageFactory.Image); + } + } + } + /// /// Tests that the image is well resized using constraints /// [Test] public void TestResizeConstraints() { - const int maxSize = 200; + const int MaxSize = 200; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); - Assert.LessOrEqual(imageFactory.Image.Width, maxSize); - Assert.LessOrEqual(imageFactory.Image.Height, maxSize); + imageFactory.Constrain(new System.Drawing.Size(MaxSize, MaxSize)); + Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); + Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); } } } @@ -277,17 +363,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCrop() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new System.Drawing.Rectangle(0, 0, maxSize, maxSize)); + imageFactory.Crop(new System.Drawing.Rectangle(0, 0, MaxSize, MaxSize)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -298,17 +384,17 @@ namespace ImageProcessor.UnitTests [Test] public void TestCropWithCropLayer() { - const int maxSize = 20; + const int MaxSize = 20; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); var original = imageFactory.Image.Clone(); - imageFactory.Crop(new Imaging.CropLayer(0, 0, maxSize, maxSize, Imaging.CropMode.Pixels)); + imageFactory.Crop(new Imaging.CropLayer(0, 0, MaxSize, MaxSize, Imaging.CropMode.Pixels)); Assert.AreNotEqual(original, imageFactory.Image); - Assert.AreEqual(maxSize, imageFactory.Image.Width); - Assert.LessOrEqual(maxSize, imageFactory.Image.Height); + Assert.AreEqual(MaxSize, imageFactory.Image.Width); + Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); } } } @@ -345,15 +431,15 @@ namespace ImageProcessor.UnitTests [Test] public void TestResize() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new System.Drawing.Size(NewSize, NewSize)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } @@ -364,21 +450,45 @@ namespace ImageProcessor.UnitTests [Test] public void TestResizeWithLayer() { - const int newSize = 150; + const int NewSize = 150; foreach (var fileName in ListInputFiles()) { using (var imageFactory = new ImageFactory()) { imageFactory.Load(fileName); - imageFactory.Resize(new Imaging.ResizeLayer( - new System.Drawing.Size(newSize, newSize), - Imaging.ResizeMode.Stretch, - Imaging.AnchorPosition.Left, - true)); - Assert.AreEqual(newSize, imageFactory.Image.Width); - Assert.AreEqual(newSize, imageFactory.Image.Height); + imageFactory.Resize(new Imaging.ResizeLayer(new System.Drawing.Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left)); + Assert.AreEqual(NewSize, imageFactory.Image.Width); + Assert.AreEqual(NewSize, imageFactory.Image.Height); } } } + + /// + /// Tests that the image is resized + /// + [Test] + public void TestRotate() + { + foreach (var fileName in ListInputFiles()) + { + using (var imageFactory = new ImageFactory()) + { + imageFactory.Load(fileName); + var original = (System.Drawing.Image)imageFactory.Image.Clone(); + imageFactory.Rotate(90); + Assert.AreEqual(original.Height, imageFactory.Image.Width); + Assert.AreEqual(original.Width, imageFactory.Image.Height); + } + } + } + + /// + /// Lists the input files in the Images folder + /// + /// The list of files. + private static IEnumerable ListInputFiles() + { + return Directory.GetFiles("./Images"); + } } } \ No newline at end of file