public void apply_to_should_assign_empty_conventions_to_api_version_neutral_controller()
        {
            // arrange
            var controllerModel   = new ControllerModel(typeof(UndecoratedController).GetTypeInfo(), new object[0]);
            var controllerBuilder = new ControllerApiVersionConventionBuilder(typeof(UndecoratedController));

            controllerBuilder.HasDeprecatedApiVersion(0, 9)
            .HasApiVersion(2, 0)
            .AdvertisesApiVersion(3, 0)
            .AdvertisesDeprecatedApiVersion(3, 0, "Beta")
            .IsApiVersionNeutral();

            // act
            controllerBuilder.ApplyTo(controllerModel);

            // assert
            controllerModel.GetProperty <ApiVersionModel>().Should().BeEquivalentTo(
                new
            {
                IsApiVersionNeutral    = true,
                DeclaredApiVersions    = new ApiVersion[0],
                SupportedApiVersions   = new ApiVersion[0],
                DeprecatedApiVersions  = new ApiVersion[0],
                ImplementedApiVersions = new ApiVersion[0]
            });
        }
Ejemplo n.º 2
0
        public void apply_to_should_assign_empty_conventions_to_api_version_neutral_controller()
        {
            // arrange
            var controllerType  = typeof(UndecoratedController);
            var action          = controllerType.GetRuntimeMethod(nameof(UndecoratedController.Get), Type.EmptyTypes);
            var attributes      = Array.Empty <object>();
            var actionModel     = new ActionModel(action, attributes);
            var controllerModel = new ControllerModel(controllerType.GetTypeInfo(), attributes)
            {
                Actions = { actionModel }
            };
            var controllerBuilder = new ControllerApiVersionConventionBuilder(controllerType);

            controllerBuilder.HasDeprecatedApiVersion(0, 9)
            .HasApiVersion(2, 0)
            .AdvertisesApiVersion(3, 0)
            .AdvertisesDeprecatedApiVersion(3, 0, "Beta")
            .IsApiVersionNeutral();

            // act
            controllerBuilder.ApplyTo(controllerModel);

            // assert
            actionModel.GetProperty <ApiVersionModel>().Should().BeEquivalentTo(
                new
            {
                IsApiVersionNeutral    = true,
                DeclaredApiVersions    = Array.Empty <ApiVersion>(),
                SupportedApiVersions   = Array.Empty <ApiVersion>(),
                DeprecatedApiVersions  = Array.Empty <ApiVersion>(),
                ImplementedApiVersions = Array.Empty <ApiVersion>()
            });
        }