RhinoMocks - 模拟具体类型 - 运行构造函数

发布于 2024-09-13 22:28:33 字数 362 浏览 1 评论 0原文

我有以下行,尝试创建具体类型的模拟:

AddPropPersonalCOI = MockRepository.GenerateMock<SomeType>(ObjectFactory.GetInstance<paramType1>(), ObjectFactory.GetInstance<paramType2>());

Assert.IsNotNull(AddPropPersonalCOI.view);

我实际上已经进入了有问题的构造函数,看着它执行,看着视图属性从传递到构造函数的值分配(我验证了不为空),但断言失败。

是的,视图是虚拟的。

有人知道我做错了什么吗?

I've got the following line, attempting to create a mock of a concrete type:

AddPropPersonalCOI = MockRepository.GenerateMock<SomeType>(ObjectFactory.GetInstance<paramType1>(), ObjectFactory.GetInstance<paramType2>());

Assert.IsNotNull(AddPropPersonalCOI.view);

I've actually stepped into the constructor in question, watched it execute, watched the view property get assigned from the value passed into the constructor (which I verified were not null), and yet the assert fails.

And yes, view is virtual.

Anyone know what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉服软 2024-09-20 22:28:33

如果 view 是虚拟的,您需要先为其设置一个期望,然后才能使用它。当您在期望模式下调用方法和属性时,Rhino Mocks 会为您提供 null 值。

If view is virtual, you'll need to set an expectation for it before you can use it. Rhino Mocks gives you null values when you call methods and properties in expectations mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文