# Summary

Class: | WireMock.Owin.OwinResponseMapper
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Owin\OwinResponseMapper.cs
Covered lines: | 42
Uncovered lines: | 5
Coverable lines: | 47
Total lines: | 114
Line coverage: | 89.3%
Branch coverage: | 82.1%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
SetResponseHeaders(...) | 0 | 0 | 1 | 0.833
.ctor() | 0 | 0 | 1 | 0
.cctor() | 0 | 0 | 1 | 0
MapAsync() | 0 | 0 | 0.833 | 0.818

# File(s)

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Collections.Generic;`
|  | `3` |  | `using System.IO;`
|  | `4` |  | `using System.Linq;`
|  | `5` |  | `using System.Net;`
|  | `6` |  | `using System.Text;`
|  | `7` |  | `using System.Threading.Tasks;`
|  | `8` |  | `using Newtonsoft.Json;`
|  | `9` |  | `using WireMock.Http;`
|  | `10` |  | `using WireMock.Util;`
|  | `11` |  | `#if !USE_ASPNETCORE`
|  | `12` |  | `using Microsoft.Owin;`
|  | `13` |  | `#else`
|  | `14` |  | `using Microsoft.AspNetCore.Http;`
|  | `15` |  | `#endif`
|  | `16` |  | ``
|  | `17` |  | `namespace WireMock.Owin`
|  | `18` |  | `{`
|  | `19` |  | `/// <summary>`
|  | `20` |  | `/// OwinResponseMapper`
|  | `21` |  | `/// </summary>`
|  | `22` |  | `public class OwinResponseMapper`
|  | `23` |  | `{`
| 110 | `24` |  | `private readonly Encoding _utf8NoBom = new UTF8Encoding(false);`
|  | `25` |  | ``
|  | `26` |  | `// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx`
|  | `27` |  | `#if !USE_ASPNETCORE`
|  | `28` |  | `private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> ResponseHeadersToFix =`
|  | `29` |  | `#else`
| 1 | `30` |  | `private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> ResponseHeadersToFix = n`
| 1 | `31` |  | `#endif`
| 23 | `32` |  | `{ HttpKnownHeaderNames.ContentType, (r, v) => r.ContentType = v.FirstOrDefault() }`
| 1 | `33` |  | `};`
|  | `34` |  | ``
|  | `35` |  | `private void SetResponseHeaders(ResponseMessage responseMessage`
|  | `36` |  | `#if !USE_ASPNETCORE`
|  | `37` |  | `, IOwinResponse response`
|  | `38` |  | `#else`
|  | `39` |  | `, HttpResponse response`
|  | `40` |  | `#endif`
|  | `41` |  | `)`
| 65 | `42` |  | `{`
|  | `43` |  | `// Set headers`
| 247 | `44` |  | `foreach (var pair in responseMessage.Headers)`
| 26 | `45` |  | `{`
| 26 | `46` |  | `if (ResponseHeadersToFix.ContainsKey(pair.Key))`
| 22 | `47` |  | `{`
| 22 | `48` |  | `ResponseHeadersToFix[pair.Key]?.Invoke(response, pair.Value);`
| 22 | `49` |  | `}`
|  | `50` |  | `else`
| 4 | `51` |  | `{`
|  | `52` |  | `#if !USE_ASPNETCORE`
|  | `53` |  | `// For non-NETSTANDARD, check if this response header can be added (#148)`
|  | `54` |  | `if (!WebHeaderCollection.IsRestricted(pair.Key, true))`
|  | `55` |  | `{`
|  | `56` |  | `response.Headers.AppendValues(pair.Key, pair.Value.ToArray());`
|  | `57` |  | `}`
|  | `58` |  | `#else`
|  | `59` |  | `// NETSTANDARD can add any header (or so it seems)`
| 4 | `60` |  | `response.Headers.Append(pair.Key, pair.Value.ToArray());`
|  | `61` |  | `#endif`
| 4 | `62` |  | `}`
| 26 | `63` |  | `}`
| 65 | `64` |  | `}`
|  | `65` |  | ``
|  | `66` |  | `/// <summary>`
|  | `67` |  | `/// Map ResponseMessage to OwinResponse/HttpResponse`
|  | `68` |  | `/// </summary>`
|  | `69` |  | `/// <param name="responseMessage"></param>`
|  | `70` |  | `/// <param name="response"></param>`
|  | `71` |  | `public async Task MapAsync(ResponseMessage responseMessage`
|  | `72` |  | `#if !USE_ASPNETCORE`
|  | `73` |  | `, IOwinResponse response`
|  | `74` |  | `#else`
|  | `75` |  | `, HttpResponse response`
|  | `76` |  | `#endif`
|  | `77` |  | `)`
| 65 | `78` |  | `{`
| 65 | `79` |  | `if (responseMessage == null)`
| 0 | `80` |  | `{`
| 0 | `81` |  | `return;`
|  | `82` |  | `}`
|  | `83` |  | ``
| 65 | `84` |  | `response.StatusCode = responseMessage.StatusCode;`
|  | `85` |  | ``
| 65 | `86` |  | `byte[] bytes = null;`
| 65 | `87` |  | `if (responseMessage.BodyAsBytes != null)`
| 2 | `88` |  | `{`
| 2 | `89` |  | `bytes = responseMessage.BodyAsBytes;`
| 2 | `90` |  | `}`
| 63 | `91` |  | `else if (responseMessage.BodyAsFile != null)`
| 0 | `92` |  | `{`
| 0 | `93` |  | `bytes = File.ReadAllBytes(responseMessage.BodyAsFile);`
| 0 | `94` |  | `}`
| 63 | `95` |  | `else if (responseMessage.BodyAsJson != null)`
| 19 | `96` |  | `{`
| 19 | `97` |  | `Formatting formatting = responseMessage.BodyAsJsonIndented == true ? Formatting.Indented : Formatting.No`
| 19 | `98` |  | `string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { F`
| 19 | `99` |  | `bytes = (responseMessage.BodyEncoding ?? _utf8NoBom).GetBytes(jsonBody);`
| 19 | `100` |  | `}`
| 44 | `101` |  | `else if (responseMessage.Body != null)`
| 30 | `102` |  | `{`
| 30 | `103` |  | `bytes = (responseMessage.BodyEncoding ?? _utf8NoBom).GetBytes(responseMessage.Body);`
| 30 | `104` |  | `}`
|  | `105` |  | ``
| 65 | `106` |  | `SetResponseHeaders(responseMessage, response);`
|  | `107` |  | ``
| 65 | `108` |  | `if (bytes != null)`
| 51 | `109` |  | `{`
| 51 | `110` |  | `await response.Body.WriteAsync(bytes, 0, bytes.Length);`
| 51 | `111` |  | `}`
| 65 | `112` |  | `}`
|  | `113` |  | `}`
|  | `114` |  | `}`

# Methods/Properties

.ctor()
.cctor()
SetResponseHeaders(WireMock.ResponseMessage,Microsoft.AspNetCore.Http.HttpResponse)
MapAsync()