我正在将AutoFixture与NUnit一起使用,当我使用OmitAutoProperties
时,仍会自动填充属性。这是我的自定义外观:
public class ContractItemCustomization : ICustomization
{
public void Customize(IFixture fixture)
{
var orderReceivedContractItem = fixture.Build<ContractItem>()
.OmitAutoProperties()
.With(x => x.Status, new ContractStatus
{
ContractLifecycleStatus = ContractLifecycleStatus.ORDER_RECEIVED
});
fixture.Customizations.Add(orderReceivedContractItem);
}
}
这是我使用自定义方式的方法:
[SetUp]
public void Setup()
{
fixture = new Fixture().Customize(
new CompositeCustomization(
new ContractItemCustomization()));
contractItem = fixture.Create<ContractItem>();
}
我想念什么?
答案 0 :(得分:0)
好吧,在更深入地了解AutoFixture文档之后,我找到了解决方案:
代替:
fixture.Customizations.Add(orderReceivedContractItem);
我必须这样做:
fixture.Register(() => orderReceivedContractItem.Create());