In Verify
Moq by default checks reference equality for arguments so it only passes when you provide the same instances (except if you’ve overriden Equals
) in your tests and in your implementation.
In you case the expectedA.Value
just returns the new A { P1 = 1 }
created in the test which, of course, isn’t the same instance created in DoSomethingWith
.
You need to use Moq’s It.Is
construct to properly test this without overriding Equals
(in fact for this you don’t need Autofixture at all):
barMock.Verify(m => m.Something(It.Is<A>(arg => arg.P1 == a.P1)));
But if you have multiple properties like P1,P2,P3… AutoFixture can be useful:
barMock.Verify(m => m.Something(It.Is<A>(arg => expectedA.Equals(a))));
Because you don’t need to write out the equality checks manually for all the properties.