From 1cfacd96123781b98da24728da0fe2062f97ea1c Mon Sep 17 00:00:00 2001 From: Thomas Broust Date: Mon, 6 Oct 2014 17:54:49 +0200 Subject: [PATCH] Changes unit tests to use FluentAssertions and tests a bunch more stuff Former-commit-id: 237c6ce8e70f16f4154bd8d2b9d4379524d19cd7 Former-commit-id: f687f45da3e081dae7f1cfc15260d4a2c79319cb --- .../ImageFactoryUnitTests.cs | 210 +++++++++--------- .../ImageProcessor.UnitTests.csproj | 8 + src/ImageProcessor.UnitTests/packages.config | 1 + 3 files changed, 109 insertions(+), 110 deletions(-) diff --git a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs index b3a970e8a..45f1ef6e8 100644 --- a/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs +++ b/src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs @@ -17,6 +17,7 @@ namespace ImageProcessor.UnitTests using ImageProcessor.Imaging.Filters.EdgeDetection; using ImageProcessor.Imaging.Filters.Photo; + using FluentAssertions; using NUnit.Framework; /// @@ -46,8 +47,9 @@ namespace ImageProcessor.UnitTests using (ImageFactory imageFactory = new ImageFactory()) { imageFactory.Load(file.FullName); - Assert.AreEqual(file.FullName, imageFactory.ImagePath); - Assert.IsNotNull(imageFactory.Image); + + imageFactory.ImagePath.Should().Be(file.FullName, "because the path should have been memorized"); + imageFactory.Image.Should().NotBeNull("because the image should have been loaded"); } } } @@ -67,8 +69,9 @@ namespace ImageProcessor.UnitTests using (ImageFactory imageFactory = new ImageFactory()) { imageFactory.Load(inStream); - Assert.AreEqual(null, imageFactory.ImagePath); - Assert.IsNotNull(imageFactory.Image); + + imageFactory.ImagePath.Should().BeNull("because an image loaded from stream should not have a file path"); + imageFactory.Image.Should().NotBeNull("because the image should have been loaded"); } } } @@ -87,7 +90,10 @@ namespace ImageProcessor.UnitTests { imageFactory.Load(file.FullName); imageFactory.Save(outputFileName); - Assert.AreEqual(true, File.Exists(outputFileName)); + + File.Exists(outputFileName).Should().BeTrue("because the file should have been saved on disk"); + + File.Delete(outputFileName); } } } @@ -104,7 +110,8 @@ namespace ImageProcessor.UnitTests { imageFactory.Save(s); s.Seek(0, SeekOrigin.Begin); - Assert.AreEqual(true, s.Capacity > 0); + + s.Capacity.Should().BeGreaterThan(0, "because the stream should contain the image"); } } } @@ -118,9 +125,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Alpha(50); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the alpha operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -133,9 +139,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Brightness(50); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the brightness operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -148,9 +153,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.BackgroundColor(Color.Yellow); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the background color operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -163,9 +167,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Contrast(50); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the contrast operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -178,9 +181,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Saturation(50); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the saturation operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -193,9 +195,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue)); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the tint operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -208,9 +209,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue)); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the vignette operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -223,7 +223,6 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Watermark(new TextLayer { FontFamily = new FontFamily("Arial"), @@ -231,7 +230,7 @@ namespace ImageProcessor.UnitTests Position = new Point(10, 10), Text = "Lorem ipsum dolor" }); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the watermark operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -244,9 +243,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.GaussianBlur(5); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the blur operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -259,9 +257,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.GaussianBlur(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the layered blur operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -274,9 +271,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.GaussianSharpen(5); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the sharpen operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -289,9 +285,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.GaussianSharpen(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the layered sharpen operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -304,57 +299,56 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Filter(MatrixFilters.BlackWhite); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the bw filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Comic); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the comic filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Gotham); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the gotham filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.GreyScale); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the greyscale filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.HiSatch); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the hisatch operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Invert); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the invert filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Lomograph); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the lomo filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.LoSatch); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the losatch filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Polaroid); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the polaroid filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Filter(MatrixFilters.Sepia); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the sepia filter operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); } } @@ -367,9 +361,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.RoundedCorners(new RoundedCornerLayer(5)); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the rounded corners operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -383,8 +376,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { imageFactory.Constrain(new Size(MaxSize, MaxSize)); - Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); - Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); + imageFactory.Image.Width.Should().BeLessOrEqualTo(MaxSize, "because the image size should have been reduced"); + imageFactory.Image.Height.Should().BeLessOrEqualTo(MaxSize, "because the image size should have been reduced"); } } @@ -398,11 +391,11 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Crop(new Rectangle(0, 0, MaxSize, MaxSize)); - AssertImagesAreDifferent(original, imageFactory.Image); - Assert.AreEqual(MaxSize, imageFactory.Image.Width); - Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); + AssertImagesAreDifferent(original, imageFactory.Image, "because the crop operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Image.Width.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); + imageFactory.Image.Height.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); } } @@ -416,11 +409,11 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels)); - AssertImagesAreDifferent(original, imageFactory.Image); - Assert.AreEqual(MaxSize, imageFactory.Image.Width); - Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); + AssertImagesAreDifferent(original, imageFactory.Image, "because the layered crop operation should have been applied on {0}", imageFactory.ImagePath); + + imageFactory.Image.Width.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); + imageFactory.Image.Height.Should().Be(MaxSize, "because the cropped image should be {0}x{0}", MaxSize); } } @@ -433,18 +426,17 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Flip(true); - AssertImagesAreDifferent(original, imageFactory.Image); - Assert.AreEqual(original.Width, imageFactory.Image.Width); - Assert.AreEqual(original.Height, imageFactory.Image.Height); + AssertImagesAreDifferent(original, imageFactory.Image, "because the vertical flip operation should have been applied on {0}", imageFactory.ImagePath); + imageFactory.Image.Width.Should().Be(original.Width, "because the dimensions should not have changed"); + imageFactory.Image.Height.Should().Be(original.Height, "because the dimensions should not have changed"); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Flip(); - AssertImagesAreDifferent(original, imageFactory.Image); - Assert.AreEqual(original.Width, imageFactory.Image.Width); - Assert.AreEqual(original.Height, imageFactory.Image.Height); + AssertImagesAreDifferent(original, imageFactory.Image, "because the horizontal flip operation should have been applied on {0}", imageFactory.ImagePath); + imageFactory.Image.Width.Should().Be(original.Width, "because the dimensions should not have changed"); + imageFactory.Image.Height.Should().Be(original.Height, "because the dimensions should not have changed"); } } @@ -458,8 +450,9 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { imageFactory.Resize(new Size(NewSize, NewSize)); - Assert.AreEqual(NewSize, imageFactory.Image.Width); - Assert.AreEqual(NewSize, imageFactory.Image.Height); + + imageFactory.Image.Width.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); + imageFactory.Image.Height.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); } } @@ -473,8 +466,9 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { imageFactory.Resize(new ResizeLayer(new Size(NewSize, NewSize), ResizeMode.Stretch, AnchorPosition.Left)); - Assert.AreEqual(NewSize, imageFactory.Image.Width); - Assert.AreEqual(NewSize, imageFactory.Image.Height); + + imageFactory.Image.Width.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); + imageFactory.Image.Height.Should().Be(NewSize, "because the new image's size should be {0}x{0}", NewSize); } } @@ -487,10 +481,10 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Rotate(90); - Assert.AreEqual(original.Height, imageFactory.Image.Width); - Assert.AreEqual(original.Width, imageFactory.Image.Height); + + imageFactory.Image.Width.Should().Be(original.Height, "because the rotated image dimensions should have been switched"); + imageFactory.Image.Height.Should().Be(original.Width, "because the rotated image dimensions should have been switched"); } } @@ -503,15 +497,14 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Hue(90); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the hue operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.Hue(116, true); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -524,9 +517,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.Pixelate(8); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the pixelate operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -542,7 +534,7 @@ namespace ImageProcessor.UnitTests imageFactory.Quality(69); int updated = imageFactory.CurrentImageFormat.Quality; - Assert.AreNotEqual(original, updated); + updated.Should().NotBe(original, "because the quality should have been changed"); } } @@ -555,9 +547,8 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.ReplaceColor(Color.White, Color.Black, 90); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the color replace operation should have been applied on {0}", imageFactory.ImagePath); } } @@ -570,52 +561,51 @@ namespace ImageProcessor.UnitTests foreach (ImageFactory imageFactory in this.ListInputImages()) { Image original = (Image)imageFactory.Image.Clone(); - AssertImagesAreIdentical(original, imageFactory.Image); imageFactory.DetectEdges(new KayyaliEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the kayyali edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new KirschEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the kirsch edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new Laplacian3X3EdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the laplacian 3x3 edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new Laplacian5X5EdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the laplacian 5x5 edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new LaplacianOfGaussianEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the laplacian gaussian edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new PrewittEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the prewitt edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new RobertsCrossEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the roberts edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new ScharrEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the scharr edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); imageFactory.DetectEdges(new SobelEdgeFilter()); - AssertImagesAreDifferent(original, imageFactory.Image); + AssertImagesAreDifferent(original, imageFactory.Image, "because the sobel edge operation should have been applied on {0}", imageFactory.ImagePath); imageFactory.Reset(); - AssertImagesAreIdentical(original, imageFactory.Image); + AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset"); } } @@ -686,9 +676,9 @@ namespace ImageProcessor.UnitTests /// /// The expected result /// The tested image - private void AssertImagesAreIdentical(Image expected, Image tested) + private void AssertImagesAreIdentical(Image expected, Image tested, string because, params string[] becauseArgs) { - Assert.IsTrue(ToByteArray(expected).SequenceEqual(ToByteArray(tested))); + ToByteArray(expected).SequenceEqual(ToByteArray(tested)).Should().BeTrue(because, becauseArgs); } /// @@ -696,9 +686,9 @@ namespace ImageProcessor.UnitTests /// /// The not-expected result /// The tested image - private void AssertImagesAreDifferent(Image expected, Image tested) + private void AssertImagesAreDifferent(Image expected, Image tested, string because, params string[] becauseArgs) { - Assert.IsFalse(ToByteArray(expected).SequenceEqual(ToByteArray(tested))); + ToByteArray(expected).SequenceEqual(ToByteArray(tested)).Should().BeFalse(because, becauseArgs); } /// diff --git a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj index ce96b012a..ee8c333fb 100644 --- a/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj +++ b/src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj @@ -37,6 +37,12 @@ false + + ..\packages\FluentAssertions.3.2.1\lib\net45\FluentAssertions.dll + + + ..\packages\FluentAssertions.3.2.1\lib\net45\FluentAssertions.Core.dll + @@ -44,6 +50,8 @@ + + diff --git a/src/ImageProcessor.UnitTests/packages.config b/src/ImageProcessor.UnitTests/packages.config index a18b325a4..266c399ff 100644 --- a/src/ImageProcessor.UnitTests/packages.config +++ b/src/ImageProcessor.UnitTests/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file