# Summary

Class: | WireMock.Util.BodyParser
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Util\BodyParser.cs
Covered lines: | 39
Uncovered lines: | 17
Coverable lines: | 56
Total lines: | 88
Line coverage: | 69.6%
Branch coverage: | 39.2%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
.cctor() | 0 | 0 | 1 | 0
ReadStringAsync() | 0 | 0 | 1 | 0.5
ReadBytesAsync() | 0 | 0 | 0 | 0
Parse() | 0 | 0 | 0.633 | 0.45

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Util\BodyParser.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.IO;`
|  | `3` |  | `using System.Linq;`
|  | `4` |  | `using System.Text;`
|  | `5` |  | `using System.Threading.Tasks;`
|  | `6` |  | `using JetBrains.Annotations;`
|  | `7` |  | `using Newtonsoft.Json;`
|  | `8` |  | ``
|  | `9` |  | `namespace WireMock.Util`
|  | `10` |  | `{`
|  | `11` |  | `internal static class BodyParser`
|  | `12` |  | `{`
| 1 | `13` |  | `private static readonly string[] JsonContentTypes =`
| 1 | `14` |  | `{`
| 1 | `15` |  | `"application/json",`
| 1 | `16` |  | `"application/vnd.api+json"`
| 1 | `17` |  | `};`
|  | `18` |  | ``
| 1 | `19` |  | `private static readonly string[] TextContentTypes =`
| 1 | `20` |  | `{`
| 1 | `21` |  | `"text/",`
| 1 | `22` |  | `"application/javascript", "application/typescript",`
| 1 | `23` |  | `"application/xml", "application/xhtml+xml",`
| 1 | `24` |  | `"application/x-www-form-urlencoded"`
| 1 | `25` |  | `};`
|  | `26` |  | ``
|  | `27` |  | `private static async Task<Tuple<string, Encoding>> ReadStringAsync(Stream stream)`
| 19 | `28` |  | `{`
| 19 | `29` |  | `using (var streamReader = new StreamReader(stream))`
| 19 | `30` |  | `{`
| 19 | `31` |  | `string content = await streamReader.ReadToEndAsync();`
|  | `32` |  | ``
| 19 | `33` |  | `return new Tuple<string, Encoding>(content, streamReader.CurrentEncoding);`
|  | `34` |  | `}`
| 19 | `35` |  | `}`
|  | `36` |  | ``
|  | `37` |  | `private static async Task<byte[]> ReadBytesAsync(Stream stream)`
| 0 | `38` |  | `{`
| 0 | `39` |  | `using (var memoryStream = new MemoryStream())`
| 0 | `40` |  | `{`
| 0 | `41` |  | `await stream.CopyToAsync(memoryStream);`
| 0 | `42` |  | `return memoryStream.ToArray();`
|  | `43` |  | `}`
| 0 | `44` |  | `}`
|  | `45` |  | ``
|  | `46` |  | `public static async Task<BodyData> Parse([NotNull] Stream stream, [CanBeNull] string contentTypeHeaderValue)`
| 19 | `47` |  | `{`
| 19 | `48` |  | `var data = new BodyData();`
|  | `49` |  | ``
| 101 | `50` |  | `if (contentTypeHeaderValue != null && TextContentTypes.Any(text => contentTypeHeaderValue.StartsWith(text, S`
| 7 | `51` |  | `{`
|  | `52` |  | `try`
| 7 | `53` |  | `{`
| 7 | `54` |  | `var stringData = await ReadStringAsync(stream);`
| 7 | `55` |  | `data.BodyAsString = stringData.Item1;`
| 7 | `56` |  | `data.Encoding = stringData.Item2;`
| 7 | `57` |  | `}`
| 0 | `58` |  | `catch`
| 0 | `59` |  | `{`
|  | `60` |  | `// Reading as string failed, just get the ByteArray.`
| 0 | `61` |  | `data.BodyAsBytes = await ReadBytesAsync(stream);`
| 0 | `62` |  | `}`
| 7 | `63` |  | `}`
| 26 | `64` |  | `else if (contentTypeHeaderValue != null && JsonContentTypes.Any(json => contentTypeHeaderValue.StartsWith(js`
| 12 | `65` |  | `{`
| 12 | `66` |  | `var stringData = await ReadStringAsync(stream);`
| 12 | `67` |  | `data.BodyAsString = stringData.Item1;`
| 12 | `68` |  | `data.Encoding = stringData.Item2;`
|  | `69` |  | ``
|  | `70` |  | `try`
| 12 | `71` |  | `{`
| 12 | `72` |  | `data.BodyAsJson = JsonConvert.DeserializeObject(stringData.Item1, new JsonSerializerSettings { Forma`
| 12 | `73` |  | `}`
| 0 | `74` |  | `catch`
| 0 | `75` |  | `{`
|  | `76` |  | `// JsonConvert failed, just set the Body as string.`
| 0 | `77` |  | `data.BodyAsString = stringData.Item1;`
| 0 | `78` |  | `}`
| 12 | `79` |  | `}`
|  | `80` |  | `else`
| 0 | `81` |  | `{`
| 0 | `82` |  | `data.BodyAsBytes = await ReadBytesAsync(stream);`
| 0 | `83` |  | `}`
|  | `84` |  | ``
| 19 | `85` |  | `return data;`
| 19 | `86` |  | `}`
|  | `87` |  | `}`
|  | `88` |  | `}`

# Methods/Properties

.cctor()
ReadStringAsync()
ReadBytesAsync()
Parse()