Here is one of my msTest Unit Tests and possibly one of the worst "looking" tests.
[TestMethod]
public void UniquePositionPoint_CreateUPP_UPPExistsInPPField()
{
//Setup the values to be used by this test.
CIM_Network network = new CIM_Network();
string x = "5";
string y = "10";
string expectedMRID = String.Format("_UPP{0}", (x + y).GetHashCode());
//Carry out the test
CIM_PositionPoint pp = new CIM_PositionPoint(network, mRID: "pp", fields: new Dictionary<string, object>()
{
{"cim:PositionPoint.CoordinateSystem",new CIM_CoordinateSystem(network, mRID: "coordSys")},
{"cim:PositionPoint.xPosition", x},
{"cim:PositionPoint.yPosition", y},
}, addBackReferences:true);
//Checks if the test was carried out correctly.
Assert.AreEqual(2, pp.Fields.Count(),
String.Format("ERROR: There should only be 2 fields in the position point as the x and y values should of been moved out to the UPP. Currently the fields in the pp are {0}",
string.Join(":", pp.Fields.Select(kvp => (kvp.Key + ":" + kvp.Value.ToString())))));
Assert.IsNotNull(pp.Fields.ContainsKey("uniquePositionPoint"), "ERROR: The field 'uniquePositionPoint:' does not exist in the position point fields.");
Assert.IsInstanceOfType(pp.getField("uniquePositionPoint"), typeof(CIM_UniquePositionPoint),
String.Format("ERROR: Expected the object at field 'uniquePositionPoint' to be of type CIM_UniquePositionPoint however it was of type {0}",
pp.getField("uniquePositionPoint").GetType().Name));
CIM_UniquePositionPoint uPP = (CIM_UniquePositionPoint)pp.getField("uniquePositionPoint");
Assert.AreEqual(expectedMRID, uPP.MRID,
String.Format("ERROR: Expected the mRID {0} to be the UPP's mRID but instead it was {1}", expectedMRID, uPP.MRID));
Assert.IsTrue(uPP.BackRefs.Contains(pp), "ERROR: The position point was not found within the upp.");
}
What the code does is add a "position point" into a network. When this happens a few things also happen as a result: 1. A UniquePositionPoint (upp for short) is created. 2. That upp will contain all of the coordinates of the position point. 3. The coordinates will be removed from the position point.
What I mainly want to know is if this (a bunch of asserts) is the correct way to test this functionality or should it be broken down at all?