My Sprite
class has a method:
private void updateWithBitmap(Bitmap b, int x, int y)
This will 'lay on top' the bitmap that's passed in, the top left corner of the passed in bitmap being at the x,y position of the parent bitmap.
Now I want write unit tests to check that this method is working correctly.
For example, we'll need to check that an exception is thrown when the passed in bitmap is larger, or is out of bounds of the parent bitmap.
[TestMethod]
[ExpectedException(typeof(System.ArgumentOutOfRangeException))]
public void TestUpdateWithBitMap_SmallerParent_ThrowsOutOfRangeException()
{
Sprite parent = new Sprite(new Bitmap(10,10));
Bitmap child = new Bitmap(20, 20);
parent.updateWithBitmap(child,0,0)
}
[TestMethod]
[ExpectedException(typeof(System.ArgumentOutOfRangeException))]
public void TestUpdateWithBitMap_PassedBitMapOutOfBounds_ThrowsOutOfRangeException()
{
Sprite parent = new Sprite(new Bitmap(10,10));
Bitmap child = new Bitmap(3, 3);
parent.updateWithBitmap(child, 9,9)
}
Good so far.
But also we want to test that the method genuinely is updating correctly.
For example, if the left most image is our parent bitmap, and the middle is the child bitmap, and we call our method with:
parent.updateWithBitmap(child, 3,3);
we get the rightmost bitmap as a result.
The question is:
Is it appropriate to store these bitmaps as resources, and then check the results are equal?
eg.
[TestMethod]
public void TestUpdateWithBitMap_UpdatesCorrectly()
{
Sprite parent = new Sprite(Properties.Resources.TestBitmapParent1);
Bitmap child = Properties.Resources.TestBitmapChild1;
parent.updateWithBitmap(child, 3,3)
#something like Assert.Equal(parent.getBitmap(), Properties.Resources.TestBitmapResult1);
}