I'm developing a battleship game in ASP.NET and I'm stucked on a problem with my unit tests with MSTest.
I want to test the creation of each type of boat and verifying that each boat's constructor make the desired boat with the good width, etc. So, I decided to write a general method with the tag [DataTestMethod]. But I don't understand how I can use an object as a parameter.
Here's an example of what I want :
[DataTestMethod]
[DataRow("Aircraft Cruiser", 5, OccupationType.Aircraft, new Aircraft())]
public void CreateAircraft(string description, int width, OccupationType occupationType, Ship resultShip)
{
var expectedShip = new Ship
{
Description = description,
Width = width,
OccupationType = occupationType
};
Assert.AreEqual(expectedShip, resultShip)
}
But it obvliously doesn't work. So I did something like that :
[DataTestMethod]
[DataRow("Aircraft Cruiser", 5, OccupationType.Aircraft, "Aircraft")]
public void CreateAircraft(string description, int width, OccupationType occupationType, string shipType)
{
var expectedShip = new Ship
{
Description = description,
Width = width,
OccupationType = occupationType
};
Ship resultShip = null;
switch (shipType)
{
case "Aircraft":
resultShip = new Aircraft();
break;
}
Assert.AreEqual(expectedShip, resultShip);
}
but I'm sure that's not the most efficent way to do what I want. Have you some idea ?
Many thanks.