コード例 #1
0
        public void Should_return_default_url_when_override_not_specified()
        {
            var actionMethod = Type <Handler> .Expression(x => x.NoOverride()).ToActionMethod();

            var urls = new DefaultUrlConvention()
                       .GetUrls(new UrlContext(null, null, actionMethod,
                                               null, new []  { "some", "url" },
                                               null, null, null, null, null));

            urls.ShouldOnlyContain("some/url");
        }
コード例 #2
0
        public void Should_return_overriden_urls()
        {
            var actionMethod = Type <Handler> .Method(x => x.Override()).ToActionMethod <Handler>();

            var urls = new DefaultUrlConvention()
                       .GetUrls(new UrlContext(null, null, actionMethod,
                                               null, new[] { "some", "url" },
                                               null, null, null, null, null));

            urls.ShouldOnlyContain("url1", "url2");
        }
コード例 #3
0
        public void Should_return_attribute_url_aliases()
        {
            var actionMethod = ActionMethod.From <AliasHandler>(x => x.Get());
            var urls         = new DefaultUrlConvention(_configuration, null)
                               .GetUrls(new UrlContext(actionMethod,
                                                       null, new List <UrlSegment>
            {
                new UrlSegment("some"),
                new UrlSegment("url")
            }, null, null, null, null));

            urls.ShouldOnlyContain("Unit/Routing/some/url", "url1", "url2");
        }
コード例 #4
0
        public void Should_return_default_url_when_override_not_specified()
        {
            var actionMethod = ActionMethod.From <Handler>(x => x.NoOverride());
            var urls         = new DefaultUrlConvention(_configuration, null)
                               .GetUrls(new UrlContext(actionMethod,
                                                       null, new List <UrlSegment>
            {
                new UrlSegment("some"),
                new UrlSegment("url")
            },
                                                       null, null, null, null));

            urls.ShouldOnlyContain("Unit/Routing/some/url");
        }
コード例 #5
0
        public void Should_return_overriden_urls()
        {
            var actionMethod = ActionMethod.From <Handler>(x => x.Override());
            var urls         = new DefaultUrlConvention(_configuration, null)
                               .GetUrls(new UrlContext(actionMethod,
                                                       null, new List <UrlSegment>
            {
                new UrlSegment("some"),
                new UrlSegment("url")
            },
                                                       null, null, null, null));

            urls.ShouldOnlyContain("url1", "url2");
        }
コード例 #6
0
        public void Should_add_url_prefix(string prefix, string expected)
        {
            var actionMethod = ActionMethod.From <Handler>(x => x.NoOverride());

            _configuration.UrlPrefix = prefix;
            var urls = new DefaultUrlConvention(_configuration, null)
                       .GetUrls(new UrlContext(actionMethod,
                                               null, new List <UrlSegment>
            {
                new UrlSegment("some"),
                new UrlSegment("url")
            },
                                               null, null, null, null));

            urls.ShouldOnlyContain(expected);
        }
コード例 #7
0
        public void Should_return_conventional_url_aliases()
        {
            var actionMethod = ActionMethod.From <AliasHandler>(x => x.Post());

            _configuration.UrlAliases.Add(x => $"{x.ActionMethod.MethodDescriptor.Name}/url1/{x.MethodSegments.ToUrl()}");
            _configuration.UrlAliases.Add(x => $"{x.ActionMethod.MethodDescriptor.Name}/url2/{x.MethodSegments.ToUrl()}");
            var urls = new DefaultUrlConvention(_configuration, null)
                       .GetUrls(new UrlContext(actionMethod,
                                               null, new List <UrlSegment>
            {
                new UrlSegment("some"),
                new UrlSegment("url")
            },
                                               null, null, null, null));

            urls.ShouldOnlyContain("Unit/Routing/some/url",
                                   "Post/url1/some/url", "Post/url2/some/url");
        }
コード例 #8
0
        public List <ActionDescriptor> GetActions()
        {
            var configuration      = new Configuration();
            var actionMethodSource = new DefaultActionMethodSource(configuration, _typeCache);
            var urlConvention      = new DefaultUrlConvention(configuration, _httpConfiguration);
            var routeConvention    = new DefaultRouteConvention(configuration,
                                                                _httpConfiguration, urlConvention.AsList <IUrlConvention>(), _constraintBuilder);

            new ConfigurationDsl(configuration, _httpConfiguration)
            .IncludeTypeAssembly <DiagnosticsActionSource>()
            .OnlyIncludeHandlersUnder <DiagnosticsActionSource>()
            .ConfigureNamespaceUrlMapping(x => x.Clear()
                                          .MapNamespaceAfter <DiagnosticsActionSource>())
            .WithUrlPrefix(_configuration.DiagnosticsUrl.Trim('/'))
            .ConfigureUrlConventions(x => x.Clear().Append(urlConvention))
            .ConfigureActionMethodSources(x => x.Clear().Append(actionMethodSource))
            .ConfigureRouteConventions(x => x.Clear().Append(routeConvention));

            return(new DefaultActionSource(configuration, _httpConfiguration,
                                           actionMethodSource.AsList(), routeConvention.AsList(),
                                           _actionDescriptorFactory).GetActions());
        }