public void controller_should_not_allow_both_compileX2Dtime_and_runX2Dtime_conventions() { // arrange var conventionBuilder = new ApiVersionConventionBuilder(); conventionBuilder.Controller <StubController>(); // act Action controllerConvention = () => conventionBuilder.Controller(typeof(StubController)); // assert controllerConvention.Should().Throw <InvalidOperationException>(); }
public void apply_should_apply_configured_conventions() { // arrange var controllerModel = new ControllerModel(typeof(v2.UndecoratedController).GetTypeInfo(), new object[0]); var conventionBuilder = new ApiVersionConventionBuilder(); conventionBuilder.Add(new VersionByNamespaceConvention()); // act conventionBuilder.ApplyTo(controllerModel); // assert controllerModel.GetProperty <ApiVersionModel>().DeclaredApiVersions.Single().Should().Be(new ApiVersion(2, 0)); }
public void apply_should_apply_configured_conventions() { // arrange var controllerType = typeof(v2.UndecoratedController).GetTypeInfo(); var action = controllerType.GetRuntimeMethod(nameof(v2.UndecoratedController.Get), Type.EmptyTypes); var attributes = Array.Empty <object>(); var actionModel = new ActionModel(action, attributes); var controllerModel = new ControllerModel(controllerType, attributes) { Actions = { actionModel } }; var conventionBuilder = new ApiVersionConventionBuilder(); var actionDescriptor = new ActionDescriptor(); conventionBuilder.Add(new VersionByNamespaceConvention()); // act conventionBuilder.ApplyTo(controllerModel); actionDescriptor.SetProperty(controllerModel); actionDescriptor.SetProperty(actionModel.GetProperty <ApiVersionModel>()); // assert actionDescriptor.MappingTo(new ApiVersion(2, 0)).Should().Be(Implicit); }