I'm using Ploeh's SemanticComparison library with great success - except when I have an abstract class involved that doesn't expose all of its constructor arguments.
Here is the exception I get -
Ploeh.SemanticComparison.ProxyCreationException : The proxy of Foo could not be created using the same semantic heuristics as the default semantic comparison. In order to create proxies of types with non-parameterless constructor the values from the source constructor must be compatible to the parameters of the destination constructor.
----> System.InvalidOperationException : Operation is not valid due to the current state of the object.
Here is the simplest example I could come up with -
// this fails with the aforementioned exception
_fixture.Create<Foo>().AsSource().OfLikeness<Foo>().CreateProxy();
public class Foo : Bar
{
public Foo(int age)
: base(age)
{
}
}
public abstract class Bar
{
private readonly int _age;
protected Bar(int age)
{
_age = age;
}
}
However, if I add public int NotAge { get; set; }
to abstract class Bar
, then all is well. I really consider this a sub-optimal solution because I don't want to expose property age
. It's simply being used to calculate other things.
How can I resolve this without exposing properties just for the sake of testing. Is there perhaps another library that can achieve the same effect without this issue?