Exemple #1
0
        public void api_routing_template___ctor_empty_template_gives_empty_variables(string template)
        {
            var t = new ApiRoutingTemplate(template);

            t.Variables.Should().NotBeNull();
            t.Variables.Should().HaveCount(0);
        }
Exemple #2
0
        public void api_routing_template___ctor_doesnt_fail_on_weird_templates(string template)
        {
            var t = new ApiRoutingTemplate(template);

            t.Variables.Should().NotBeNull();
            t.Variables.Should().BeEmpty();
        }
Exemple #3
0
        /// <summary>Gets the template information.</summary>
        /// <param name="context">The context.</param>
        /// <param name="resolver">The resolver.</param>
        /// <param name="routes">The routes.</param>
        /// <returns></returns>
        private static async Task <ApiRoutingTemplate> GetRoutingTemplate(
            this ApiRequestContext context,
            IUriRouteResolver resolver,
            IApiRoutingTable routes)
        {
            RouteMatch         result;
            ApiRoutingTemplate template = null;

            foreach (var route in routes.GetRoutes())
            {
                result = await resolver.ResolveRoute(route.Template, context.Request.Path).ConfigureAwait(false);

                if (result?.IsMatch ?? false)
                {
                    if (template == null)
                    {
                        template = new ApiRoutingTemplate(route.Template);
                    }

                    template.Locations.Add(new ApiEndpointLocation(
                                               controller: route.Location.Controller,
                                               methodInfo: route.Location.MethodInfo,
                                               httpMethod: route.Location.HttpMethod,
                                               bodyParameterType: route.Location.BodyParameterType,
                                               uriParameterType: route.Location.UriParameterType,
                                               simpleParameters: route.Location.SimpleParameters,
                                               methodReturnType: route.Location.MethodReturnType));
                }
            }

            return(template);
        }
Exemple #4
0
        public void api_routing_template___ctor_builds_up_variables(string template)
        {
            var t = new ApiRoutingTemplate(template);

            t.Variables.Should().NotBeNull();
            t.Variables.Should().HaveCount(4);
            t.Variables[0].Should().Be("MyVar1");
            t.Variables[1].Should().Be("myvar2");
            t.Variables[2].Should().Be("myVar3");
            t.Variables[3].Should().Be("myVar4");
        }