예제 #1
0
    public void MapUmbracoRoute(string umbracoPath, string area, string prefix, string defaultAction, bool includeControllerName)
    {
        var endpoints = new TestRouteBuilder();

        endpoints.MapUmbracoRoute <Testing1Controller>(umbracoPath, area, prefix, defaultAction, includeControllerName);

        var route    = endpoints.DataSources.First();
        var endpoint = (RouteEndpoint)route.Endpoints[0];

        var controllerName        = ControllerExtensions.GetControllerName <Testing1Controller>();
        var controllerNamePattern = controllerName.ToLowerInvariant();

        if (includeControllerName)
        {
            if (prefix.IsNullOrWhiteSpace())
            {
                Assert.AreEqual(
                    $"{umbracoPath}/{controllerNamePattern}/{{action}}/{{id?}}",
                    endpoint.RoutePattern.RawText);
            }
            else
            {
                Assert.AreEqual(
                    $"{umbracoPath}/{prefix}/{controllerNamePattern}/{{action}}/{{id?}}",
                    endpoint.RoutePattern.RawText);
            }
        }
        else
        {
            if (prefix.IsNullOrWhiteSpace())
            {
                Assert.AreEqual($"{umbracoPath}/{{action}}/{{id?}}", endpoint.RoutePattern.RawText);
            }
            else
            {
                Assert.AreEqual($"{umbracoPath}/{prefix}/{{action}}/{{id?}}", endpoint.RoutePattern.RawText);
            }
        }

        if (!area.IsNullOrWhiteSpace())
        {
            Assert.AreEqual(area, endpoint.RoutePattern.Defaults[AreaToken]);
        }

        if (!defaultAction.IsNullOrWhiteSpace())
        {
            Assert.AreEqual(defaultAction, endpoint.RoutePattern.Defaults["action"]);
        }

        Assert.AreEqual(controllerName, endpoint.RoutePattern.Defaults[ControllerToken]);
    }