public void apply_should_throw_exception_for_ambiguous_api_versions_in_namespace(string @namespace) { // arrange var controllerType = new TestType(@namespace); var attributes = new Attribute[0]; var controllerModel = new TestHttpControllerDescriptor(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 = new Attribute[0]; var controllerModel = new TestHttpControllerDescriptor(controllerType.GetTypeInfo(), attributes); var convention = new VersionByNamespaceConvention(); // act var applied = convention.Apply(Mock.Of <IControllerConventionBuilder>(), controllerModel); // assert applied.Should().BeFalse(); }
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 Attribute[] { new ObsoleteAttribute("Deprecated") }; var controllerModel = new TestHttpControllerDescriptor(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()); }