当前位置: 首页>>代码示例>>C#>>正文


C# AsyncControllerActionInvoker类代码示例

本文整理汇总了C#中AsyncControllerActionInvoker的典型用法代码示例。如果您正苦于以下问题:C# AsyncControllerActionInvoker类的具体用法?C# AsyncControllerActionInvoker怎么用?C# AsyncControllerActionInvoker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AsyncControllerActionInvoker类属于命名空间,在下文中一共展示了AsyncControllerActionInvoker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeAction_ActionThrowsException_ThreadAbort

        public void InvokeAction_ActionThrowsException_ThreadAbort()
        {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            Assert.Throws<ThreadAbortException>(
                delegate { invoker.BeginInvokeAction(controllerContext, "ActionCallsThreadAbort", null, null); });
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:10,代码来源:AsyncControllerActionInvokerTest.cs

示例2: InvokeAction_ActionThrowsException_NotHandled

        public void InvokeAction_ActionThrowsException_NotHandled()
        {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            Assert.Throws<Exception>(
                delegate { invoker.BeginInvokeAction(controllerContext, "ActionThrowsExceptionAndIsNotHandled", null, null); },
                @"Some exception text.");
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:11,代码来源:AsyncControllerActionInvokerTest.cs

示例3: InvokeAction_ActionNotFound

        public void InvokeAction_ActionNotFound() {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "ActionNotFound", null, null);
            bool retVal = invoker.EndInvokeAction(asyncResult);

            // Assert
            Assert.IsFalse(retVal);
        }
开发者ID:consumentor,项目名称:Server,代码行数:12,代码来源:AsyncControllerActionInvokerTest.cs

示例4: InvokeAction_AuthorizationFilterShortCircuits

        public void InvokeAction_AuthorizationFilterShortCircuits() {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "AuthorizationFilterShortCircuits", null, null);
            bool retVal = invoker.EndInvokeAction(asyncResult);

            // Assert
            Assert.IsTrue(retVal);
            Assert.AreEqual("From authorization filter", ((TestController)controllerContext.Controller).Log);
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:AsyncControllerActionInvokerTest.cs

示例5: InvokeAction_ActionThrowsException_Handled

        public void InvokeAction_ActionThrowsException_Handled() {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "ActionThrowsExceptionAndIsHandled", null, null);
            Assert.IsNull(((TestController)controllerContext.Controller).Log, "Result filter shouldn't have executed yet.");

            bool retVal = invoker.EndInvokeAction(asyncResult);
            Assert.IsTrue(retVal);
            Assert.AreEqual("From exception filter", ((TestController)controllerContext.Controller).Log);
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:AsyncControllerActionInvokerTest.cs

示例6: InvokeAction_AuthenticationFilterChallenges

        public void InvokeAction_AuthenticationFilterChallenges()
        {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "AuthenticationFilterChallenges", null, null);
            bool retVal = invoker.EndInvokeAction(asyncResult);

            // Assert
            Assert.True(retVal);
            Assert.Equal("From authentication filter challenge", ((TestController)controllerContext.Controller).Log);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:14,代码来源:AsyncControllerActionInvokerTest.cs

示例7: InvokeAction_ResultThrowsException_NotHandled

        public void InvokeAction_ResultThrowsException_NotHandled() {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "ResultThrowsExceptionAndIsNotHandled", null, null);
            ExceptionHelper.ExpectException<Exception>(
                delegate {
                    invoker.EndInvokeAction(asyncResult);
                },
                @"Some exception text.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:AsyncControllerActionInvokerTest.cs

示例8: InvokeActionMethod_SynchronousDescriptor

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

            Mock<ActionDescriptor> mockActionDescriptor = new Mock<ActionDescriptor>();
            mockActionDescriptor.Setup(d => d.Execute(controllerContext, parameters)).Returns(expectedResult);

            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

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

            // Assert
            Assert.Equal(expectedResult, returnedResult);
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:19,代码来源:AsyncControllerActionInvokerTest.cs

示例9: InvokeAction_ThrowsIfControllerContextIsNull

        public void InvokeAction_ThrowsIfControllerContextIsNull()
        {
            // Arrange
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            Assert.ThrowsArgumentNull(
                delegate { invoker.BeginInvokeAction(null, "someAction", null, null); }, "controllerContext");
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:9,代码来源:AsyncControllerActionInvokerTest.cs

示例10: InvokeAction_ThrowsIfActionNameIsNull

        public void InvokeAction_ThrowsIfActionNameIsNull()
        {
            // Arrange
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            Assert.ThrowsArgumentNullOrEmpty(
                delegate { invoker.BeginInvokeAction(new ControllerContext(), null, null, null); }, "actionName");
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:9,代码来源:AsyncControllerActionInvokerTest.cs

示例11: InvokeAction_ResultThrowsException_Handled

        public void InvokeAction_ResultThrowsException_Handled()
        {
            // Arrange
            ControllerContext controllerContext = GetControllerContext();
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            IAsyncResult asyncResult = invoker.BeginInvokeAction(controllerContext, "ResultThrowsExceptionAndIsHandled", null, null);
            bool retVal = invoker.EndInvokeAction(asyncResult);

            Assert.True(retVal);
            Assert.Equal("From exception filter", ((TestController)controllerContext.Controller).Log);
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:13,代码来源:AsyncControllerActionInvokerTest.cs

示例12: InvokeAction_RequestValidationFails

        public void InvokeAction_RequestValidationFails()
        {
            // Arrange
            ControllerContext controllerContext = GetControllerContext(passesRequestValidation: false);
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            Assert.Throws<HttpRequestValidationException>(
                delegate { invoker.BeginInvokeAction(controllerContext, "NormalAction", null, null); });
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:10,代码来源:AsyncControllerActionInvokerTest.cs

示例13: InvokeAction_RequestValidationFails

        public void InvokeAction_RequestValidationFails() {
            // Arrange
            ControllerContext controllerContext = GetControllerContext(false /* passesRequestValidation */);
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();

            // Act & assert
            ExceptionHelper.ExpectException<HttpRequestValidationException>(
                delegate {
                    invoker.BeginInvokeAction(controllerContext, "NormalAction", null, null);
                });
        }
开发者ID:consumentor,项目名称:Server,代码行数:11,代码来源:AsyncControllerActionInvokerTest.cs

示例14: BeingInvokeActionMethodWithFiltersTester

        private ActionResult BeingInvokeActionMethodWithFiltersTester(Func<IAsyncResult> beginFunction, Func<ActionResult> endFunction, bool checkBegin, bool checkEnd, IActionFilter[] filters)
        {
            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();
            ControllerContext controllerContext = new ControllerContext();
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            Mock<AsyncActionDescriptor> mockActionDescriptor = new Mock<AsyncActionDescriptor>();
            bool endExecuteCalled = false;
            bool beginExecuteCalled = false;
            Func<ActionResult> endExecute = () =>
            {
                endExecuteCalled = true;
                return endFunction();
            };
            Func<IAsyncResult> beingExecute = () =>
            {
                beginExecuteCalled = true;
                return beginFunction();
            };

            mockActionDescriptor.Setup(d => d.BeginExecute(controllerContext, parameters, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(beingExecute);
            mockActionDescriptor.Setup(d => d.EndExecute(It.IsAny<IAsyncResult>())).Returns(endExecute);

            IAsyncResult outerAsyncResult = null;
            try
            {
                outerAsyncResult = invoker.BeginInvokeActionMethodWithFilters(controllerContext, filters, mockActionDescriptor.Object, parameters, null, null);
            }
            catch (Exception ex)
            {
                if (checkEnd)
                {
                    // Testing end, so not expecting exception thrown from begin
                    Assert.NotNull(ex);
                }
                else
                {
                    throw ex;
                }
            }

            Assert.NotNull(outerAsyncResult);
            Assert.Equal(checkBegin, beginExecuteCalled);
            Assert.False(endExecuteCalled);

            ActionExecutedContext postContext = invoker.EndInvokeActionMethodWithFilters(outerAsyncResult);

            Assert.NotNull(postContext);
            if (checkEnd)
            {
                Assert.True(endExecuteCalled);
            }
            return postContext.Result;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:53,代码来源:AsyncControllerActionInvokerTest.cs

示例15: InvokeActionMethodWithFilters_ShortCircuited

        public void InvokeActionMethodWithFilters_ShortCircuited() {
            // Arrange
            List<string> actionLog = new List<string>();
            ControllerContext controllerContext = new ControllerContext();
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            ActionResult actionResult = new ViewResult();

            ActionFilterImpl filter1 = new ActionFilterImpl() {
                OnActionExecutingImpl = delegate(ActionExecutingContext filterContext) {
                    actionLog.Add("OnActionExecuting1");
                },
                OnActionExecutedImpl = delegate(ActionExecutedContext filterContext) {
                    actionLog.Add("OnActionExecuted1");
                }
            };
            ActionFilterImpl filter2 = new ActionFilterImpl() {
                OnActionExecutingImpl = delegate(ActionExecutingContext filterContext) {
                    actionLog.Add("OnActionExecuting2");
                    filterContext.Result = actionResult;
                },
                OnActionExecutedImpl = delegate(ActionExecutedContext filterContext) {
                    actionLog.Add("OnActionExecuted2");
                }
            };

            Mock<AsyncActionDescriptor> mockActionDescriptor = new Mock<AsyncActionDescriptor>();
            mockActionDescriptor.Expect(d => d.BeginExecute(controllerContext, parameters, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Throws(new Exception("I shouldn't have been called."));
            mockActionDescriptor.Expect(d => d.EndExecute(It.IsAny<IAsyncResult>())).Throws(new Exception("I shouldn't have been called."));

            AsyncControllerActionInvoker invoker = new AsyncControllerActionInvoker();
            IActionFilter[] filters = new IActionFilter[] { filter1, filter2 };

            // Act
            IAsyncResult outerAsyncResult = invoker.BeginInvokeActionMethodWithFilters(controllerContext, filters, mockActionDescriptor.Object, parameters, null, null);
            ActionExecutedContext postContext = invoker.EndInvokeActionMethodWithFilters(outerAsyncResult);

            // Assert
            CollectionAssert.AreEqual(
                new string[] { "OnActionExecuting1", "OnActionExecuting2", "OnActionExecuted1" },
                actionLog);
            Assert.AreEqual(actionResult, postContext.Result);
        }
开发者ID:consumentor,项目名称:Server,代码行数:42,代码来源:AsyncControllerActionInvokerTest.cs


注:本文中的AsyncControllerActionInvoker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。