public void ResolveShouldResolveCorrectlyWithPartialJsonContentBody() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithModel/5", "POST", body: @"{""Integer"":5}", contentType: ContentType.ApplicationJson)); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("ActionWithModel", routeInfo.Action); Assert.Equal(2, routeInfo.ActionArguments.Count); Assert.Equal(5, routeInfo.ActionArguments["id"].Value); Assert.True(routeInfo.ActionArguments.ContainsKey("model")); var model = routeInfo.ActionArguments["model"].Value as RequestModel; Assert.NotNull(model); Assert.Equal(5, model.Integer); Assert.Equal(null, model.String); Assert.False(routeInfo.ModelState.IsValid); }
public void ResolveShouldResolveCorrectlyWithJsonContentBodyAndQueryString() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithMultipleParameters/5", "POST", body: @"{""Integer"":5,""String"":""Test""}", queryString: "?text=test", contentType: ContentType.ApplicationJson)); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("ActionWithMultipleParameters", routeInfo.Action); Assert.Equal(3, routeInfo.ActionArguments.Count); Assert.Equal(5, routeInfo.ActionArguments["id"].Value); Assert.Equal("test", routeInfo.ActionArguments["text"].Value); Assert.True(routeInfo.ActionArguments.ContainsKey("model")); var model = routeInfo.ActionArguments["model"].Value as RequestModel; Assert.NotNull(model); Assert.Equal(5, model.Integer); Assert.Equal("Test", model.String); Assert.True(routeInfo.ModelState.IsValid); }
public void ResolveShouldNotCallTheActualActionCode() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Home/FailingAction")); Assert.True(routeInfo.IsResolved); }
public void ResolveShouldResolveCorrectlyWithRouteAttribute() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/AttributeController/AttributeAction")); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(RouteController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Route", routeInfo.ControllerName); Assert.Equal("Index", routeInfo.Action); Assert.Equal(0, routeInfo.ActionArguments.Count); Assert.True(routeInfo.ModelState.IsValid); }
public void ResolveShouldResolveCorrectControllerAndActionWithActionNameAttribute() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/AnotherName")); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("AnotherName", routeInfo.Action); Assert.Equal(0, routeInfo.ActionArguments.Count); Assert.True(routeInfo.ModelState.IsValid); }
public void ResolveShouldResolveCorrectlyWithMissingQueryString() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/QueryString", "POST")); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("QueryString", routeInfo.Action); Assert.Equal(0, routeInfo.ActionArguments.Count); Assert.True(routeInfo.ModelState.IsValid); }
public void ResolveShouldResolveCorrectlyWithWrongSpecificMethod() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/GetMethod", "POST")); Assert.False(routeInfo.IsResolved); Assert.Equal("action could not be matched", routeInfo.UnresolvedError); Assert.Null(routeInfo.ControllerType); Assert.Null(routeInfo.ControllerName); Assert.Null(routeInfo.Action); Assert.Null(routeInfo.ActionArguments); Assert.Null(routeInfo.ModelState); }
public void ResolveShouldResolveCorrectlyWithNonMatchingParameterOfDifferentType() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithParameters/Test")); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("ActionWithParameters", routeInfo.Action); Assert.Equal(0, routeInfo.ActionArguments.Count); Assert.False(routeInfo.ModelState.IsValid); }
public void ResolveShouldReturnProperErrorWhenTwoActionsAreMatched() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithOverloads")); Assert.False(routeInfo.IsResolved); Assert.Equal( "exception was thrown when trying to select an action: 'Multiple actions matched. The following actions matched route data and had all constraints satisfied:\r\n\r\nMyTested.AspNetCore.Mvc.Test.Setups.Routing.NormalController.ActionWithOverloads (MyTested.AspNetCore.Mvc.Test.Setups)\r\nMyTested.AspNetCore.Mvc.Test.Setups.Routing.NormalController.ActionWithOverloads (MyTested.AspNetCore.Mvc.Test.Setups)'", routeInfo.UnresolvedError); Assert.Null(routeInfo.ControllerType); Assert.Null(routeInfo.ControllerName); Assert.Null(routeInfo.Action); Assert.Null(routeInfo.ActionArguments); Assert.Null(routeInfo.ModelState); }
public void ResolveShouldReturnProperErrorWhenRequestFiltersArePresentAndRequestIsNotSetup() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/FiltersAction")); Assert.False(routeInfo.IsResolved); Assert.Equal( "action could not be invoked because of the declared filters. You must set the request properties so that they will pass through the pipeline", routeInfo.UnresolvedError); Assert.Null(routeInfo.ControllerType); Assert.Null(routeInfo.ControllerName); Assert.Null(routeInfo.Action); Assert.Null(routeInfo.ActionArguments); Assert.Null(routeInfo.ModelState); }
public void ResolveShouldResolveCorrectlyWithEmptyJsonContentBody() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithModel/5", "POST", contentType: ContentType.ApplicationJson)); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("ActionWithModel", routeInfo.Action); Assert.Equal(1, routeInfo.ActionArguments.Count); Assert.Equal(5, routeInfo.ActionArguments["id"].Value); Assert.False(routeInfo.ActionArguments.ContainsKey("model")); Assert.False(routeInfo.ModelState.IsValid); }
public void ResolveShouldResolveCorrectlyWithParameterAndQueryString() { var routeInfo = MvcRouteResolver.Resolve( TestApplication.RoutingServices, TestApplication.Router, this.GetRouteContext("/Normal/ActionWithMultipleParameters/5", queryString: "?text=test", contentType: ContentType.ApplicationJson)); Assert.True(routeInfo.IsResolved); Assert.Null(routeInfo.UnresolvedError); Assert.Equal(typeof(NormalController).GetTypeInfo(), routeInfo.ControllerType); Assert.Equal("Normal", routeInfo.ControllerName); Assert.Equal("ActionWithMultipleParameters", routeInfo.Action); Assert.Equal(3, routeInfo.ActionArguments.Count); Assert.Equal(5, routeInfo.ActionArguments["id"].Value); Assert.Equal("test", routeInfo.ActionArguments["text"].Value); Assert.True(routeInfo.ActionArguments.ContainsKey("model")); Assert.True(routeInfo.ModelState.IsValid); }
public ResolvedRouteContext GetActualRouteInfo() { return(this.actualRouteInfo ?? (this.actualRouteInfo = MvcRouteResolver.Resolve(this.Services, this.Router, this.RouteContext))); }