# WireMock.Transformers.ResponseMessageTransformer - Coverage Report

# Summary

Class: | WireMock.Transformers.ResponseMessageTransformer
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Transformers\ResponseMessageTransformer.cs
Covered lines: | 33
Uncovered lines: | 0
Coverable lines: | 33
Total lines: | 57
Line coverage: | 100%
Branch coverage: | 87.5%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
Transform(...) | 8 | 16 | 100 | 88.89

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Transformers\ResponseMessageTransformer.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System.Collections.Generic;`
|  | `2` |  | `using System.Linq;`
|  | `3` |  | `using HandlebarsDotNet;`
|  | `4` |  | `using Newtonsoft.Json;`
|  | `5` |  | `using WireMock.Util;`
|  | `6` |  | ``
|  | `7` |  | `namespace WireMock.Transformers`
|  | `8` |  | `{`
|  | `9` |  | `internal static class ResponseMessageTransformer`
|  | `10` |  | `{`
|  | `11` |  | `public static ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original)`
| 6 | `12` |  | `{`
| 6 | `13` |  | `bool bodyIsJson = original.BodyAsJson != null;`
| 6 | `14` |  | `var responseMessage = new ResponseMessage { StatusCode = original.StatusCode };`
|  | `15` |  | ``
| 6 | `16` |  | `if (!bodyIsJson)`
| 5 | `17` |  | `{`
| 5 | `18` |  | `responseMessage.BodyOriginal = original.Body;`
| 5 | `19` |  | `}`
|  | `20` |  | ``
| 6 | `21` |  | `var template = new { request = requestMessage };`
|  | `22` |  | ``
|  | `23` |  | `// Body`
| 6 | `24` |  | `string body = bodyIsJson ? JsonConvert.SerializeObject(original.BodyAsJson) : original.Body;`
| 6 | `25` |  | `if (body != null)`
| 6 | `26` |  | `{`
| 6 | `27` |  | `var templateBody = Handlebars.Compile(body);`
|  | `28` |  | ``
| 6 | `29` |  | `if (!bodyIsJson)`
| 5 | `30` |  | `{`
| 5 | `31` |  | `responseMessage.Body = templateBody(template);`
| 5 | `32` |  | `}`
|  | `33` |  | `else`
| 1 | `34` |  | `{`
| 1 | `35` |  | `responseMessage.BodyAsJson = JsonConvert.DeserializeObject(templateBody(template));`
| 1 | `36` |  | `}`
| 6 | `37` |  | `}`
|  | `38` |  | ``
|  | `39` |  | `// Headers`
| 6 | `40` |  | `var newHeaders = new Dictionary<string, WireMockList<string>>();`
| 22 | `41` |  | `foreach (var header in original.Headers)`
| 2 | `42` |  | `{`
| 2 | `43` |  | `var templateHeaderKey = Handlebars.Compile(header.Key);`
| 2 | `44` |  | `var templateHeaderValues = header.Value`
| 2 | `45` |  | `.Select(Handlebars.Compile)`
| 5 | `46` |  | `.Select(func => func(template))`
| 2 | `47` |  | `.ToArray();`
|  | `48` |  | ``
| 2 | `49` |  | `newHeaders.Add(templateHeaderKey(template), new WireMockList<string>(templateHeaderValues));`
| 2 | `50` |  | `}`
|  | `51` |  | ``
| 6 | `52` |  | `responseMessage.Headers = newHeaders;`
|  | `53` |  | ``
| 6 | `54` |  | `return responseMessage;`
| 6 | `55` |  | `}`
|  | `56` |  | `}`
|  | `57` |  | `}`

# Methods/Properties

Transform(WireMock.RequestMessage,WireMock.ResponseMessage)