예제 #1
0
        public void apply_should_throw_exception_for_ambiguous_api_versions_in_namespace(string @namespace)
        {
            // arrange
            var controllerType  = new TestType(@namespace);
            var attributes      = Array.Empty <object>();
            var controllerModel = new ControllerModel(controllerType.GetTypeInfo(), attributes);
            var convention      = new VersionByNamespaceConvention();

            // act
            Action apply = () => convention.Apply(Mock.Of <IControllerConventionBuilder>(), controllerModel);

            // assert
            apply.Should().Throw <InvalidOperationException>();
        }
        public void apply_should_ignore_unmatched_namespace()
        {
            // arrange
            var controllerType  = new TestType("Contoso.Api.Controllers");
            var attributes      = Array.Empty <object>();
            var controllerModel = new ControllerModel(controllerType.GetTypeInfo(), attributes);
            var convention      = new VersionByNamespaceConvention();

            // act
            var applied = convention.Apply(Mock.Of <IControllerConventionBuilder>(), controllerModel);

            // assert
            applied.Should().BeFalse();
        }
예제 #3
0
        public void apply_should_infer_deprecated_api_version_from_namespace(string @namespace, string versionText)
        {
            // arrange
            var apiVersion      = ApiVersion.Parse(versionText);
            var controllerType  = new TestType(@namespace);
            var attributes      = new object[] { new ObsoleteAttribute("Deprecated") };
            var controllerModel = new ControllerModel(controllerType.GetTypeInfo(), attributes);
            var controller      = new Mock <IControllerConventionBuilder>();
            var convention      = new VersionByNamespaceConvention();

            controller.Setup(c => c.HasDeprecatedApiVersion(It.IsAny <ApiVersion>()));

            // act
            var applied = convention.Apply(controller.Object, controllerModel);

            // assert
            applied.Should().BeTrue();
            controller.Verify(c => c.HasDeprecatedApiVersion(apiVersion), Once());
        }