public void Execute() { // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>(); mockControllerContext.Expect(c => c.Controller).Returns(new ExecuteController()); ControllerContext controllerContext = mockControllerContext.Object; Dictionary <string, object> parameters = new Dictionary <string, object>() { { "id1", 42 } }; ReflectedAsyncActionDescriptor ad = GetActionDescriptor(_asyncMethod, _completedMethod); SignalContainer <object> resultContainer = new SignalContainer <object>(); AsyncCallback callback = ar => { object o = ad.EndExecute(ar); resultContainer.Signal(o); }; // Act ad.BeginExecute(controllerContext, parameters, callback, null); object retVal = resultContainer.Wait(); // Assert Assert.AreEqual("Hello world: 42", retVal); }
public static object ExecuteHelper(TaskAsyncActionDescriptor actionDescriptor, Dictionary <string, object> parameters, ControllerContext controllerContext = null) { SignalContainer <object> resultContainer = new SignalContainer <object>(); AsyncCallback callback = ar => { object o = actionDescriptor.EndExecute(ar); resultContainer.Signal(o); }; actionDescriptor.BeginExecute(controllerContext ?? GetControllerContext(), parameters, callback, state: null); return(resultContainer.Wait()); }