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 re开发者_运维百科sult 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.
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:
var wasCalled = false;
mock.Stub(s => s.Register(r => wasCalled = true);
...
Assert.IsTrue(wasCalled);
This will ensure your "Register" method is calling the lambda that is passed to it.
精彩评论