Summary

Class:WireMock.Owin.GlobalExceptionMiddleware
Assembly:WireMock.Net
File(s):C:\Users\StefHeyenrath\Documents\GitHub\WireMock.Net\src\WireMock.Net\Owin\GlobalExceptionMiddleware.cs
Covered lines:17
Uncovered lines:5
Coverable lines:22
Total lines:71
Line coverage:77.2%
Branch coverage:58.3%

Metrics

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

File(s)

C:\Users\StefHeyenrath\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;
 6using IContext = Microsoft.Owin.IOwinContext;
 7using OwinMiddleware = Microsoft.Owin.OwinMiddleware;
 8using Next = Microsoft.Owin.OwinMiddleware;
 9#else
 10using OwinMiddleware = System.Object;
 11using IContext = Microsoft.AspNetCore.Http.HttpContext;
 12using Next = Microsoft.AspNetCore.Http.RequestDelegate;
 13#endif
 14using WireMock.Owin.Mappers;
 15using WireMock.Validation;
 16
 17namespace WireMock.Owin
 18{
 19    internal class GlobalExceptionMiddleware : OwinMiddleware
 20    {
 21        private readonly IWireMockMiddlewareOptions _options;
 22        private readonly IOwinResponseMapper _responseMapper;
 23
 24#if !USE_ASPNETCORE
 25        public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapp
 26        {
 27            Check.NotNull(options, nameof(options));
 28            Check.NotNull(responseMapper, nameof(responseMapper));
 29
 30            _options = options;
 31            _responseMapper = responseMapper;
 32        }
 33#else
 4834        public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapp
 4835        {
 4836            Check.NotNull(options, nameof(options));
 4837            Check.NotNull(responseMapper, nameof(responseMapper));
 38
 4839            Next = next;
 4840            _options = options;
 4841            _responseMapper = responseMapper;
 4842        }
 43#endif
 44
 45#if USE_ASPNETCORE
 4646        public Next Next { get; }
 47#endif
 48
 49#if !USE_ASPNETCORE
 50        public override Task Invoke(IContext ctx)
 51#else
 52        public Task Invoke(IContext ctx)
 53#endif
 4654        {
 4655            return InvokeInternal(ctx);
 4556        }
 57
 58        private async Task InvokeInternal(IContext ctx)
 4659        {
 60            try
 4661            {
 4662                await Next?.Invoke(ctx);
 4663            }
 064            catch (Exception ex)
 065            {
 066                _options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
 067                await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.
 068            }
 4669        }
 70    }
 71}