public void apply_to_should_assign_model_to_controller_from_conventions_and_attributes()
        {
            // arrange
            var attributes        = typeof(DecoratedController).GetTypeInfo().GetCustomAttributes().Cast <object>().ToArray();
            var controllerModel   = new ControllerModel(typeof(DecoratedController).GetTypeInfo(), attributes);
            var controllerBuilder = new ControllerApiVersionConventionBuilder(typeof(DecoratedController));

            controllerBuilder.HasApiVersion(1, 0)
            .AdvertisesApiVersion(4, 0);

            // act
            controllerBuilder.ApplyTo(controllerModel);

            // assert
            controllerModel.GetProperty <ApiVersionModel>().ShouldBeEquivalentTo(
                new
            {
                IsApiVersionNeutral    = false,
                DeclaredApiVersions    = new[] { new ApiVersion(0, 9), new ApiVersion(1, 0), new ApiVersion(2, 0) },
                SupportedApiVersions   = new[] { new ApiVersion(1, 0), new ApiVersion(2, 0), new ApiVersion(3, 0), new ApiVersion(4, 0) },
                DeprecatedApiVersions  = new[] { new ApiVersion(0, 9), new ApiVersion(3, 0, "Beta") },
                ImplementedApiVersions = new[] { new ApiVersion(0, 9), new ApiVersion(1, 0), new ApiVersion(2, 0), new ApiVersion(3, 0), new ApiVersion(3, 0, "Beta"), new ApiVersion(4, 0) }
            });
        }
Esempio n. 2
0
        public void on_providers_executed_should_apply_api_versionX2Dneutral_model_conventions()
        {
            // arrange
            var model        = ApiVersionModel.Neutral;
            var type         = typeof(object);
            var attributes   = new object[] { new ApiVersionNeutralAttribute() };
            var actionMethod = type.GetRuntimeMethod(nameof(object.ToString), EmptyTypes);
            var controller   = new ControllerModel(type.GetTypeInfo(), attributes)
            {
                Actions = { new ActionModel(actionMethod, new object[0]) }
            };
            var options  = Options.Create(new ApiVersioningOptions());
            var context  = new ApplicationModelProviderContext(new[] { controller.ControllerType });
            var provider = new ApiVersioningApplicationModelProvider(options);

            context.Result.Controllers.Add(controller);

            // act
            provider.OnProvidersExecuted(context);

            // assert
            controller.GetProperty <ApiVersionModel>().Should().BeSameAs(model);
            controller.Actions.Single().GetProperty <ApiVersionModel>().Should().BeSameAs(model);
        }