测试:将值插入到 Action中
如何使用Rhino Mocks 将值插入到操作中?
Register()
执行一个操作,该操作被分配给稍后在函数中使用的局部变量:
var result = EnumResult.Timeout;
something.Register<EnumResult>(r => result = r);
<do things with result which need to be unit tested>
我希望能够将一个值作为 r 注入到该操作中(正如函数中所定义的那样)并测试之后会发生什么。
How do you use Rhino Mocks to insert a value into an action?
Register()
takes an action that is assigned to a local variable that is used later in the function:
var result = EnumResult.Timeout;
something.Register<EnumResult>(r => result = r);
<do things with result which need to be unit tested>
I want to be able to inject a value as r into the action (as it is defined in the function) and test what happens afterwards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道您不能在测试中传递一个设置某些变量的 lambda,然后验证在测试结束时是否设置了该变量吗?像这样的事情:
这将确保您的“Register”方法正在调用传递给它的 lambda。
Couldn't you just pass a lambda in your test that sets some variable and then validate the variable was set at the end of the test? Something like this:
This will ensure your "Register" method is calling the lambda that is passed to it.