One way to solve this is use an anonymous object.
BeEquivalentTo
looks at the expectation to decide what properties to consider when doing an structural equivalency comparison.
In this
class MyClass
{
string Prop1 { get; set; }
string Prop2 { get; set; }
}
var subject = new MyClass
{
Prop1 = "IrrelevantValue",
Prop2 = "value2"
}
var expected = new
{
Prop2 = "value2"
}
objectA.Should().BeEquivalentTo(expected);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…