本文整理汇总了C#中AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters方法的具体用法?C# AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters怎么用?C# AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncControllerActionInvoker
的用法示例。
在下文中一共展示了AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: InvokeActionMethodWithFilters
public void InvokeActionMethodWithFilters()
{
// Arrange
List<string> actionLog = new List<string>();
ControllerContext controllerContext = new ControllerContext();
Dictionary<string, object> parameters = new Dictionary<string, object>();
MockAsyncResult innerAsyncResult = new MockAsyncResult();
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"); },
OnActionExecutedImpl = delegate(ActionExecutedContext filterContext) { actionLog.Add("OnActionExecuted2"); }
};
Mock<AsyncActionDescriptor> mockActionDescriptor = new Mock<AsyncActionDescriptor>();
mockActionDescriptor.Setup(d => d.BeginExecute(controllerContext, parameters, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(innerAsyncResult);
mockActionDescriptor.Setup(d => d.EndExecute(innerAsyncResult)).Returns(actionResult);
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
Assert.Equal(new[] { "OnActionExecuting1", "OnActionExecuting2", "OnActionExecuted2", "OnActionExecuted1" }, actionLog.ToArray());
Assert.Equal(actionResult, postContext.Result);
}