I love to Extend my Assert.AreEqual to many different classes, the known one is the CollectionAssert of course, but I can think of some more such as: ImageAssert, XmlAssert etc..
Did you Create your own Assert classes? and what kind of new would you like to create?
I've just added an implementation to ImageAssert as I wrote above (in my question) I would be glad to hear more of that kind of samples
[TestMethod]
public void CompareImagesSize()
{
Image expected = Bitmap.FromFile(@"C:\ShaniData\Projects2008\TddSamples\Output\ExpectedImage.png");
Image actual = Bitmap.FromFile(@"C:\ShaniData\Projects2008\TddSamples\Output\RhinoDiagram.png");
Bitmap expectedBitmap = new Bitmap(expected);
Bitmap actualBitmap = new Bitmap(actual);
ImageAssert.HasTheSameSize(expectedBitmap, actualBitmap);
}
[TestMethod]
public void CompareTwoSameImagesButWithDifferenExtension()
{
Image expected = Bitmap.FromFile(@"C:\ShaniData\Projects2008\TddSamples\Output\Image2.png");
Image actual = Bitmap.FromFile(@"C:\ShaniData\Projects2008\TddSamples\Output\Image1.jpg");
Bitmap expectedBitmap = new Bitmap(expected);
Bitmap actualBitmap = new Bitmap(actual);
ImageAssert.AreEqual(expectedBitmap, actualBitmap);
}
public class ImageAssert
{
//public static void MoreMethods(Bitmap expected, Bitmap actual)
//{
// //Compare image extensions
// //Compare Thumbnail...
//}
public static void HasTheSameSize(Bitmap expected, Bitmap actual)
{
if ((expected.Height != actual.Height)
|| (expected.Width != actual.Width))
HandleFail("ImageAssert.HasTheSameSize", String.Empty);
}
public static void AreEqual(Bitmap expected, Bitmap actual)
{
for (int i = 0; i < expected.Width; i++)
{
for (int j = 0; j < expected.Height; j++)
{
Color expectedBit = expected.GetPixel(i, j);
Color actualBit = actual.GetPixel(i, j);
if (!expectedBit.Equals(actualBit))
{
HandleFail("ImageAssert.AreEqual", String.Empty, i, j);
return;
}
}
}
}
internal static void HandleFail(string assertionName, string message, params object[] parameters)
{
throw new AssertFailedException(String.Format(assertionName));
}
}