public void is_deprecated_should_return_expected_result_for_deprecated_version(int majorVersion, bool expected)
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                new Mock <IApiVersionGroupNameFormatter>().Object,
                new OptionsWrapper <ApiVersioningOptions>(new ApiVersioningOptions()));
            var action     = new ActionDescriptor();
            var controller = new ControllerModel(typeof(Controller).GetTypeInfo(), new object[0]);
            var model      = new ApiVersionModel(
                declaredVersions: new[] { new ApiVersion(1, 0), new ApiVersion(2, 0) },
                supportedVersions: new[] { new ApiVersion(2, 0) },
                deprecatedVersions: new[] { new ApiVersion(1, 0) },
                advertisedVersions: Empty <ApiVersion>(),
                deprecatedAdvertisedVersions: Empty <ApiVersion>());

            controller.SetProperty(model);
            action.SetProperty(controller);

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(majorVersion, 0));

            // assert
            result.Should().Be(expected);
        }
Example #2
0
            LazyApiVersionDescriptions(DefaultApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
            {
                Contract.Requires(apiVersionDescriptionProvider != null);
                Contract.Requires(actionDescriptorCollectionProvider != null);

                this.apiVersionDescriptionProvider      = apiVersionDescriptionProvider;
                this.actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
            }
Example #3
0
            internal static Lazy <IReadOnlyList <ApiVersionDescription> > Create(DefaultApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
            {
                Contract.Requires(apiVersionDescriptionProvider != null);
                Contract.Requires(actionDescriptorCollectionProvider != null);
                Contract.Ensures(Contract.Result <Lazy <IReadOnlyList <ApiVersionDescription> > >() != null);

                var descriptions = new LazyApiVersionDescriptions(apiVersionDescriptionProvider, actionDescriptorCollectionProvider);

                return(new Lazy <IReadOnlyList <ApiVersionDescription> >(descriptions.EnumerateApiVersions));
            }
        public void is_deprecated_should_return_false_without_api_vesioning()
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                Options.Create(new ApiExplorerOptions()));
            var action = new ActionDescriptor();

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(1, 0));

            // assert
            result.Should().BeFalse();
        }
        public void is_deprecated_should_return_false_without_api_vesioning()
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                new Mock <IApiVersionGroupNameFormatter>().Object,
                new OptionsWrapper <ApiVersioningOptions>(new ApiVersioningOptions()));
            var action = new ActionDescriptor();

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(1, 0));

            // assert
            result.Should().BeFalse();
        }
        public void is_deprecated_should_return_false_when_controller_is_versionX2Dneutral()
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                Options.Create(new ApiExplorerOptions()));
            var action = new ActionDescriptor();

            action.SetProperty(ApiVersionModel.Neutral);

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(1, 0));

            // assert
            result.Should().BeFalse();
        }
        public void is_deprecated_should_return_false_when_controller_is_versionX2Dneutral()
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                new Mock <IApiVersionGroupNameFormatter>().Object);
            var action     = new ActionDescriptor();
            var controller = new ControllerModel(typeof(Controller).GetTypeInfo(), new object[0]);

            controller.SetProperty(ApiVersionModel.Neutral);
            action.SetProperty(controller);

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(1, 0));

            // assert
            result.Should().BeFalse();
        }
        public void api_version_descriptions_should_collate_expected_versions()
        {
            // arrange
            var actionProvider      = new TestActionDescriptorCollectionProvider();
            var groupNameFormatter  = new DefaultApiVersionGroupNameFormatter();
            var descriptionProvider = new DefaultApiVersionDescriptionProvider(actionProvider, groupNameFormatter);

            // act
            var descriptions = descriptionProvider.ApiVersionDescriptions;

            // assert
            descriptions.ShouldBeEquivalentTo(
                new[]
            {
                new ApiVersionDescription(new ApiVersion(0, 9), "v0.9", true),
                new ApiVersionDescription(new ApiVersion(1, 0), "v1", false),
                new ApiVersionDescription(new ApiVersion(2, 0), "v2", false),
                new ApiVersionDescription(new ApiVersion(3, 0), "v3", false)
            });
        }
        public void is_deprecated_should_return_expected_result_for_deprecated_version(int majorVersion, bool expected)
        {
            // arrange
            var provider = new DefaultApiVersionDescriptionProvider(
                new Mock <IActionDescriptorCollectionProvider>().Object,
                Options.Create(new ApiExplorerOptions()));
            var action = new ActionDescriptor();
            var model  = new ApiVersionModel(
                declaredVersions: new[] { new ApiVersion(1, 0), new ApiVersion(2, 0) },
                supportedVersions: new[] { new ApiVersion(2, 0) },
                deprecatedVersions: new[] { new ApiVersion(1, 0) },
                advertisedVersions: Empty <ApiVersion>(),
                deprecatedAdvertisedVersions: Empty <ApiVersion>());

            action.SetProperty(model);

            // act
            var result = provider.IsDeprecated(action, new ApiVersion(majorVersion, 0));

            // assert
            result.Should().Be(expected);
        }
            internal static Lazy <IReadOnlyList <ApiVersionDescription> > Create(DefaultApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
            {
                var descriptions = new LazyApiVersionDescriptions(apiVersionDescriptionProvider, actionDescriptorCollectionProvider);

                return(new Lazy <IReadOnlyList <ApiVersionDescription> >(descriptions.EnumerateApiVersions));
            }
 LazyApiVersionDescriptions(DefaultApiVersionDescriptionProvider apiVersionDescriptionProvider, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
 {
     this.apiVersionDescriptionProvider      = apiVersionDescriptionProvider;
     this.actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
 }