Example #1
0
        public void api_descriptions_should_recognize_composite_routes()
        {
            // arrange
            var configuration        = new HttpConfiguration();
            var routeTemplate        = "api/values";
            var controllerDescriptor = new HttpControllerDescriptor(configuration, "AttributeApiExplorerValues", typeof(AttributeApiExplorerValuesController));
            var action          = new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(AttributeApiExplorerValuesController).GetMethod("Action"));
            var actions         = new ReflectedHttpActionDescriptor[] { action };
            var routeCollection = new List <IHttpRoute>()
            {
                CreateDirectRoute(routeTemplate, actions)
            };
            var route = NewRouteCollectionRoute();

            route.EnsureInitialized(() => routeCollection);
            configuration.Routes.Add("Route", route);

            IApiExplorer apiExplorer = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.Single().Should().Should().BeEquivalentTo(
                new { HttpMethod = Get, RelativePath = routeTemplate, ActionDescriptor = action },
                options => options.ExcludingMissingMembers());
        }
Example #2
0
        public void api_descriptions_should_ignore_api_for_direct_route_action()
        {
            // arrange
            var configuration = new HttpConfiguration();
            var routeTemplate = "api/values";
            var model         = new ApiVersionModel(new ApiVersion(1, 0));
            var controller    = new HttpControllerDescriptor(configuration, "ApiExplorerValues", typeof(ApiExplorerValuesController));
            var actions       = new ReflectedHttpActionDescriptor[]
            {
                new ReflectedHttpActionDescriptor(controller, typeof(ApiExplorerValuesController).GetMethod("Get"))
                {
                    Properties = { [typeof(ApiVersionModel)] = model },
                },
                new ReflectedHttpActionDescriptor(controller, typeof(ApiExplorerValuesController).GetMethod("Post"))
                {
                    Properties = { [typeof(ApiVersionModel)] = model },
                },
            };

            configuration.Routes.Add("Route", CreateDirectRoute(routeTemplate, actions));

            IApiExplorer apiExplorer = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.Single().Should().Should().BeEquivalentTo(
                new { HttpMethod = Get, RelativePath = routeTemplate },
                options => options.ExcludingMissingMembers());
        }
Example #3
0
        public void api_description_group_should_explore_v3_beta_actions(HttpConfiguration configuration)
        {
            // arrange
            var apiExplorer      = new VersionedApiExplorer(configuration);
            var apiVersion       = new ApiVersion(3, 0, "beta");
            var descriptionGroup = apiExplorer.ApiDescriptions[apiVersion];

            // act
            var descriptions  = descriptionGroup.ApiDescriptions;
            var relativePaths = descriptions.Select(d => d.RelativePath).ToArray();

            // assert
            descriptionGroup.IsDeprecated.Should().BeTrue();
            descriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    ID           = $"GET{relativePaths[0]}",
                    HttpMethod   = Get,
                    RelativePath = relativePaths[0],
                    Version      = apiVersion
                },
                new
                {
                    ID           = $"GET{relativePaths[1]}",
                    HttpMethod   = Get,
                    RelativePath = relativePaths[1],
                    Version      = apiVersion
                }
            },
                options => options.ExcludingMissingMembers());
        }
Example #4
0
        public void api_description_group_should_explore_v2_actions(HttpConfiguration configuration)
        {
            // arrange
            var apiExplorer      = new VersionedApiExplorer(configuration);
            var apiVersion       = new ApiVersion(2, 0);
            var descriptionGroup = apiExplorer.ApiDescriptions[apiVersion];

            // act
            var descriptions = descriptionGroup.ApiDescriptions;

            // assert
            descriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    ID           = "GETValues",
                    HttpMethod   = Get,
                    RelativePath = "Values",
                    Version      = apiVersion
                },
                new
                {
                    ID           = "GETValues/{id}",
                    HttpMethod   = Get,
                    RelativePath = "Values/{id}",
                    Version      = apiVersion
                }
            },
                options => options.ExcludingMissingMembers());
        }
Example #5
0
        public void api_descriptions_should_collate_expected_versions(HttpConfiguration configuration)
        {
            // arrange
            var apiExplorer = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.ApiVersions.Should().Equal(
                new ApiVersion(1, 0),
                new ApiVersion(2, 0),
                new ApiVersion(3, 0, "beta"),
                new ApiVersion(3, 0),
                new ApiVersion(4, 0));
        }
Example #6
0
        public void api_description_group_should_explore_v4_actions(HttpConfiguration configuration)
        {
            // arrange
            var apiExplorer      = new VersionedApiExplorer(configuration);
            var apiVersion       = new ApiVersion(4, 0);
            var descriptionGroup = apiExplorer.ApiDescriptions[apiVersion];

            // act
            var descriptions  = descriptionGroup.ApiDescriptions;
            var relativePaths = descriptions.Select(d => d.RelativePath).ToArray();

            // assert
            descriptions.Should().BeEquivalentTo(
                new[]
            {
                new
                {
                    ID           = $"GET{relativePaths[0]}",
                    HttpMethod   = Get,
                    RelativePath = relativePaths[0],
                    Version      = apiVersion
                },
                new
                {
                    ID           = $"GET{relativePaths[1]}",
                    HttpMethod   = Get,
                    RelativePath = relativePaths[1],
                    Version      = apiVersion
                },
                new
                {
                    ID           = $"POST{relativePaths[2]}",
                    HttpMethod   = Post,
                    RelativePath = relativePaths[2],
                    Version      = apiVersion
                },
                new
                {
                    ID           = $"DELETE{relativePaths[3]}",
                    HttpMethod   = Delete,
                    RelativePath = relativePaths[3],
                    Version      = apiVersion
                }
            },
                options => options.ExcludingMissingMembers());
        }
Example #7
0
        public void api_descriptions_should_flatten_versioned_controllers(HttpConfiguration configuration)
        {
            // arrange
            var assembliesResolver = configuration.Services.GetAssembliesResolver();
            var controllerTypes    = configuration.Services.GetHttpControllerTypeResolver().GetControllerTypes(assembliesResolver);
            var apiExplorer        = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.Flatten()
            .Select(d => d.ActionDescriptor.ControllerDescriptor.ControllerType)
            .Distinct()
            .Should()
            .Equal(controllerTypes);
        }
Example #8
0
        public void api_descriptions_should_recognize_direct_routes()
        {
            // arrange
            var configuration        = new HttpConfiguration();
            var routeTemplate        = "api/values";
            var controllerDescriptor = new HttpControllerDescriptor(configuration, "ApiExplorerValues", typeof(ApiExplorerValuesController));
            var action  = new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(ApiExplorerValuesController).GetMethod("Get"));
            var actions = new ReflectedHttpActionDescriptor[] { action };

            configuration.Routes.Add("Route", CreateDirectRoute(routeTemplate, actions));

            IApiExplorer apiExplorer = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.Single().Should().Should().BeEquivalentTo(
                new { HttpMethod = Get, RelativePath = routeTemplate, ActionDescriptor = action },
                options => options.ExcludingMissingMembers());
        }
Example #9
0
        public void api_descriptions_should_ignore_api_for_direct_route_controller()
        {
            // arrange
            var configuration        = new HttpConfiguration();
            var routeTemplate        = "api/values";
            var controllerDescriptor = new HttpControllerDescriptor(configuration, "IgnoreApiValues", typeof(IgnoreApiValuesController));
            var actions = new ReflectedHttpActionDescriptor[]
            {
                new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(IgnoreApiValuesController).GetMethod("Get")),
                new ReflectedHttpActionDescriptor(controllerDescriptor, typeof(IgnoreApiValuesController).GetMethod("Post")),
            };

            configuration.Routes.Add("Route", CreateDirectRoute(routeTemplate, actions));

            IApiExplorer apiExplorer = new VersionedApiExplorer(configuration);

            // act
            var descriptions = apiExplorer.ApiDescriptions;

            // assert
            descriptions.Should().BeEmpty();
        }
Example #10
0
        public void api_description_group_should_explore_v1_actions(HttpConfiguration configuration)
        {
            // arrange
            var apiExplorer      = new VersionedApiExplorer(configuration);
            var apiVersion       = new ApiVersion(1, 0);
            var descriptionGroup = apiExplorer.ApiDescriptions[apiVersion];

            // act
            var description  = descriptionGroup.ApiDescriptions.Single();
            var relativePath = description.RelativePath;

            // assert
            description.Should().BeEquivalentTo(
                new
            {
                ID           = $"GET{relativePath}",
                HttpMethod   = Get,
                RelativePath = relativePath,
                Version      = apiVersion
            },
                options => options.ExcludingMissingMembers());
        }