Sha*_*eKm 3 .net c# autofixture
如何在包含接口属性的对象中使用AutoFixture填充属性?
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
...
Run Code Online (Sandbox Code Playgroud)
fixture.Create()抛出:
Ploeh.AutoFixture.dll中出现"Ploeh.AutoFixture.ObjectCreationException"类型的异常,但未在用户代码中处理
其他信息:AutoFixture无法从Mediachase.Commerce.Inventory.ICarInformation创建实例,因为它是一个接口
有没有办法为该属性提供具有混凝土类型的AutoFixture?
是的,您可以使用TypeRelay自定义
fixture.Customizations.Add(
new TypeRelay(
typeof(ICarInformation),
typeof(CarInformation));
Run Code Online (Sandbox Code Playgroud)
或者,如果你想使用Moq使用假对象,你可以使用AutoMoqCustomization或者AutoConfiguredMoqCustomization.
| 归档时间: |
|
| 查看次数: |
736 次 |
| 最近记录: |