Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit f82516d

Browse files
author
YishaiGalatzer
committed
Fix issue #1202
1 parent 038b8c7 commit f82516d

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

src/Microsoft.AspNet.Mvc.Core/ReflectedActionInvoker.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ public ReflectedActionInvoker([NotNull] ActionContext actionContext,
3737
}
3838
}
3939

40-
public override Task InvokeAsync()
40+
public async override Task InvokeAsync()
4141
{
42-
ActionContext.Controller = _controllerFactory.CreateController(ActionContext);
43-
ActionContext.InputFormatters = _inputFormattersProvider.InputFormatters
44-
.ToList();
45-
return base.InvokeAsync();
42+
var controller = _controllerFactory.CreateController(ActionContext);
43+
try
44+
{
45+
ActionContext.Controller = controller;
46+
ActionContext.InputFormatters = _inputFormattersProvider.InputFormatters
47+
.ToList();
48+
await base.InvokeAsync();
49+
}
50+
finally
51+
{
52+
_controllerFactory.ReleaseController(ActionContext.Controller);
53+
}
4654
}
4755

4856
protected override async Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)

test/Microsoft.AspNet.Mvc.Core.Test/ReflectedActionInvokerTest.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,12 +1272,12 @@ public void CreateActionResult_ReturnsObjectContentResult(Type type, object inpu
12721272
Assert.Same(input, contentResult.Value);
12731273
}
12741274

1275-
private ReflectedActionInvoker CreateInvoker(IFilter filter, bool actionThrows = false)
1275+
private TestReflectedActionInvoker CreateInvoker(IFilter filter, bool actionThrows = false)
12761276
{
12771277
return CreateInvoker(new[] { filter }, actionThrows);
12781278
}
12791279

1280-
private ReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrows = false)
1280+
private TestReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrows = false)
12811281
{
12821282
var actionDescriptor = new ReflectedActionDescriptor()
12831283
{
@@ -1319,6 +1319,7 @@ private ReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrow
13191319

13201320
var controllerFactory = new Mock<IControllerFactory>();
13211321
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>())).Returns(this);
1322+
controllerFactory.Setup(m => m.ReleaseController(this)).Verifiable();
13221323

13231324
var actionBindingContextProvider = new Mock<IActionBindingContextProvider>(MockBehavior.Strict);
13241325
actionBindingContextProvider
@@ -1333,11 +1334,12 @@ private ReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrow
13331334
var inputFormattersProvider = new Mock<IInputFormattersProvider>();
13341335
inputFormattersProvider.SetupGet(o => o.InputFormatters)
13351336
.Returns(new List<IInputFormatter>());
1336-
var invoker = new ReflectedActionInvoker(
1337+
1338+
var invoker = new TestReflectedActionInvoker(
13371339
actionContext,
13381340
actionBindingContextProvider.Object,
13391341
filterProvider.Object,
1340-
controllerFactory.Object,
1342+
controllerFactory,
13411343
actionDescriptor,
13421344
inputFormattersProvider.Object);
13431345

@@ -1613,5 +1615,34 @@ public Task ExecuteResultAsync(ActionContext context)
16131615
return Task.FromResult(0);
16141616
}
16151617
}
1618+
1619+
public class TestReflectedActionInvoker : ReflectedActionInvoker
1620+
{
1621+
private Mock<IControllerFactory> _factoryMock;
1622+
1623+
public TestReflectedActionInvoker(
1624+
ActionContext actionContext,
1625+
IActionBindingContextProvider bindingContextProvider,
1626+
INestedProviderManager<FilterProviderContext> filterProvider,
1627+
Mock<IControllerFactory> controllerFactoryMock,
1628+
ReflectedActionDescriptor descriptor,
1629+
IInputFormattersProvider inputFormattersProvider) :
1630+
base(actionContext,
1631+
bindingContextProvider,
1632+
filterProvider,
1633+
controllerFactoryMock.Object,
1634+
descriptor,
1635+
inputFormattersProvider)
1636+
{
1637+
_factoryMock = controllerFactoryMock;
1638+
}
1639+
1640+
public async override Task InvokeAsync()
1641+
{
1642+
await base.InvokeAsync();
1643+
1644+
_factoryMock.Verify();
1645+
}
1646+
}
16161647
}
16171648
}

0 commit comments

Comments
 (0)