public void IgnoreRoute_GetVirtualPathReturnsNull() { // Arrange DomainHttpRoute route = new DomainHttpRoute("myDomain", "api/{controller}/{action}", new { controller = "SomeValue", action = "SomeAction" }); HostedHttpRouteCollection collection = new HostedHttpRouteCollection(new RouteCollection()); collection.IgnoreRoute("domainRoute", route.RouteTemplate); HttpRequestMessage request = CreateHttpRequestMessageWithContext(); HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary() { { "controller", "controllerName" }, { "action", "actionName" }, { "httproute", true } }; request.SetRouteData(new HttpRouteData(route, routeValues)); // Act IHttpVirtualPathData httpvPathData = collection.GetVirtualPath(request, "domainRoute", routeValues); // Assert // Altough it contains the ignore route, GetVirtualPath from the ignored route will always return null. Assert.Equal(collection.Count, 1); Assert.Null(httpvPathData); }
public void CustomHttpRouteGetVitualPathRunsCustomHttpRoute() { // Arrange DomainHttpRoute route = new DomainHttpRoute( "myDomain", "api/{controller}/{action}", new { controller = "SomeValue", action = "SomeAction" } ); HostedHttpRouteCollection collection = new HostedHttpRouteCollection( new RouteCollection() ); collection.Add("domainRoute", route); HttpRequestMessage request = CreateHttpRequestMessageWithContext(); HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary() { { "controller", "controllerName" }, { "action", "actionName" }, { "httproute", true } }; request.SetRouteData(new HttpRouteData(route, routeValues)); // Act IHttpVirtualPathData httpvPathData = collection.GetVirtualPath( request, "domainRoute", routeValues ); // Assert Assert.NotNull(httpvPathData); Assert.Equal("/api/controllerName/actionNameFromDomain", httpvPathData.VirtualPath); }
public void CustomHttpRouteGetVitualPathRunsCustomHttpRoute() { // Arrange DomainHttpRoute route = new DomainHttpRoute("myDomain", "api/{controller}/{action}", new { controller = "SomeValue", action = "SomeAction" }); HostedHttpRouteCollection collection = new HostedHttpRouteCollection(new RouteCollection()); collection.Add("domainRoute", route); HttpRequestMessage request = CreateHttpRequestMessageWithContext(); HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary() { {"controller", "controllerName"}, {"action", "actionName"}, {"httproute", true} }; request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(route, routeValues); // Act IHttpVirtualPathData httpvPathData = collection.GetVirtualPath(request, "domainRoute", routeValues); // Assert Assert.NotNull(httpvPathData); Assert.Equal("/api/controllerName/actionNameFromDomain", httpvPathData.VirtualPath); }
public void GetVirtualPath_GuardClauses() { Assert.ThrowsArgumentNull(() => _webApiRoutes.GetVirtualPath(request: null, name: null, values: null), "request"); }