I have a WPF module that gets data in form of interfaces, e.g. ICustomer
. The real Customer object is defined in another module, that I can't reference in the WPF module because of lose coupling.
Since we want design data in our projects, and I want to avoid to write Fakes for every entity, I thought that using Moq would help here, so I made a small example:
public MainVM()
{
if (IsInDesignMode)
{
var c1 = new Mock<ICustomer>();
c1.SetupAllProperties();
c1.FirstName = "John";
c1.LastName = "Doe";
Customers = new List<ICustomer>
{
c1.Object,
};
}
}
In the view I bring in the datacontext and do:
d:DataContext="{d:DesignInstance vm:MainVM, IsDesignTimeCreatable=True}"
The problem now is, that the line in the view throws me an exception:
Unable to cast object of type 'Castle.Proxies.ICustomerProxy_5' to 'Prototype.Data.ICustomer'
How can I get rid of this error? Is there some workaround?