我正在尝试为具有嵌套成员的命令设置自定义。但是我的自定义无法正常工作。我究竟做错了什么?当我尝试创建实例时,出现错误,该月份必须介于1到12之间,这意味着未触发我的自定义。
var fixture = new Fixture();
fixture.Customize<CreatePaymentCardCommand.SourceCard>(
obj =>
{
obj.With(x => x.ExpirationMonth, Random.Next(1, 12))
.With(x => x.ExpirationYear, DateTime.Now.AddYears(Random.Next(1, 3)).Year);
return obj;
});
fixture.Customize<CreatePaymentCardCommand>(
obj =>
{
obj.With(
x => x.Source,
() => new CreatePaymentCardCommand.Source()
{
Card = fixture.Create<CreatePaymentCardCommand.SourceCard>(),
Owner = fixture.Create<CreatePaymentCardCommand.Owner>(),
Id = fixture.Create<string>(),
});
return obj;
});
var obj = fixture.Create<CreatePaymentCardCommand>();