I have a mocked method that looks like this:
class NotMineClass {
T Execute(Func operation)
{
// do something
return operation();
}
}
In my code, I do such as:
public MyType MyMethod()
{
MyType object = new MyType();
bool success = notMineClassInstance.Execute(() =>
{
// some things
retVal = injectedObject1.method();
object.attribute = injectedObject2.method();
// some other things
return retVal;
}
if (success)
{
object.otherAttribute = someValue;
}
return object;
}
My case is, I am testing MyMethod with Moq and I want to verify the Func behaviour is as expected. I have some injected objects in its body, that are mocks, and should be verified; it also starts building my return value, so I can't do any assertion unless I invoke the function passed as parameter.
In Java and jUnit + EasyMock , I would capture the parameter passed, like this:
public void testMyMethod() {
// ...
Capture < Function < void, Boolean > > functionCapture = Captures.last();
expect(notMineClassInstance.execute(EasyMock.capture(functionCapture)));
// Expectations for the body of the function
replay();
functionCapture.getValue().apply(null);
}
How do I do the same using C# + Moq?