public void Create_ReturnsExceptionHandlerOptions() { var options = ExceptionHandlerOptionsFactory.Create(); // Asserts options.ExceptionHandler.Should().NotBeNull().And.BeAssignableTo <RequestDelegate>(); }
public void ExceptionHandler_ShouldInvokeDelegatedHandle(DefaultHttpContext http) { var options = ExceptionHandlerOptionsFactory.Create(); var action = options.ExceptionHandler; action.Invoke(http); // Asserts http.Response.StatusCode.Should().Be(StatusCodes.Status422UnprocessableEntity); http.Response.ContentType.Should().Be(MediaTypeNames.Application.Json); }
public static IApplicationBuilder UseMyExceptionHandler(this IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } if (env.IsStaging() || env.IsProduction()) { app.UseExceptionHandler(ExceptionHandlerOptionsFactory.Create()); } return(app); }
public static IApplicationBuilder UseMyExceptionHandler(this IApplicationBuilder app, IWebHostEnvironment env) { app.UseExceptionHandler(ExceptionHandlerOptionsFactory.Create()); return(app); }