public async Task RouteAsync_Notifies_ActionSelected() { // Arrange var listener = new TestNotificationListener(); var context = CreateRouteContext(notificationListener: listener); context.RouteData.Values.Add("tag", "value"); var handler = new MvcRouteHandler(); // Act await handler.RouteAsync(context); // Assert Assert.NotNull(listener?.ActionSelected.ActionDescriptor); Assert.NotNull(listener?.ActionSelected.HttpContext); var routeValues = listener?.ActionSelected?.RouteData?.Values; Assert.NotNull(routeValues); Assert.Equal(1, routeValues.Count); Assert.Contains(routeValues, kvp => kvp.Key == "tag" && string.Equals(kvp.Value, "value")); }
public async Task ViewResult_NotifiesViewNotFound() { // Arrange var viewName = "myview"; var httpContext = GetHttpContext(); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var listener = new TestNotificationListener(); httpContext.RequestServices.GetRequiredService <INotifier>().EnlistTarget(listener); var viewEngine = new Mock <IViewEngine>(); var view = Mock.Of <IView>(); viewEngine.Setup(e => e.FindView(context, "myview")) .Returns(ViewEngineResult.NotFound("myview", new string[] { "location/myview" })); var viewResult = new ViewResult { ViewName = viewName, ViewEngine = viewEngine.Object, }; // Act await Assert.ThrowsAsync <InvalidOperationException>( async() => await viewResult.ExecuteResultAsync(context)); // Assert Assert.NotNull(listener.ViewResultViewNotFound); Assert.NotNull(listener.ViewResultViewNotFound.ActionContext); Assert.NotNull(listener.ViewResultViewNotFound.Result); Assert.Equal(new string[] { "location/myview" }, listener.ViewResultViewNotFound.SearchedLocations); Assert.Equal("myview", listener.ViewResultViewNotFound.ViewName); }
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.AfterAction?.ActionDescriptor); Assert.NotNull(listener.AfterAction?.HttpContext); }