示例#1
0
        public void RouteUrlWithUrlRouteContext_ReturnsExpectedResult()
        {
            // Arrange
            var services  = GetServices();
            var urlHelper = CreateUrlHelperWithRouteCollection(services, "/app");

            var routeContext = new UrlRouteContext()
            {
                RouteName = "namedroute",
                Values    = new
                {
                    Action     = "newaction",
                    Controller = "home2",
                    id         = "someid"
                },
                Fragment = "somefragment",
                Host     = "remotetown",
                Protocol = "ftp"
            };

            // Act
            var url = urlHelper.RouteUrl(routeContext);

            // Assert
            Assert.Equal("ftp://remotetown/app/named/home2/newaction/someid#somefragment", url);
        }
示例#2
0
            public string RouteUrl(UrlRouteContext routeContext)
            {
                Assert.Equal(_routeName, routeContext.RouteName);
                Assert.Null(routeContext.Protocol);
                Assert.Null(routeContext.Host);
                Assert.Null(routeContext.Fragment);

                RouteValues = routeContext.Values;

                return(_url);
            }
示例#3
0
文件: UrlHelper.cs 项目: notami18/Mvc
        /// <inheritdoc />
        public virtual string RouteUrl(UrlRouteContext routeContext)
        {
            var valuesDictionary = PropertyHelper.ObjectToDictionary(routeContext.Values);

            var path = GeneratePathFromRoute(routeContext.RouteName, valuesDictionary);
            if (path == null)
            {
                return null;
            }

            return GenerateUrl(routeContext.Protocol, routeContext.Host, path, routeContext.Fragment);
        }
示例#4
0
        /// <inheritdoc />
        public virtual string RouteUrl(UrlRouteContext routeContext)
        {
            var valuesDictionary = PropertyHelper.ObjectToDictionary(routeContext.Values);

            var path = GeneratePathFromRoute(routeContext.RouteName, valuesDictionary);

            if (path == null)
            {
                return(null);
            }

            return(GenerateUrl(routeContext.Protocol, routeContext.Host, path, routeContext.Fragment));
        }
示例#5
0
 public override string RouteUrl(UrlRouteContext routeContext)
 {
     return ConvertToLowercaseUrl(base.RouteUrl(routeContext));
 }
            public string RouteUrl(UrlRouteContext routeContext)
            {
                Assert.Equal(_routeName, routeContext.RouteName);
                Assert.Null(routeContext.Protocol);
                Assert.Null(routeContext.Host);
                Assert.Null(routeContext.Fragment);

                RouteValues = routeContext.Values;

                return _url;
            }
示例#7
0
        public void RouteUrlWithUrlRouteContext_ReturnsExpectedResult()
        {
            // Arrange
            var services = GetServices();
            var urlHelper = CreateUrlHelperWithRouteCollection(services, "/app");

            var routeContext = new UrlRouteContext()
            {
                RouteName = "namedroute",
                Values = new
                {
                    Action = "newaction",
                    Controller = "home2",
                    id = "someid"
                },
                Fragment = "somefragment",
                Host = "remotetown",
                Protocol = "ftp"
            };

            // Act
            var url = urlHelper.RouteUrl(routeContext);

            // Assert
            Assert.Equal("ftp://remotetown/app/named/home2/newaction/someid#somefragment", url);
        }