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:10
Uncovered lines:4
Coverable lines:14
Total lines:56
Line coverage:71.4%
Branch coverage:66.6%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
Invoke()9855.5671.43

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 !NETSTANDARD
 5using Microsoft.Owin;
 6#else
 7using Microsoft.AspNetCore.Http;
 8#endif
 9
 10namespace WireMock.Owin
 11{
 12#if !NETSTANDARD
 13    internal class GlobalExceptionMiddleware : OwinMiddleware
 14#else
 15    internal class GlobalExceptionMiddleware
 16#endif
 17    {
 18        private readonly WireMockMiddlewareOptions _options;
 19
 20#if !NETSTANDARD
 4721        public GlobalExceptionMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
 4722        {
 4723            _options = options;
 4724        }
 25#else
 26        public GlobalExceptionMiddleware(RequestDelegate next, WireMockMiddlewareOptions options)
 27        {
 28            Next = next;
 29            _options = options;
 30        }
 31#endif
 32
 33#if NETSTANDARD
 34        public RequestDelegate Next { get; }
 35#endif
 36
 4737        private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
 38
 39#if !NETSTANDARD
 40        public override async Task Invoke(IOwinContext ctx)
 41#else
 42        public async Task Invoke(HttpContext ctx)
 43#endif
 5844         {
 45            try
 5846            {
 5847                 await Next?.Invoke(ctx);
 5848            }
 049             catch (Exception ex)
 050            {
 051                _options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
 052                await _responseMapper.MapAsync(new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObjec
 53            }
 5854        }
 55    }
 56}