public void Execute() { // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>(); mockControllerContext.Expect(c => c.Controller).Returns(new ExecuteController()); ControllerContext controllerContext = mockControllerContext.Object; MethodInfo beginMethod = typeof(ExecuteController).GetMethod("BeginMethod"); MethodInfo endMethod = typeof(ExecuteController).GetMethod("EndMethod"); Dictionary <string, object> parameters = new Dictionary <string, object>() { { "id", 42 } }; ReflectedAsyncPatternActionDescriptor ad = GetActionDescriptor(beginMethod, endMethod); 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(42, retVal); }
public void ExecuteThrowsIfControllerContextIsNull() { // Arrange ReflectedAsyncPatternActionDescriptor ad = GetActionDescriptor(null, null); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { ad.BeginExecute(null, null, null, null); }, "controllerContext"); }
public void ExecuteThrowsIfParametersIsNull() { // Arrange ReflectedAsyncPatternActionDescriptor ad = GetActionDescriptor(null, null); ControllerContext controllerContext = new Mock <ControllerContext>().Object; // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { ad.BeginExecute(controllerContext, null, null, null); }, "parameters"); }