This commit is contained in:
parent
038b8c7f19
commit
f82516d155
|
|
@ -37,12 +37,20 @@ namespace Microsoft.AspNet.Mvc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task InvokeAsync()
|
public async override Task InvokeAsync()
|
||||||
{
|
{
|
||||||
ActionContext.Controller = _controllerFactory.CreateController(ActionContext);
|
var controller = _controllerFactory.CreateController(ActionContext);
|
||||||
ActionContext.InputFormatters = _inputFormattersProvider.InputFormatters
|
try
|
||||||
.ToList();
|
{
|
||||||
return base.InvokeAsync();
|
ActionContext.Controller = controller;
|
||||||
|
ActionContext.InputFormatters = _inputFormattersProvider.InputFormatters
|
||||||
|
.ToList();
|
||||||
|
await base.InvokeAsync();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_controllerFactory.ReleaseController(ActionContext.Controller);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)
|
protected override async Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)
|
||||||
|
|
|
||||||
|
|
@ -1272,12 +1272,12 @@ namespace Microsoft.AspNet.Mvc
|
||||||
Assert.Same(input, contentResult.Value);
|
Assert.Same(input, contentResult.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReflectedActionInvoker CreateInvoker(IFilter filter, bool actionThrows = false)
|
private TestReflectedActionInvoker CreateInvoker(IFilter filter, bool actionThrows = false)
|
||||||
{
|
{
|
||||||
return CreateInvoker(new[] { filter }, actionThrows);
|
return CreateInvoker(new[] { filter }, actionThrows);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrows = false)
|
private TestReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrows = false)
|
||||||
{
|
{
|
||||||
var actionDescriptor = new ReflectedActionDescriptor()
|
var actionDescriptor = new ReflectedActionDescriptor()
|
||||||
{
|
{
|
||||||
|
|
@ -1319,6 +1319,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
var controllerFactory = new Mock<IControllerFactory>();
|
var controllerFactory = new Mock<IControllerFactory>();
|
||||||
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>())).Returns(this);
|
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>())).Returns(this);
|
||||||
|
controllerFactory.Setup(m => m.ReleaseController(this)).Verifiable();
|
||||||
|
|
||||||
var actionBindingContextProvider = new Mock<IActionBindingContextProvider>(MockBehavior.Strict);
|
var actionBindingContextProvider = new Mock<IActionBindingContextProvider>(MockBehavior.Strict);
|
||||||
actionBindingContextProvider
|
actionBindingContextProvider
|
||||||
|
|
@ -1333,11 +1334,12 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var inputFormattersProvider = new Mock<IInputFormattersProvider>();
|
var inputFormattersProvider = new Mock<IInputFormattersProvider>();
|
||||||
inputFormattersProvider.SetupGet(o => o.InputFormatters)
|
inputFormattersProvider.SetupGet(o => o.InputFormatters)
|
||||||
.Returns(new List<IInputFormatter>());
|
.Returns(new List<IInputFormatter>());
|
||||||
var invoker = new ReflectedActionInvoker(
|
|
||||||
|
var invoker = new TestReflectedActionInvoker(
|
||||||
actionContext,
|
actionContext,
|
||||||
actionBindingContextProvider.Object,
|
actionBindingContextProvider.Object,
|
||||||
filterProvider.Object,
|
filterProvider.Object,
|
||||||
controllerFactory.Object,
|
controllerFactory,
|
||||||
actionDescriptor,
|
actionDescriptor,
|
||||||
inputFormattersProvider.Object);
|
inputFormattersProvider.Object);
|
||||||
|
|
||||||
|
|
@ -1613,5 +1615,34 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TestReflectedActionInvoker : ReflectedActionInvoker
|
||||||
|
{
|
||||||
|
private Mock<IControllerFactory> _factoryMock;
|
||||||
|
|
||||||
|
public TestReflectedActionInvoker(
|
||||||
|
ActionContext actionContext,
|
||||||
|
IActionBindingContextProvider bindingContextProvider,
|
||||||
|
INestedProviderManager<FilterProviderContext> filterProvider,
|
||||||
|
Mock<IControllerFactory> controllerFactoryMock,
|
||||||
|
ReflectedActionDescriptor descriptor,
|
||||||
|
IInputFormattersProvider inputFormattersProvider) :
|
||||||
|
base(actionContext,
|
||||||
|
bindingContextProvider,
|
||||||
|
filterProvider,
|
||||||
|
controllerFactoryMock.Object,
|
||||||
|
descriptor,
|
||||||
|
inputFormattersProvider)
|
||||||
|
{
|
||||||
|
_factoryMock = controllerFactoryMock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async override Task InvokeAsync()
|
||||||
|
{
|
||||||
|
await base.InvokeAsync();
|
||||||
|
|
||||||
|
_factoryMock.Verify();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue