Beispiel #1
0
        public void add_api_versioning_should_configure_mvc_with_custom_options()
        {
            // arrange
            var services = new ServiceCollection();

            // act
            services.AddApiVersioning(
                options =>
            {
                options.ReportApiVersions  = true;
                options.ApiVersionReader   = ApiVersionReader.Combine(new QueryStringApiVersionReader(), new HeaderApiVersionReader("api-version"));
                options.ApiVersionSelector = new ConstantApiVersionSelector(new ApiVersion(DateTime.Today));
            });

            // assert
            services.Single(sd => sd.ServiceType == typeof(IApiVersionReader)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IApiVersionSelector)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IErrorResponseProvider)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IActionSelector)).ImplementationType.Should().Be(typeof(ApiVersionActionSelector));
            services.Single(sd => sd.ServiceType == typeof(IApiVersionRoutePolicy)).ImplementationType.Should().Be(typeof(DefaultApiVersionRoutePolicy));
            services.Single(sd => sd.ServiceType == typeof(ReportApiVersionsAttribute)).ImplementationType.Should().Be(typeof(ReportApiVersionsAttribute));
            services.Single(sd => sd.ServiceType == typeof(IReportApiVersions)).ImplementationFactory.Should().NotBeNull();
            services.Any(sd => sd.ServiceType == typeof(IPostConfigureOptions <MvcOptions>) && sd.ImplementationType == typeof(ApiVersioningMvcOptionsSetup)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IPostConfigureOptions <RouteOptions>) && sd.ImplementationType == typeof(ApiVersioningRouteOptionsSetup)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IApplicationModelProvider) && sd.ImplementationType == typeof(ApiVersioningApplicationModelProvider)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorProvider) && sd.ImplementationType == typeof(ApiVersionCollator)).Should().BeTrue();
        }
Beispiel #2
0
        public void add_api_versioning_should_configure_mvc_with_default_options()
        {
            // arrange
            var services = new ServiceCollection();

            // act
            services.AddApiVersioning();

            // assert
            services.Single(sd => sd.ServiceType == typeof(IApiVersionReader)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IApiVersionSelector)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IErrorResponseProvider)).ImplementationFactory.Should().NotBeNull();
            services.Single(sd => sd.ServiceType == typeof(IActionSelector)).ImplementationType.Should().Be(typeof(ApiVersionActionSelector));
            services.Single(sd => sd.ServiceType == typeof(IApiVersionRoutePolicy)).ImplementationType.Should().Be(typeof(DefaultApiVersionRoutePolicy));
            services.Single(sd => sd.ServiceType == typeof(ReportApiVersionsAttribute)).ImplementationType.Should().Be(typeof(ReportApiVersionsAttribute));
            services.Single(sd => sd.ServiceType == typeof(IReportApiVersions)).ImplementationFactory.Should().NotBeNull();
            services.Any(sd => sd.ServiceType == typeof(IPostConfigureOptions <MvcOptions>) && sd.ImplementationType == typeof(ApiVersioningMvcOptionsSetup)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IPostConfigureOptions <RouteOptions>) && sd.ImplementationType == typeof(ApiVersioningRouteOptionsSetup)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IApplicationModelProvider) && sd.ImplementationType == typeof(ApiVersioningApplicationModelProvider)).Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorProvider) && sd.ImplementationType == typeof(ApiVersionCollator)).Should().BeTrue();
        }
Beispiel #3
0
        public void enable_api_versioning_should_register_expected_services()
        {
            // arrange
            var services = new ServiceCollection();
            var mock     = new Mock <IODataBuilder>();

            mock.SetupGet(b => b.Services).Returns(services);

            var builder = mock.Object;

            // act
            builder.EnableApiVersioning();

            // assert
            services.Single(sd => sd.ServiceType == typeof(IActionSelector)).ImplementationType.Should().Be(typeof(ODataApiVersionActionSelector));
            services.Single(sd => sd.ServiceType == typeof(VersionedODataModelBuilder)).ImplementationType.Should().Be(typeof(VersionedODataModelBuilder));
            services.Single(sd => sd.ServiceType == typeof(IODataRouteCollectionProvider)).ImplementationType.Should().Be(typeof(ODataRouteCollectionProvider));
            services.Any(sd => sd.ServiceType == typeof(IApplicationModelProvider) && sd.ImplementationType.Name == "ODataApplicationModelProvider").Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorProvider) && sd.ImplementationType.Name == "ODataActionDescriptorProvider").Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorChangeProvider) && sd.ImplementationInstance.GetType().Name == "ODataActionDescriptorChangeProvider").Should().BeTrue();
        }
        public void enable_api_versioning_should_configure_custom_options()
        {
            // arrange
            var services          = new ServiceCollection();
            var customConventions = Mock.Of <ApiVersionConventionBuilder>();
            var mock = new Mock <IODataBuilder>();

            mock.SetupGet(b => b.Services).Returns(services);

            var builder = mock.Object;

            // act
            builder.EnableApiVersioning(options => options.Conventions = customConventions);

            // assert
            services.Single(sd => sd.ServiceType == typeof(IActionSelector)).ImplementationType.Should().Be(typeof(ODataApiVersionActionSelector));
            services.Single(sd => sd.ServiceType == typeof(VersionedODataModelBuilder)).ImplementationType.Should().Be(typeof(VersionedODataModelBuilder));
            services.Single(sd => sd.ServiceType == typeof(IODataRouteCollectionProvider)).ImplementationType.Should().Be(typeof(ODataRouteCollectionProvider));
            services.Any(sd => sd.ServiceType == typeof(IApplicationModelProvider) && sd.ImplementationType.Name == "ODataApplicationModelProvider").Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorProvider) && sd.ImplementationType.Name == "ODataActionDescriptorProvider").Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IActionDescriptorChangeProvider) && sd.ImplementationInstance.GetType().Name == "ODataActionDescriptorChangeProvider").Should().BeTrue();
            services.Any(sd => sd.ServiceType == typeof(IApiControllerSpecification) && sd.ImplementationType == typeof(ODataControllerSpecification)).Should().BeTrue();
        }