具有嵌套集合的类 - 如何填充嵌套类?
我对如何将一个类与另一个类的嵌套集合进行水合感到有点困惑。 我收到错误:
AutoFixture 无法从 System.Collections.Generic.IList`1[typename...] 创建实例
我尝试使用 Fixture.Register()
注册用于填充内部类的类型。 我可以用一个示例来显示
- 主类
- 另一个类的嵌套集合(IList/IEnumerable)。
我还注意到 Register()
被标记为已过时,但 CodePlex 上没有关于 Inject()
方法的文档,所以我很困惑这是如何实现的应该有效。
I'm a bit confused as to hydrate a class with a nested collection of another class.
I get the error:
AutoFixture was unable to create an instance from System.Collections.Generic.IList`1[typename...]
I've tried to use Fixture.Register()
to register the type for populating the inner class.
I could just to do with a sample which shows
- The main class
- The nested collection (IList/IEnumerable) of another class.
I've also noticed that Register()
is marked as obsolete, yet there is no documentation on the Inject()
method on CodePlex so I'm stumped as to how this should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AutoFixture 不假设如何实例化接口实例,但是您可以非常轻松地启用您寻求的行为 - 例如整数:
在即将推出的 AutoFixture 2.1 中,您也可以通过单个方法调用启用各种集合的约定:
关于 Register 方法的弃用,请注意,这只是 Register 方法的单个重载被标记为过时。 Inject 方法是直接替换方法 - 它具有相同的签名和用法,只是名称不同。所有其他寄存器重载均未弃用,应按“记录”使用。
AutoFixture makes no presumptions on how to instantiate instances of interfaces, but you can pretty easily enable the behavior you seek - e.g. for integers:
In the upcoming AutoFixture 2.1 you can also just enable conventions for various collections with a single method call:
Regarding the deprecation of the Register method, please notice that it's only a single overload of the Register method that's marked obsolete. The Inject method is the direct replacement - it has the same signature and usage, just a different name. All the other Register overloads are not deprecated and should be used as 'documented'.