在Nbuilder中,是否可以将对象的某些属性设置为null?

时间:2019-10-02 02:30:08

标签: c# .net-core xunit nbuilder

就像automapper一样,我们在NBuilder中是否有扩展名可以将某些值设置为null?

我有一个测试,我在测试我的映射时会忽略很多字段,因此使它们为null。因此,要验证输出,我必须添加很多.With(x => someProperty = null)。

有什么办法解决吗?

Builder<AClass>.CreateNew()
.With(x =>x.Property1 = "Some Value")
.With(x =>x.Property2 = "Some Value")
.With(x =>x.Property3 = null)
.With(x =>x.Property4 = null)

有没有办法做类似的事情

Builder<AClass>.CreateNew()
.With(x =>x.Property1 = "Some Value")
.With(x =>x.Property2 = "Some Value")
.RestOfThemAsNull()

0 个答案:

没有答案