Suppose i have lots of classes like this (Foo1, Foo2 ..)
class Foo
{
public int F{get; set;}
public Bar ConvertToBar ()
{
return new Bar(){ B = this.F*10 };
}
}
all they have in common is ConvertToBar() method.
I have two approaches to unit-test this method:
Call convert to ConvertToBar () and check all it's properties (I have to do it in all tests for each Foo like class)
Bar bar = foo.ConvertToBar (); Assert.AreEqual (expectedValue, bar.Property); ...
Write helper method that compares two Bar instances and then use it like this:
Bar expectedBar = new Bar () Assert.True( barCompareMethod (expectedBar, foo.ConvertToBar ());
What will be the best way to write unit-test for this method?