I want to be able to compare the two following objects for likeness using AutoFixture.SemanticComparison:
public class Object1
{
public int a;
}
public class Object2
{
public int a;
public int b;
}
Now, when I do it this way:
var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().ShouldEqual(o2);
I get the following exception: "The following members did not match: - b."
I found out that I can omit the 'b' member like this:
var o1 = new Object1 { a = 1 };
var o2 = new Object2 { a = 1, b = 2};
o1.AsSource().OfLikeness<Object2>().Without(object2 => object2.b).ShouldEqual(o2);
However, I find that this is quite cumbersome, because whenever I add a new member to class Object2, I have to correct my unit tests (or at least unit test helpers).
Is there a way to say "I want to compare for likeness just for the subset that exists in both objects"?