Browse Source

Yet a few other unit tests

Former-commit-id: 8c384e50213dfb577c395a2d1850eb20fdad0a57
af/merge-core
Thomas Broust 12 years ago
committed by James South
parent
commit
a6fec0fc9d
  1. 182
      src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs

182
src/ImageProcessor.UnitTests/ImageFactoryUnitTests.cs

@ -11,8 +11,8 @@
namespace ImageProcessor.UnitTests namespace ImageProcessor.UnitTests
{ {
using System; using System;
using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using NUnit.Framework; using NUnit.Framework;
/// <summary> /// <summary>
@ -21,15 +21,6 @@ namespace ImageProcessor.UnitTests
[TestFixture] [TestFixture]
public class ImageFactoryUnitTests public class ImageFactoryUnitTests
{ {
/// <summary>
/// Lists the input files in the Images folder
/// </summary>
/// <returns>The list of files.</returns>
private static IEnumerable<string> ListInputFiles()
{
return Directory.GetFiles("./Images");
}
/// <summary> /// <summary>
/// Tests the loading of image from a file /// Tests the loading of image from a file
/// </summary> /// </summary>
@ -45,10 +36,9 @@ namespace ImageProcessor.UnitTests
Assert.IsNotNull(imageFactory.Image); Assert.IsNotNull(imageFactory.Image);
} }
} }
} }
/// <summary>> /// <summary>
/// Tests the loading of image from a memory stream /// Tests the loading of image from a memory stream
/// </summary> /// </summary>
[Test] [Test]
@ -124,6 +114,84 @@ namespace ImageProcessor.UnitTests
} }
} }
/// <summary>
/// Tests that a filter is really applied by checking that the image is modified
/// </summary>
[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);
}
}
}
/// <summary>
/// Tests that a filter is really applied by checking that the image is modified
/// </summary>
[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);
}
}
}
/// <summary>
/// Tests that a filter is really applied by checking that the image is modified
/// </summary>
[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);
}
}
}
/// <summary>
/// Tests that a filter is really applied by checking that the image is modified
/// </summary>
[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);
}
}
}
/// <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
/// </summary> /// </summary>
@ -252,21 +320,39 @@ namespace ImageProcessor.UnitTests
} }
} }
/// <summary>
/// Tests that a filter is really applied by checking that the image is modified
/// </summary>
[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);
}
}
}
/// <summary> /// <summary>
/// Tests that the image is well resized using constraints /// Tests that the image is well resized using constraints
/// </summary> /// </summary>
[Test] [Test]
public void TestResizeConstraints() public void TestResizeConstraints()
{ {
const int maxSize = 200; const int MaxSize = 200;
foreach (var fileName in ListInputFiles()) foreach (var fileName in ListInputFiles())
{ {
using (var imageFactory = new ImageFactory()) using (var imageFactory = new ImageFactory())
{ {
imageFactory.Load(fileName); imageFactory.Load(fileName);
imageFactory.Constrain(new System.Drawing.Size(maxSize, maxSize)); imageFactory.Constrain(new System.Drawing.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);
} }
} }
} }
@ -277,17 +363,17 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestCrop() public void TestCrop()
{ {
const int maxSize = 20; const int MaxSize = 20;
foreach (var fileName in ListInputFiles()) foreach (var fileName in ListInputFiles())
{ {
using (var imageFactory = new ImageFactory()) using (var imageFactory = new ImageFactory())
{ {
imageFactory.Load(fileName); imageFactory.Load(fileName);
var original = imageFactory.Image.Clone(); 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.AreNotEqual(original, imageFactory.Image);
Assert.AreEqual(maxSize, imageFactory.Image.Width); Assert.AreEqual(MaxSize, imageFactory.Image.Width);
Assert.LessOrEqual(maxSize, imageFactory.Image.Height); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height);
} }
} }
} }
@ -298,17 +384,17 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestCropWithCropLayer() public void TestCropWithCropLayer()
{ {
const int maxSize = 20; const int MaxSize = 20;
foreach (var fileName in ListInputFiles()) foreach (var fileName in ListInputFiles())
{ {
using (var imageFactory = new ImageFactory()) using (var imageFactory = new ImageFactory())
{ {
imageFactory.Load(fileName); imageFactory.Load(fileName);
var original = imageFactory.Image.Clone(); 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.AreNotEqual(original, imageFactory.Image);
Assert.AreEqual(maxSize, imageFactory.Image.Width); Assert.AreEqual(MaxSize, imageFactory.Image.Width);
Assert.LessOrEqual(maxSize, imageFactory.Image.Height); Assert.LessOrEqual(MaxSize, imageFactory.Image.Height);
} }
} }
} }
@ -345,15 +431,15 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestResize() public void TestResize()
{ {
const int newSize = 150; const int NewSize = 150;
foreach (var fileName in ListInputFiles()) foreach (var fileName in ListInputFiles())
{ {
using (var imageFactory = new ImageFactory()) using (var imageFactory = new ImageFactory())
{ {
imageFactory.Load(fileName); imageFactory.Load(fileName);
imageFactory.Resize(new System.Drawing.Size(newSize, newSize)); imageFactory.Resize(new System.Drawing.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);
} }
} }
} }
@ -364,21 +450,45 @@ namespace ImageProcessor.UnitTests
[Test] [Test]
public void TestResizeWithLayer() public void TestResizeWithLayer()
{ {
const int newSize = 150; const int NewSize = 150;
foreach (var fileName in ListInputFiles()) foreach (var fileName in ListInputFiles())
{ {
using (var imageFactory = new ImageFactory()) using (var imageFactory = new ImageFactory())
{ {
imageFactory.Load(fileName); imageFactory.Load(fileName);
imageFactory.Resize(new Imaging.ResizeLayer( imageFactory.Resize(new Imaging.ResizeLayer(new System.Drawing.Size(NewSize, NewSize), Imaging.ResizeMode.Stretch, Imaging.AnchorPosition.Left));
new System.Drawing.Size(newSize, newSize), Assert.AreEqual(NewSize, imageFactory.Image.Width);
Imaging.ResizeMode.Stretch, Assert.AreEqual(NewSize, imageFactory.Image.Height);
Imaging.AnchorPosition.Left,
true));
Assert.AreEqual(newSize, imageFactory.Image.Width);
Assert.AreEqual(newSize, imageFactory.Image.Height);
} }
} }
} }
/// <summary>
/// Tests that the image is resized
/// </summary>
[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);
}
}
}
/// <summary>
/// Lists the input files in the Images folder
/// </summary>
/// <returns>The list of files.</returns>
private static IEnumerable<string> ListInputFiles()
{
return Directory.GetFiles("./Images");
}
} }
} }
Loading…
Cancel
Save