Exemplo n.º 1
0
        public void EndExecuteThrowsIfCalledPrematurely()
        {
            // Arrange
            ExecuteController        controller            = new ExecuteController();
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

            mockControllerContext.Expect(c => c.Controller).Returns(controller);
            ControllerContext controllerContext = mockControllerContext.Object;

            Dictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "id", 42 }
            };

            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(_actionMethod);

            // Act & assert
            controller.AsyncManager.OutstandingOperations.Increment();
            IAsyncResult asyncResult = ad.BeginExecute(controllerContext, parameters, null, null);

            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                ad.EndExecute(asyncResult);
            },
                @"EndExecute() was called prematurely.");
        }
Exemplo n.º 2
0
        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>()
            {
                { "id", 42 }
            };

            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(_actionMethod);

            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(84, retVal);
        }