コード例 #1
0
        public void Create_ReturnsExceptionHandlerOptions()
        {
            var options = ExceptionHandlerOptionsFactory.Create();

            // Asserts
            options.ExceptionHandler.Should().NotBeNull().And.BeAssignableTo <RequestDelegate>();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public static IApplicationBuilder UseMyExceptionHandler(this IApplicationBuilder app, IWebHostEnvironment env)
 {
     app.UseExceptionHandler(ExceptionHandlerOptionsFactory.Create());
     return(app);
 }