Reputation: 367
I'm new at unit testing and I try to test my parser:
public static List<tranche> Parse22(string record)
{
List <tranche> Tranche = new List<tranche>();
foreach (var i in record)
{
var ts = new tranche();
ts.dealer_name = line.Substring(2, 5);
ts.invoice = line.Substring(7, 7);
ts.amount = Decimal.Parse(line.Substring(14, 13));
ts.vin = line.Substring(46, 17);
ts.model = line.Substring(63, 4);
ts.registration = line.Substring(72, 10);
ts.brutto = Decimal.Parse(line.Substring(95, 13));
Tranche.Add(ts);
}
return Tranche;
}
I want to test dealer_name and VIN are correct. But I don't understand what should be at "Assert."
[TestClass]
public class ParserTest
{
[TestMethod]
public void Parse_LineStarts22_ReturnsVINandDealerNameCorrect()
{
string record = testString;
var res = myParser.Parse22(record);
Assert.AreEqual() //???
}
}
Upvotes: 0
Views: 357
Reputation: 6155
The method has two parameter: expected value and actual value
Because res is a List
you have to access the item you want to check via the index and then the propety you want to check.
This is an example for the first item in your res List
.
Assert.AreEqual("expectedDealerName", res[0].dealer_name);
Assert.AreEqual("expectedVin", res[0].vin);
For more information have a look at the Assert.AreEqual Method
In my example the AreEqual(Object, Object)
method will be used.
Verifies that two specified objects are equal. The assertion fails if the objects are not equal.
Upvotes: 2