我有一个具有这样属性的类
public string Foo
{
get { return _foo; }
set
{
if (!string.Equals(_foo, value))
{
_foo= value;
OnPropertyChanged();
}
}
}
当我使用 _fixture = new Fixture {OmitAutoProperties = true}; 创建对象时,我希望它具有值,但它为 null 并且 setter 永远不会命中。我错过了什么吗?
最佳答案
这是设计使然。正如文档所述:
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
换句话说,在 AutoFixture 中,术语“自动属性”指的是 AutoFixture 自动填充可写属性的功能。也许更好的词是DoNotAutomaticallyPopulateProperties
。
我可以理解这种困惑,就像在 C# 中一样,auto-property 也可以解释为含义 Auto-Implemented Properties .
坦率地说,AutoFixture 的术语也许应该更加谨慎地选择,但多年来,我认为以前从未引起过我的注意。
具体来说,OP Foo
是一个可写属性,当您禁用自动属性时,永远不会调用 setter。
关于autofixture - OmitAutoProperties 影响非自动属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43829116/