Beispiel #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.");
        }
Beispiel #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);
        }
Beispiel #3
0
        public void ExecuteThrowsIfControllerContextIsNull()
        {
            // Arrange
            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(null);

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                ad.BeginExecute(null, null, null, null);
            }, "controllerContext");
        }
Beispiel #4
0
        public void ExecuteThrowsIfParametersIsNull()
        {
            // Arrange
            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(null);
            ControllerContext controllerContext         = new Mock <ControllerContext>().Object;

            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                delegate {
                ad.BeginExecute(controllerContext, null, null, null);
            }, "parameters");
        }
Beispiel #5
0
        public void ExecuteThrowsIfActionMethodReturnsNull()
        {
            // Arrange
            Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>();

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

            MethodInfo actionMethod = typeof(ExecuteController).GetMethod("FooReturnsNull");
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(actionMethod);

            // Act & assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                ad.BeginExecute(controllerContext, parameters, null, null);
            },
                @"Method 'System.Func`1[System.Int32] FooReturnsNull()' returned null. The method must return a value.");
        }