Browse Source

Shaves off a few seconds off unit tests by loading the images just once

Former-commit-id: 34b291f988d3853e62941b08ee21a495ac058cca
Former-commit-id: 46472f04cb1a024f476e38c7ea72e669ca8f918e
pull/17/head
Thomas Broust 12 years ago
parent
commit
860f30a813
  1. 1
      build/build.ps1
  2. 195
      src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs
  3. 14
      src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj
  4. 1
      src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id
  5. BIN
      src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg

1
build/build.ps1

@ -152,6 +152,7 @@ task Run-Coverage -depends Build-Tests {
$CoverageOutputPath = Join-Path $TEST_RESULTS "$($_)_Coverage.xml" $CoverageOutputPath = Join-Path $TEST_RESULTS "$($_)_Coverage.xml"
Write-Host "Running code coverage on project $_" Write-Host "Running code coverage on project $_"
$coverageFilter = "-filter:+[*]* -[FluentAssertions*]* -[*]Common.Exceptions -[ImageProcessor.UnitTests]* -[ImageProcessor.Web.UnitTests]*"
& $OPENCOVER_EXE -register:user -target:$NUNIT_EXE -targetargs:"$TestDdlPath /noshadow /nologo" -targetdir:$TestDllFolder -output:$CoverageOutputPath & $OPENCOVER_EXE -register:user -target:$NUNIT_EXE -targetargs:"$TestDdlPath /noshadow /nologo" -targetdir:$TestDllFolder -output:$CoverageOutputPath
Write-Host "Transforming coverage results file to HTML" Write-Host "Transforming coverage results file to HTML"

195
src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs

@ -27,7 +27,12 @@ namespace ImageProcessor.UnitTests
/// <summary> /// <summary>
/// The list of images. Designed to speed up the tests a little. /// The list of images. Designed to speed up the tests a little.
/// </summary> /// </summary>
private IEnumerable<FileInfo> images; private IEnumerable<FileInfo> imagesInfos;
/// <summary>
/// The list of ImageFactories. Designed to speed up the test a bit more.
/// </summary>
private List<ImageFactory> imagesFactories;
/// <summary> /// <summary>
/// Tests the loading of image from a file /// Tests the loading of image from a file
@ -92,11 +97,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestSaveToMemory() public void TestSaveToMemory()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
using (MemoryStream s = new MemoryStream()) using (MemoryStream s = new MemoryStream())
{ {
imageFactory.Save(s); imageFactory.Save(s);
@ -105,7 +107,6 @@ namespace ImageProcessor.UnitTests
} }
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -113,17 +114,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectAlpha() public void TestApplyEffectAlpha()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Alpha(50); imageFactory.Alpha(50);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that brightness changes is really applied by checking that the image is modified /// Tests that brightness changes is really applied by checking that the image is modified
@ -131,17 +128,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectBrightness() public void TestApplyEffectBrightness()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Brightness(50); imageFactory.Brightness(50);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that background color changes are really applied by checking that the image is modified /// Tests that background color changes are really applied by checking that the image is modified
@ -149,17 +142,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectBackgroundColor() public void TestApplyEffectBackgroundColor()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.BackgroundColor(Color.Yellow); imageFactory.BackgroundColor(Color.Yellow);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a contrast change is really applied by checking that the image is modified /// Tests that a contrast change is really applied by checking that the image is modified
@ -167,17 +156,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectContrast() public void TestApplyEffectContrast()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Contrast(50); imageFactory.Contrast(50);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a saturation change is really applied by checking that the image is modified /// Tests that a saturation change is really applied by checking that the image is modified
@ -185,17 +170,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectSaturation() public void TestApplyEffectSaturation()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Saturation(50); imageFactory.Saturation(50);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a tint change is really applied by checking that the image is modified /// Tests that a tint change is really applied by checking that the image is modified
@ -203,17 +184,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectTint() public void TestApplyEffectTint()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue)); imageFactory.Tint(Color.FromKnownColor(KnownColor.AliceBlue));
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a vignette change is really applied by checking that the image is modified /// Tests that a vignette change is really applied by checking that the image is modified
@ -221,17 +198,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectVignette() public void TestApplyEffectVignette()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue)); imageFactory.Vignette(Color.FromKnownColor(KnownColor.AliceBlue));
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -239,11 +212,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectWatermark() public void TestApplyEffectWatermark()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Watermark(new TextLayer imageFactory.Watermark(new TextLayer
{ {
@ -255,7 +225,6 @@ namespace ImageProcessor.UnitTests
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -263,17 +232,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectBlur() public void TestApplyEffectBlur()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.GaussianBlur(5); imageFactory.GaussianBlur(5);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -281,17 +246,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectBlurWithLayer() public void TestApplyEffectBlurWithLayer()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.GaussianBlur(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); imageFactory.GaussianBlur(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 });
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -299,17 +260,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectSharpen() public void TestApplyEffectSharpen()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.GaussianSharpen(5); imageFactory.GaussianSharpen(5);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -317,17 +274,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectSharpenWithLayer() public void TestApplyEffectSharpenWithLayer()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.GaussianSharpen(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 }); imageFactory.GaussianSharpen(new GaussianLayer { Sigma = 10, Size = 5, Threshold = 2 });
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that all filters can be applied /// Tests that all filters can be applied
@ -335,11 +288,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestApplyEffectFilter() public void TestApplyEffectFilter()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Filter(MatrixFilters.BlackWhite); imageFactory.Filter(MatrixFilters.BlackWhite);
@ -383,7 +333,6 @@ namespace ImageProcessor.UnitTests
imageFactory.Reset(); imageFactory.Reset();
} }
} }
}
/// <summary> /// <summary>
/// Tests that a filter is really applied by checking that the image is modified /// Tests that a filter is really applied by checking that the image is modified
@ -391,17 +340,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestRoundedCorners() public void TestRoundedCorners()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.RoundedCorners(new RoundedCornerLayer(5)); imageFactory.RoundedCorners(new RoundedCornerLayer(5));
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is well resized using constraints /// Tests that the image is well resized using constraints
@ -410,17 +355,13 @@ namespace ImageProcessor.UnitTests
public void TestResizeConstraints() public void TestResizeConstraints()
{ {
const int MaxSize = 200; const int MaxSize = 200;
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
imageFactory.Constrain(new Size(MaxSize, MaxSize)); imageFactory.Constrain(new Size(MaxSize, MaxSize));
Assert.LessOrEqual(imageFactory.Image.Width, MaxSize); Assert.LessOrEqual(imageFactory.Image.Width, MaxSize);
Assert.LessOrEqual(imageFactory.Image.Height, MaxSize); Assert.LessOrEqual(imageFactory.Image.Height, MaxSize);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is well cropped /// Tests that the image is well cropped
@ -429,11 +370,8 @@ namespace ImageProcessor.UnitTests
public void TestCrop() public void TestCrop()
{ {
const int MaxSize = 20; const int MaxSize = 20;
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Crop(new Rectangle(0, 0, MaxSize, MaxSize)); imageFactory.Crop(new Rectangle(0, 0, MaxSize, MaxSize));
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
@ -441,7 +379,6 @@ namespace ImageProcessor.UnitTests
Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is well cropped /// Tests that the image is well cropped
@ -450,11 +387,8 @@ namespace ImageProcessor.UnitTests
public void TestCropWithCropLayer() public void TestCropWithCropLayer()
{ {
const int MaxSize = 20; const int MaxSize = 20;
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels)); imageFactory.Crop(new CropLayer(0, 0, MaxSize, MaxSize, CropMode.Pixels));
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
@ -462,7 +396,6 @@ namespace ImageProcessor.UnitTests
Assert.LessOrEqual(MaxSize, imageFactory.Image.Height); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is flipped /// Tests that the image is flipped
@ -470,11 +403,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestFlip() public void TestFlip()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Flip(true); imageFactory.Flip(true);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
@ -488,7 +418,6 @@ namespace ImageProcessor.UnitTests
Assert.AreEqual(original.Height, imageFactory.Image.Height); Assert.AreEqual(original.Height, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is resized /// Tests that the image is resized
@ -497,17 +426,13 @@ namespace ImageProcessor.UnitTests
public void TestResize() public void TestResize()
{ {
const int NewSize = 150; const int NewSize = 150;
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
imageFactory.Resize(new Size(NewSize, NewSize)); imageFactory.Resize(new Size(NewSize, NewSize));
Assert.AreEqual(NewSize, imageFactory.Image.Width); Assert.AreEqual(NewSize, imageFactory.Image.Width);
Assert.AreEqual(NewSize, imageFactory.Image.Height); Assert.AreEqual(NewSize, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is resized /// Tests that the image is resized
@ -516,17 +441,13 @@ namespace ImageProcessor.UnitTests
public void TestResizeWithLayer() public void TestResizeWithLayer()
{ {
const int NewSize = 150; const int NewSize = 150;
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
imageFactory.Resize(new ResizeLayer(new Size(NewSize, NewSize), ResizeMode.Stretch, AnchorPosition.Left)); imageFactory.Resize(new ResizeLayer(new Size(NewSize, NewSize), ResizeMode.Stretch, AnchorPosition.Left));
Assert.AreEqual(NewSize, imageFactory.Image.Width); Assert.AreEqual(NewSize, imageFactory.Image.Width);
Assert.AreEqual(NewSize, imageFactory.Image.Height); Assert.AreEqual(NewSize, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image is resized /// Tests that the image is resized
@ -534,18 +455,14 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestRotate() public void TestRotate()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Rotate(90); imageFactory.Rotate(90);
Assert.AreEqual(original.Height, imageFactory.Image.Width); Assert.AreEqual(original.Height, imageFactory.Image.Width);
Assert.AreEqual(original.Width, imageFactory.Image.Height); Assert.AreEqual(original.Width, imageFactory.Image.Height);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the images hue has been altered. /// Tests that the images hue has been altered.
@ -553,11 +470,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestHue() public void TestHue()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Hue(90); imageFactory.Hue(90);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
@ -568,7 +482,6 @@ namespace ImageProcessor.UnitTests
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image has been pixelated. /// Tests that the image has been pixelated.
@ -576,17 +489,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestPixelate() public void TestPixelate()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.Pixelate(8); imageFactory.Pixelate(8);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the images quality has been set. /// Tests that the images quality has been set.
@ -594,11 +503,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestQuality() public void TestQuality()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{
using (ImageFactory imageFactory = new ImageFactory())
{ {
imageFactory.Load(file.FullName);
int original = imageFactory.CurrentImageFormat.Quality; int original = imageFactory.CurrentImageFormat.Quality;
imageFactory.Quality(69); imageFactory.Quality(69);
int updated = imageFactory.CurrentImageFormat.Quality; int updated = imageFactory.CurrentImageFormat.Quality;
@ -606,7 +512,6 @@ namespace ImageProcessor.UnitTests
Assert.AreNotEqual(original, updated); Assert.AreNotEqual(original, updated);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the image has had a color replaced. /// Tests that the image has had a color replaced.
@ -614,17 +519,13 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestReplaceColor() public void TestReplaceColor()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.ReplaceColor(Color.White, Color.Black, 90); imageFactory.ReplaceColor(Color.White, Color.Black, 90);
Assert.AreNotEqual(original, imageFactory.Image); Assert.AreNotEqual(original, imageFactory.Image);
} }
} }
}
/// <summary> /// <summary>
/// Tests that the various edge detection algorithms are applied. /// Tests that the various edge detection algorithms are applied.
@ -632,11 +533,8 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestEdgeDetection() public void TestEdgeDetection()
{ {
foreach (FileInfo file in this.ListInputFiles()) foreach (ImageFactory imageFactory in this.ListInputImages())
{ {
using (ImageFactory imageFactory = new ImageFactory())
{
imageFactory.Load(file.FullName);
Image original = (Image)imageFactory.Image.Clone(); Image original = (Image)imageFactory.Image.Clone();
imageFactory.DetectEdges(new KayyaliEdgeFilter()); imageFactory.DetectEdges(new KayyaliEdgeFilter());
@ -676,7 +574,6 @@ namespace ImageProcessor.UnitTests
imageFactory.Reset(); imageFactory.Reset();
} }
} }
}
/// <summary> /// <summary>
/// Gets the files matching the given extensions. /// Gets the files matching the given extensions.
@ -710,16 +607,34 @@ namespace ImageProcessor.UnitTests
/// <returns>The list of files.</returns> /// <returns>The list of files.</returns>
private IEnumerable<FileInfo> ListInputFiles() private IEnumerable<FileInfo> ListInputFiles()
{ {
if (this.images != null) if (this.imagesInfos != null)
{ {
return this.images; return this.imagesInfos;
} }
DirectoryInfo directoryInfo = new DirectoryInfo("./Images"); DirectoryInfo directoryInfo = new DirectoryInfo("./Images");
this.images = GetFilesByExtensions(directoryInfo, new[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".webp" }); this.imagesInfos = GetFilesByExtensions(directoryInfo, new[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".webp" });
return this.imagesInfos;
}
/// <summary>
/// Lists the input images to use from the Images folder
/// </summary>
/// <returns>The list of images</returns>
private IEnumerable<ImageFactory> ListInputImages()
{
if (imagesFactories == null || imagesFactories.Count() == 0)
{
imagesFactories = new List<ImageFactory>();
foreach (FileInfo fi in this.ListInputFiles())
{
imagesFactories.Add((new ImageFactory()).Load(fi.FullName));
}
}
return this.images; return imagesFactories;
} }
} }
} }

14
src/ImageProcessor.UnitTests/ImageProcessor.UnitTests.csproj

@ -69,9 +69,6 @@
<None Include="Images\cmyk.jpg"> <None Include="Images\cmyk.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Images\color-vision-test.gif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\exif-Tulips.jpg"> <None Include="Images\exif-Tulips.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@ -114,9 +111,6 @@
<None Include="Images\profile-srgb.jpg"> <None Include="Images\profile-srgb.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Images\size-Penguins-200.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Images\text-over-transparent.png"> <None Include="Images\text-over-transparent.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
@ -135,14 +129,6 @@
<Link>Images\text.png</Link> <Link>Images\text.png</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="..\Images\thor.jpg">
<Link>Images\thor.jpg</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\Images\udendørs-374.jpg">
<Link>Images\udendørs-374.jpg</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\Images\udendørs.jpg"> <None Include="..\Images\udendørs.jpg">
<Link>Images\udendørs.jpg</Link> <Link>Images\udendørs.jpg</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

1
src/ImageProcessor.UnitTests/Images/color-vision-test.gif.REMOVED.git-id

@ -1 +0,0 @@
b169fac4f1591e81e91c0bb6fed6dcf62a34c80e

BIN
src/ImageProcessor.UnitTests/Images/size-Penguins-200.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Loading…
Cancel
Save