public ApiBehaviorApplicationModelProvider( IOptions <ApiBehaviorOptions> apiBehaviorOptions, IModelMetadataProvider modelMetadataProvider, IClientErrorFactory clientErrorFactory, ILoggerFactory loggerFactory) { _apiBehaviorOptions = apiBehaviorOptions.Value; _modelMetadataProvider = modelMetadataProvider; _logger = loggerFactory.CreateLogger <ApiBehaviorApplicationModelProvider>(); if (!_apiBehaviorOptions.SuppressModelStateInvalidFilter && _apiBehaviorOptions.InvalidModelStateResponseFactory == null) { throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull( typeof(ApiBehaviorOptions), nameof(ApiBehaviorOptions.InvalidModelStateResponseFactory))); } _modelStateInvalidFilter = new ModelStateInvalidFilter( apiBehaviorOptions.Value, loggerFactory.CreateLogger <ModelStateInvalidFilter>()); _clientErrorResultFilter = new ClientErrorResultFilter( clientErrorFactory, loggerFactory.CreateLogger <ClientErrorResultFilter>()); }
public void OnResultExecuting_DoesNothing_IfTransformedValueIsNull() { // Arrange var actionResult = new NotFoundResult(); var context = GetContext(actionResult); var factory = new Mock <IClientErrorFactory>(); factory .Setup(f => f.GetClientError(It.IsAny <ActionContext>(), It.IsAny <IClientErrorActionResult>())) .Returns((IActionResult)null) .Verifiable(); var filter = new ClientErrorResultFilter(factory.Object, NullLogger <ClientErrorResultFilter> .Instance); // Act filter.OnResultExecuting(context); // Assert Assert.Same(actionResult, context.Result); factory.Verify(); }