public void OnProvidersExecuting_SkipsAddingFilterToActionIfFeatureIsDisabledUsingOptions() { // Arrange var context = GetContext(typeof(SimpleController)); var options = new TestOptionsManager <ApiBehaviorOptions>(new ApiBehaviorOptions { EnableModelStateInvalidFilter = false, }); var provider = new ApiControllerApplicationModelProvider(options, NullLoggerFactory.Instance); // Act provider.OnProvidersExecuting(context); // Assert Assert.Collection( Assert.Single(context.Result.Controllers).Actions.OrderBy(a => a.ActionName), action => { Assert.DoesNotContain(typeof(ModelStateInvalidFilter), action.Filters.Select(f => f.GetType())); }, action => { Assert.DoesNotContain(typeof(ModelStateInvalidFilter), action.Filters.Select(f => f.GetType())); }); }
public void OnProvidersExecuting_AddsModelStateInvalidFilter_IfActionIsAnnotatedWithAttribute() { // Arrange var context = GetContext(typeof(SimpleController)); var options = new TestOptionsManager <ApiBehaviorOptions>(new ApiBehaviorOptions { InvalidModelStateResponseFactory = _ => null, }); var provider = new ApiControllerApplicationModelProvider(options, NullLoggerFactory.Instance); // Act provider.OnProvidersExecuting(context); // Assert Assert.Collection( Assert.Single(context.Result.Controllers).Actions.OrderBy(a => a.ActionName), action => { Assert.Contains(typeof(ModelStateInvalidFilter), action.Filters.Select(f => f.GetType())); }, action => { Assert.DoesNotContain(typeof(ModelStateInvalidFilter), action.Filters.Select(f => f.GetType())); }); }
public void OnProvidersExecuting_DoesNotAddModelStateInvalidFilterToController_IfFeatureIsDisabledViaOptions() { // Arrange var context = GetContext(typeof(TestApiController)); var options = new TestOptionsManager <ApiBehaviorOptions>(new ApiBehaviorOptions { EnableModelStateInvalidFilter = false, }); var provider = new ApiControllerApplicationModelProvider(options, NullLoggerFactory.Instance); // Act provider.OnProvidersExecuting(context); // Assert var controllerModel = Assert.Single(context.Result.Controllers); Assert.DoesNotContain(typeof(ModelStateInvalidFilter), controllerModel.Filters.Select(f => f.GetType())); }
public void OnProvidersExecuting_AddsModelStateInvalidFilter_IfTypeIsAnnotatedWithAttribute() { // Arrange var context = GetContext(typeof(TestApiController)); var options = new TestOptionsManager <ApiBehaviorOptions>(new ApiBehaviorOptions { InvalidModelStateResponseFactory = _ => null, }); var provider = new ApiControllerApplicationModelProvider(options, NullLoggerFactory.Instance); // Act provider.OnProvidersExecuting(context); // Assert var controllerModel = Assert.Single(context.Result.Controllers); Assert.IsType <ModelStateInvalidFilter>(controllerModel.Filters.Last()); }