我有一个概念上看起来像这样的类:
public class Entity
{
private readonly List<double> _values = new List<double>();
...
public List<double> Values
{
get
{
return _values;
}
}
}
在单元测试中,我想使用 AutoFixture 提供随机实体列表:
var entities = this.fixture.CreateMany<Entity>().ToList();
但是,没有自动生成的值被添加到 Entity 对象的 Values 属性,正如我所期望的(希望...)。我试图将值列表更改为非只读,并向 Values 属性添加一个 setter,这解决了问题,但是没有更好的选择吗?
请您参考如下方法:
AutoFixture 不会填充只读集合,但您可以要求它这样做:
var entity = fixture.Create<Entity>();
fixture.AddManyTo(entity.Values);
