Add an event notification for when the action is invoked
This commit is contained in:
parent
8e402af47e
commit
6170ac1924
|
|
@ -85,6 +85,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
await InvokeActionAsync(context, actionDescriptor);
|
||||
context.IsHandled = true;
|
||||
}
|
||||
|
||||
if (_notifier.ShouldNotify("Microsoft.AspNet.Mvc.ActionInvoked"))
|
||||
{
|
||||
_notifier.Notify(
|
||||
"Microsoft.AspNet.Mvc.ActionInvoked",
|
||||
new { actionDescriptor, httpContext = context.HttpContext });
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -179,6 +179,24 @@ namespace Microsoft.AspNet.Mvc
|
|||
Assert.Contains(routeValues, kvp => kvp.Key == "tag" && string.Equals(kvp.Value, "value"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RouteAsync_Notifies_ActionInvoked()
|
||||
{
|
||||
// Arrange
|
||||
var listener = new TestNotificationListener();
|
||||
|
||||
var context = CreateRouteContext(notificationListener: listener);
|
||||
|
||||
var handler = new MvcRouteHandler();
|
||||
|
||||
// Act
|
||||
await handler.RouteAsync(context);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(listener?.ActionInvoked.ActionDescriptor);
|
||||
Assert.NotNull(listener?.ActionInvoked.HttpContext);
|
||||
}
|
||||
|
||||
private RouteContext CreateRouteContext(
|
||||
ActionDescriptor actionDescriptor = null,
|
||||
IActionSelector actionSelector = null,
|
||||
|
|
|
|||
|
|
@ -23,11 +23,31 @@ namespace Microsoft.AspNet.Mvc.TestCommon.Notification
|
|||
};
|
||||
}
|
||||
|
||||
public OnActionInvokedEventData ActionInvoked { get; set; }
|
||||
|
||||
[NotificationName("Microsoft.AspNet.Mvc.ActionInvoked")]
|
||||
public virtual void OnActionInvoked(
|
||||
IHttpContext httpContext,
|
||||
IActionDescriptor actionDescriptor)
|
||||
{
|
||||
ActionInvoked = new OnActionInvokedEventData()
|
||||
{
|
||||
ActionDescriptor = actionDescriptor,
|
||||
HttpContext = httpContext,
|
||||
};
|
||||
}
|
||||
|
||||
public class OnActionSelectedEventData
|
||||
{
|
||||
public IActionDescriptor ActionDescriptor { get; set; }
|
||||
public IHttpContext HttpContext { get; set; }
|
||||
public IRouteData RouteData { get; set; }
|
||||
}
|
||||
|
||||
public class OnActionInvokedEventData
|
||||
{
|
||||
public IActionDescriptor ActionDescriptor { get; set; }
|
||||
public IHttpContext HttpContext { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue