How can I have AutoFixture populate properties in my object containing interface property?
public class Car : ICar
{
public string Name { get; set; }
public ICarinformation ContactInformation { get; set; } // problematic
...
public CarInformation: ICarinformation
{
public string Make {get; set; } // I would like these to be populated as well
...
fixture.Create() throws:
An exception of type 'Ploeh.AutoFixture.ObjectCreationException' occurred in Ploeh.AutoFixture.dll but was not handled in user code
Additional information: AutoFixture was unable to create an instance from Mediachase.Commerce.Inventory.ICarInformation because it's an interface
Is there a way to provide AutoFixture with Concrete type for that property?
Yes, you can just use the TypeRelay
customization
fixture.Customizations.Add(
new TypeRelay(
typeof(ICarInformation),
typeof(CarInformation));
Alternatively, if you wanted to use a fake object using Moq, you could use either AutoMoqCustomization
or AutoConfiguredMoqCustomization
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With