I want to compare the following two objects for similarity using AutoFixture.SemanticComparison:
public class Object1 { public int a; } public class Object2 { public int a; public int b; }
Now when I do it like this:
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' element as follows:
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 this rather cumbersome, because whenever I add a new element to the Object2 class, I have to fix my unit tests (or at least the unit test helpers).
Is there a way to say "I want to compare for similarity only for the subset that exists in both objects"?
source share