Summary

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

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
Map(...)8487.5100
GetRequestBody(...)42100100

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using System.Net;
 6using System.Text;
 7
 8namespace WireMock
 9{
 10    /// <summary>
 11    /// The http listener request mapper.
 12    /// </summary>
 13    public class HttpListenerRequestMapper
 14    {
 15        /// <summary>
 16        /// The map.
 17        /// </summary>
 18        /// <param name="listenerRequest">The listener request.</param>
 19        /// <returns>The <see cref="RequestMessage"/>.</returns>
 20        public RequestMessage Map(HttpListenerRequest listenerRequest)
 1821        {
 1822            Uri url = listenerRequest.Url;
 1823            string verb = listenerRequest.HttpMethod;
 1824            byte[] body = GetRequestBody(listenerRequest);
 1825             Encoding bodyEncoding = body != null ? listenerRequest.ContentEncoding : null;
 1826             string bodyAsString = bodyEncoding?.GetString(body);
 1827            var listenerHeaders = listenerRequest.Headers;
 10028            var headers = listenerHeaders.AllKeys.ToDictionary(k => k, k => listenerHeaders[k]);
 1829            var cookies = new Dictionary<string, string>();
 30
 5431            foreach (Cookie cookie in listenerRequest.Cookies)
 032                cookies.Add(cookie.Name, cookie.Value);
 33
 1834            return new RequestMessage(url, verb, body, bodyAsString, bodyEncoding, headers, cookies) { DateTime = DateTi
 1835        }
 36
 37        /// <summary>
 38        /// The get request body.
 39        /// </summary>
 40        /// <param name="request">The request.</param>
 41        /// <returns>The <see cref="string"/>.</returns>
 42        private byte[] GetRequestBody(HttpListenerRequest request)
 1843        {
 1844             if (!request.HasEntityBody)
 1645            {
 1646                return null;
 47            }
 48
 249            using (var bodyStream = request.InputStream)
 250            {
 251                using (var memoryStream = new MemoryStream())
 252                {
 253                    bodyStream.CopyTo(memoryStream);
 54
 255                    return memoryStream.ToArray();
 56                }
 57            }
 1858        }
 59    }
 60}