对于将一个类与另一个类的嵌套集合进行水合,我有点困惑。
我得到错误:
AutoFixture was unable to create an instance from System.Collections.Generic.IList`1[typename...]
我尝试使用
Fixture.Register()
注册用于填充内部类的类型。我可以只做一个显示的样本
我还注意到
Register()
被标记为过时,但 Inject()
上没有文档CodePlex 上的方法,所以我很难理解它应该如何工作。
最佳答案
AutoFixture 不假设如何实例化接口(interface)实例,但您可以 pretty easily enable the behavior you seek - 例如对于整数:
fixture.Register(() => fixture.CreateMany<int>());
在即将推出的 AutoFixture 2.1 中,您也可以只使用 enable conventions for various collections使用单个方法调用:
var fixture = new Fixture().Customize(new MultipleCustomization());
关于 Register 方法的弃用,请注意它只是 Register 方法的一个重载被标记为过时。 Inject 方法是直接替换 - 它具有相同的签名和用法,只是名称不同。所有其他寄存器重载均未弃用,应作为“记录”使用。
关于autofixture - 带有嵌套集合的类 - 如何填充嵌套类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5458137/