Dynamic Proxy overriding Equals in AutoFixture Likeness
From version 2.9.0 of AutoFixture, the Likeness class contains a new feature for creating a dynamic proxy that overrides Equals on the destination type.
As an example, we want to compare instances of the following types:
We can have the following syntax (prior to version 2.9.0):
However, from version 2.9.0 there is also a new CreateProxy method on Likeness which returns a proxy of the destination type overriding Equals with Likeness's instance of IEqualityComparer (the SemanticComparer class):
Below is also an example, where we need to verify that an expectation was met:
Although the new Bar instance is created inside the DoSomething method, we can pass a proxied Bar instance on the mock's Verify method.
Internally, a custom Proxy Generator was written which also supports types with non-parameterless constructors. In order to create proxies of such types, the values from the source have to be compatible with the parameters on the destination constructor. (The mapping between the two is made possible by using the same semantic heuristics, as the default semantic comparison.)