Summary

Class:WireMock.Owin.GlobalExceptionMiddleware
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Owin\GlobalExceptionMiddleware.cs
Covered lines:12
Uncovered lines:5
Coverable lines:17
Total lines:56
Line coverage:70.5%
Branch coverage:58.3%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor(...)0010
Invoke()000.50.583

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Owin\GlobalExceptionMiddleware.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using Newtonsoft.Json;
 4#if !USE_ASPNETCORE
 5using Microsoft.Owin;
 6#else
 7using Microsoft.AspNetCore.Http;
 8#endif
 9
 10namespace WireMock.Owin
 11{
 12#if !USE_ASPNETCORE
 13    internal class GlobalExceptionMiddleware : OwinMiddleware
 14#else
 15    internal class GlobalExceptionMiddleware
 16#endif
 17    {
 18        private readonly WireMockMiddlewareOptions _options;
 19
 20#if !USE_ASPNETCORE
 21        public GlobalExceptionMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
 22        {
 23            _options = options;
 24        }
 25#else
 4926        public GlobalExceptionMiddleware(RequestDelegate next, WireMockMiddlewareOptions options)
 4927        {
 4928            Next = next;
 4929            _options = options;
 4930        }
 31#endif
 32
 33#if USE_ASPNETCORE
 6534        public RequestDelegate Next { get; }
 35#endif
 36
 4937        private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
 38
 39#if !USE_ASPNETCORE
 40        public override async Task Invoke(IOwinContext ctx)
 41#else
 42        public async Task Invoke(HttpContext ctx)
 43#endif
 6544        {
 45            try
 6546            {
 6547                await Next?.Invoke(ctx);
 6548            }
 049            catch (Exception ex)
 050            {
 051                _options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
 052                await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.
 053            }
 6554        }
 55    }
 56}