在 Rhino.Mocks 中存根字典
我有一个关于依赖项的只读字典,我希望能够使用返回值进行存根,并检查对其的分配是否已发生。
我希望 Rhino.Mocks 会默认为我创建一个空字典,但不幸的是它没有。由于它是只读的,我无法创建新字典并将其分配给该属性。
我希望能够将其存根。据我了解,C# 语法看起来像这样:
m.Stub(x => x.myProperty).Return("abc");
所以我希望这适用于 VB:
m.Stub(sub(x) x.myProperty).Return("abc");
但事实并非如此(编译器错误)。关于如何实现这一目标有什么想法吗?如果可以实现这一点,我对 Expect/Verify 语法持开放态度......
I have a read-only dictionary on a dependency that I'd like to be able to stub with return values, and check that assignments to it have happened.
I was hoping that Rhino.Mocks would create an empty dictionary for me by default, but unfortunately it doesn't. Since it is read-only, I can't create a new dictionary and assign it to that property.
I was hoping to be able to stub it instead. From what I understand, the C# syntax for this would looking something like this:
m.Stub(x => x.myProperty).Return("abc");
So I was hoping that this would work for VB:
m.Stub(sub(x) x.myProperty).Return("abc");
But it doesn't (compiler error). Any ideas on how to accomplish this? I'm open to the Expect/Verify syntax if it can accomplish this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Function
就可以解决问题:如果您想验证
myProperty
是否被调用,您可以使用Expect
而不是Stub
>:Using
Function
will do the trick:If you want to verify whether
myProperty
got called you could useExpect
instead ofStub
: