public void BeginInvokeActionEndContinuationWithThreadAbortException() {
            // Arrange
            ThreadAbortException ex = (ThreadAbortException)Activator.CreateInstance(typeof(ThreadAbortException), true /* nonPublic */);
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            ExceptionHelper.ExpectException<ThreadAbortException>(
                delegate {
                    invoker.BeginInvokeActionEndContinuation(null, null, () => { throw ex; });
                });
        }
        public void BeginInvokeActionEndContinuationWithNormalControlFlow() {
            // Arrange
            bool wasCalled = false;
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            invoker.BeginInvokeActionEndContinuation(null, null, () => { wasCalled = true; });

            // Assert
            Assert.IsTrue(wasCalled);
        }
예제 #3
0
 protected AsyncController() {
     ActionInvoker = new AsyncControllerActionInvoker();
 }
        public void SynchronizationContextPropertyHasDefaultValue() {
            // Act
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Assert
            Assert.IsNotNull(invoker.SynchronizationContext);
        }
        public void SynchronizationContextPropertyExplicitlySetByConstructor() {
            // Arrange
            SynchronizationContext syncContext = new SynchronizationContext();

            // Act
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker(syncContext);

            // Assert
            Assert.AreEqual(syncContext, invoker.SynchronizationContext);
        }
        public void InvokeActionThrowsIfControllerContextIsNull() {
            // Arrange
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                    invoker.BeginInvokeAction(null, null, null, null);
                }, "controllerContext");
        }
        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);
        }
예제 #9
0
 protected AsyncController()
 {
     ActionInvoker = new AsyncControllerActionInvoker();
 }
        public void InvokeActionThrowsIfActionNameIsNull() {
            // Arrange
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();
            ControllerContext controllerContext = new ControllerContext();

            // Act & assert
            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
                delegate {
                    invoker.BeginInvokeAction(controllerContext, null, null, null);
                }, "actionName");
        }