Let's say I have some asynchronous APM template methods (BeginXxx, EndXxx) (as part of some WCF service proxy that I call):
public interface ISomeService
{
IAsyncResult BeginSomeMethod(int num, AsyncCallback callback, object state);
int EndSomeMethod(IAsyncResult ar);
}
In my actual code, it is used Task.Factory.FromAsyncto create a Task, and then waits for this task using the new async / await template introduced in .net 4.5.
I would like to test my class, and so I need to write a method that gets the mock, begin, end method and return method and sets the layout so that it ultimately returns the required return value.
usage example:
SetupAsync(mock, mocked => mocked.BeginSomeMethod, mocked=> mocked.EndSomeMethod, 7);
Which will cause an asynchronous stream with any int argument to return 7. I cannot figure out how to do this in the mock.
source
share