Summary

Class:WireMock.Owin.OwinRequestMapper
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Owin\OwinRequestMapper.cs
Covered lines:23
Uncovered lines:1
Coverable lines:24
Total lines:70
Line coverage:95.8%
Branch coverage:50%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
MapAsync()13493.3360

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Owin\OwinRequestMapper.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Text;
 6using System.Threading.Tasks;
 7#if NET45
 8using Microsoft.Owin;
 9#else
 10using Microsoft.AspNetCore.Http;
 11using Microsoft.AspNetCore.Http.Extensions;
 12using Microsoft.AspNetCore.Http.Features;
 13#endif
 14
 15namespace WireMock.Owin
 16{
 17    /// <summary>
 18    /// OwinRequestMapper
 19    /// </summary>
 20    public class OwinRequestMapper
 21    {
 22        /// <summary>
 23        /// MapAsync IOwinRequest to RequestMessage
 24        /// </summary>
 25        /// <param name="request"></param>
 26        /// <returns></returns>
 27        public async Task<RequestMessage> MapAsync(
 28#if NET45
 29            IOwinRequest request
 30#else
 31            HttpRequest request
 32#endif
 33            )
 1334        {
 35#if NET45
 1336            Uri url = request.Uri;
 37#else
 38            Uri url = new Uri(request.GetEncodedUrl());
 39#endif
 1340            string verb = request.Method;
 41
 1342            string bodyAsString = null;
 1343            byte[] body = null;
 1344            Encoding bodyEncoding = null;
 1345             if (request.Body != null)
 1346            {
 1347                 using (var streamReader = new StreamReader(request.Body))
 1348                {
 1349                    bodyAsString = await streamReader.ReadToEndAsync();
 1350                    bodyEncoding = streamReader.CurrentEncoding;
 1351                }
 52
 1353                body = bodyEncoding.GetBytes(bodyAsString);
 1354            }
 55
 1356            var listenerHeaders = request.Headers;
 57
 1358            var headers = new Dictionary<string, string>();
 8759            foreach (var header in listenerHeaders)
 2460                headers.Add(header.Key, header.Value.FirstOrDefault());
 61
 1362            var cookies = new Dictionary<string, string>();
 63
 3964            foreach (var cookie in request.Cookies)
 065                cookies.Add(cookie.Key, cookie.Value);
 66
 1367            return new RequestMessage(url, verb, body, bodyAsString, bodyEncoding, headers, cookies) { DateTime = DateTi
 1368        }
 69    }
 70}

Methods/Properties

MapAsync()