public void ResolveShouldResolveCorrectlyWithSpecificMethod()
        {
            var config  = TestObjectFactory.GetHttpConfigurationWithRoutes();
            var request = new HttpRequestMessage(HttpMethod.Get, "api/Route/GetMethod");

            var routeInfo = InternalRouteResolver.Resolve(config, request);

            Assert.IsTrue(routeInfo.IsResolved);
            Assert.IsFalse(routeInfo.IsIgnored);
            Assert.IsFalse(routeInfo.MethodIsNotAllowed);
            Assert.IsNullOrEmpty(routeInfo.UnresolvedError);
            Assert.AreEqual(typeof(RouteController), routeInfo.Controller);
            Assert.AreEqual("GetMethod", routeInfo.Action);
            Assert.AreEqual(0, routeInfo.ActionArguments.Count);
            Assert.IsNull(routeInfo.HttpMessageHandler);
            Assert.IsTrue(routeInfo.ModelState.IsValid);
        }
Exemple #2
0
        public void ResolveShouldReturnProperErrorWhenTwoActionsAreMatched()
        {
            var routeInfo = InternalRouteResolver.Resolve(
                TestApplication.RouteServices,
                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.Routes.NormalController.ActionWithOverloads (MyTested.AspNetCore.Mvc.Test)\r\nMyTested.AspNetCore.Mvc.Test.Setups.Routes.NormalController.ActionWithOverloads (MyTested.AspNetCore.Mvc.Test)'",
                routeInfo.UnresolvedError);
            Assert.Null(routeInfo.ControllerType);
            Assert.Null(routeInfo.ControllerName);
            Assert.Null(routeInfo.Action);
            Assert.Null(routeInfo.ActionArguments);
            Assert.Null(routeInfo.ModelState);
        }
Exemple #3
0
        public void ResolveShouldResolveCorrectlyWithFullQueryString()
        {
            var routeInfo = InternalRouteResolver.Resolve(
                TestApplication.RouteServices,
                TestApplication.Router,
                this.GetRouteContext("/Normal/QueryString", "POST", "?first=test&second=5"));

            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(2, routeInfo.ActionArguments.Count);
            Assert.Equal("test", routeInfo.ActionArguments["first"].Value);
            Assert.Equal(5, routeInfo.ActionArguments["second"].Value);
            Assert.True(routeInfo.ModelState.IsValid);
        }
Exemple #4
0
        public void ResolveShouldReturnProperErrorWhenTwoActionsAreMatched()
        {
            var config  = TestObjectFactory.GetHttpConfigurationWithRoutes();
            var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/SameAction");

            var routeInfo = InternalRouteResolver.Resolve(config, request);

            Assert.IsFalse(routeInfo.IsResolved);
            Assert.IsFalse(routeInfo.IsIgnored);
            Assert.IsFalse(routeInfo.MethodIsNotAllowed);
            Assert.AreEqual("it could not be resolved: 'Multiple actions were found that match the request'", routeInfo.UnresolvedError);
            Assert.IsNull(routeInfo.Controller);
            Assert.IsNull(routeInfo.Action);
            Assert.IsNull(routeInfo.ActionArguments);
            Assert.IsNull(routeInfo.HttpMessageHandler);
            Assert.IsNull(routeInfo.ModelState);
        }
Exemple #5
0
        public void ResolveShouldNotResolveCorrectlyWithMissingQueryString()
        {
            var config  = TestObjectFactory.GetHttpConfigurationWithRoutes();
            var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/QueryString");

            var routeInfo = InternalRouteResolver.Resolve(config, request);

            Assert.IsFalse(routeInfo.IsResolved);
            Assert.IsFalse(routeInfo.IsIgnored);
            Assert.IsFalse(routeInfo.MethodIsNotAllowed);
            Assert.AreEqual("it could not be resolved: 'Not Found'", routeInfo.UnresolvedError);
            Assert.IsNull(routeInfo.Controller);
            Assert.IsNull(routeInfo.Action);
            Assert.IsNull(routeInfo.ActionArguments);
            Assert.IsNull(routeInfo.HttpMessageHandler);
            Assert.IsNull(routeInfo.ModelState);
        }
Exemple #6
0
        public void ResolveShouldResolveCorrectControllerAndAction()
        {
            var config  = TestObjectFactory.GetHttpConfigurationWithRoutes();
            var request = new HttpRequestMessage(HttpMethod.Post, "api/NoParameterlessConstructor/OkAction");

            var routeInfo = InternalRouteResolver.Resolve(config, request);

            Assert.IsTrue(routeInfo.IsResolved);
            Assert.IsFalse(routeInfo.IsIgnored);
            Assert.IsFalse(routeInfo.MethodIsNotAllowed);
            Assert.IsNullOrEmpty(routeInfo.UnresolvedError);
            Assert.AreEqual(typeof(NoParameterlessConstructorController), routeInfo.Controller);
            Assert.AreEqual("OkAction", routeInfo.Action);
            Assert.AreEqual(0, routeInfo.ActionArguments.Count);
            Assert.IsNull(routeInfo.HttpMessageHandler);
            Assert.IsTrue(routeInfo.ModelState.IsValid);
        }
        public void ResolveShouldResolveCorrectlyWithParameterAndQueryString()
        {
            var config  = TestObjectFactory.GetHttpConfigurationWithRoutes();
            var request = new HttpRequestMessage(HttpMethod.Post, "api/Route/WithParameterAndQueryString/5?value=test");

            var routeInfo = InternalRouteResolver.Resolve(config, request);

            Assert.IsTrue(routeInfo.IsResolved);
            Assert.IsFalse(routeInfo.IsIgnored);
            Assert.IsFalse(routeInfo.MethodIsNotAllowed);
            Assert.IsNullOrEmpty(routeInfo.UnresolvedError);
            Assert.AreEqual(typeof(RouteController), routeInfo.Controller);
            Assert.AreEqual("WithParameterAndQueryString", routeInfo.Action);
            Assert.AreEqual(5, routeInfo.ActionArguments["id"].Value);
            Assert.AreEqual("test", routeInfo.ActionArguments["value"].Value);
            Assert.IsNull(routeInfo.HttpMessageHandler);
            Assert.IsTrue(routeInfo.ModelState.IsValid);
        }
Exemple #8
0
        public void ResolveShouldResolveCorrectlyWithParameterAndQueryString()
        {
            var routeInfo = InternalRouteResolver.Resolve(
                TestApplication.RouteServices,
                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);
        }
Exemple #9
0
        public void ResolveShouldResolveCorrectlyWithEmptyJsonContentBody()
        {
            var routeInfo = InternalRouteResolver.Resolve(
                TestApplication.RouteServices,
                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(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.Null(model);

            Assert.True(routeInfo.ModelState.IsValid);
        }
Exemple #10
0
 public ResolvedRouteContext GetActualRouteInfo()
 {
     return(this.actualRouteInfo ??
            (this.actualRouteInfo = InternalRouteResolver.Resolve(this.Services, this.Router, this.RouteContext)));
 }
Exemple #11
0
 private ResolvedRouteInfo GetActualRouteInfo()
 {
     return(this.actualRouteInfo ??
            (this.actualRouteInfo = InternalRouteResolver.Resolve(this.HttpConfiguration, this.requestMessage)));
 }