public void InvokeActionMethodWithSynchronousDescriptor() {
            // Arrange
            ControllerContext controllerContext = new Mock<ControllerContext>().Object;
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            ActionResult expectedResult = new ViewResult();

            Mock<ActionDescriptor> mockDescriptor = new Mock<ActionDescriptor>();
            mockDescriptor.Expect(d => d.Execute(controllerContext, parameters)).Returns(expectedResult);
            ActionDescriptor descriptor = mockDescriptor.Object;

            SignalContainer<IAsyncResult> callbackContainer = new SignalContainer<IAsyncResult>();
            AsyncCallback callback = ar => {
                callbackContainer.Signal(ar);
            };

            object state = new object();

            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            IAsyncResult asyncResult = invoker.BeginInvokeActionMethod(controllerContext, descriptor, parameters, callback, state);
            IAsyncResult passedToCallback = callbackContainer.Wait();
            ActionResult returnedResult = invoker.EndInvokeActionMethod(asyncResult);

            // Assert
            Assert.AreEqual(asyncResult, passedToCallback, "Returned IAsyncResult and IAsyncResult provided to callback were different.");
            Assert.AreEqual(state, asyncResult.AsyncState);
            Assert.AreEqual(expectedResult, returnedResult);
        }
        public void InvokeActionMethodWithAsynchronousDescriptor() {
            // Arrange
            ControllerContext controllerContext = new Mock<ControllerContext>().Object;
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            ActionResult expectedResult = new ViewResult();

            IAsyncResult innerResult = new MockAsyncResult();

            Mock<ActionDescriptor> mockDescriptor = new Mock<ActionDescriptor>();
            IMock<IAsyncActionDescriptor> mockAsyncDescriptor = mockDescriptor.As<IAsyncActionDescriptor>();
            mockAsyncDescriptor.Expect(d => d.BeginExecute(controllerContext, parameters, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(innerResult);
            mockAsyncDescriptor.Expect(d => d.EndExecute(innerResult)).Returns(expectedResult);
            ActionDescriptor descriptor = mockDescriptor.Object;

            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            IAsyncResult asyncResult = invoker.BeginInvokeActionMethod(controllerContext, descriptor, parameters, null, null);
            ActionResult returnedResult = invoker.EndInvokeActionMethod(asyncResult);

            // Assert
            Assert.AreEqual(expectedResult, returnedResult);
        }