# Summary

Class: | WireMock.ResponseBuilders.Response
Assembly: | WireMock.Net
File(s): | C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\ResponseBuilders\Response.cs
Covered lines: | 80
Uncovered lines: | 16
Coverable lines: | 96
Total lines: | 277
Line coverage: | 83.3%
Branch coverage: | 80%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
Create(...) | 2 | 0 | 100 | 100
Create(...) | 1 | 0 | 0 | 0
.ctor(...) | 1 | 0 | 100 | 100
WithStatusCode(...) | 1 | 0 | 100 | 100
WithStatusCode(...) | 1 | 0 | 0 | 0
WithSuccess() | 1 | 0 | 0 | 0
WithNotFound() | 1 | 0 | 0 | 0
WithHeader(...) | 1 | 0 | 100 | 100
WithHeaders(...) | 1 | 0 | 100 | 100
WithBody(...) | 2 | 2 | 100 | 100
WithBodyAsJson(...) | 3 | 2 | 100 | 66.67
WithBodyAsBase64(...) | 2 | 2 | 100 | 66.67
WithTransformer() | 1 | 0 | 100 | 100
WithDelay(...) | 2 | 0 | 100 | 100
WithDelay(...) | 1 | 0 | 0 | 0
ProvideResponse() | 8 | 4 | 100 | 100

# File(s)

## C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\ResponseBuilders\Response.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Collections.Generic;`
|  | `3` |  | `using System.Net;`
|  | `4` |  | `using System.Text;`
|  | `5` |  | `using System.Threading.Tasks;`
|  | `6` |  | `using HandlebarsDotNet;`
|  | `7` |  | `using JetBrains.Annotations;`
|  | `8` |  | `using Newtonsoft.Json;`
|  | `9` |  | `using WireMock.Validation;`
|  | `10` |  | ``
|  | `11` |  | `namespace WireMock.ResponseBuilders`
|  | `12` |  | `{`
|  | `13` |  | `/// <summary>`
|  | `14` |  | `/// The Response.`
|  | `15` |  | `/// </summary>`
|  | `16` |  | `public class Response : IResponseBuilder`
|  | `17` |  | `{`
|  | `18` |  | `/// <summary>`
|  | `19` |  | `/// The delay`
|  | `20` |  | `/// </summary>`
| 14 | `21` |  | `public TimeSpan? Delay { get; private set; }`
|  | `22` |  | ``
|  | `23` |  | `/// <summary>`
|  | `24` |  | `/// Gets a value indicating whether [use transformer].`
|  | `25` |  | `/// </summary>`
|  | `26` |  | `/// <value>`
|  | `27` |  | `/// <c>true</c> if [use transformer]; otherwise, <c>false</c>.`
|  | `28` |  | `/// </value>`
| 15 | `29` |  | `public bool UseTransformer { get; private set; }`
|  | `30` |  | ``
|  | `31` |  | `/// <summary>`
|  | `32` |  | `/// Gets the response message.`
|  | `33` |  | `/// </summary>`
|  | `34` |  | `/// <value>`
|  | `35` |  | `/// The response message.`
|  | `36` |  | `/// </value>`
| 74 | `37` |  | `public ResponseMessage ResponseMessage { get; }`
|  | `38` |  | ``
|  | `39` |  | `/// <summary>`
|  | `40` |  | `/// Creates this instance.`
|  | `41` |  | `/// </summary>`
|  | `42` |  | `/// <param name="responseMessage">ResponseMessage</param>`
|  | `43` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `44` |  | `[PublicAPI]`
|  | `45` |  | `public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null)`
| 22 | `46` |  | `{`
| 22 | `47` |  | `var message = responseMessage ?? new ResponseMessage { StatusCode = (int)HttpStatusCode.OK };`
| 22 | `48` |  | `return new Response(message);`
| 22 | `49` |  | `}`
|  | `50` |  | ``
|  | `51` |  | `/// <summary>`
|  | `52` |  | `/// Creates this instance.`
|  | `53` |  | `/// </summary>`
|  | `54` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `55` |  | `[PublicAPI]`
|  | `56` |  | `public static IResponseBuilder Create([NotNull] Func<ResponseMessage> func)`
| 0 | `57` |  | `{`
| 0 | `58` |  | `Check.NotNull(func, nameof(func));`
|  | `59` |  | ``
| 0 | `60` |  | `return new Response(func());`
| 0 | `61` |  | `}`
|  | `62` |  | ``
|  | `63` |  | `/// <summary>`
|  | `64` |  | `/// Initializes a new instance of the <see cref="Response"/> class.`
|  | `65` |  | `/// </summary>`
|  | `66` |  | `/// <param name="responseMessage">`
|  | `67` |  | `/// The response.`
|  | `68` |  | `/// </param>`
| 22 | `69` |  | `private Response(ResponseMessage responseMessage)`
| 22 | `70` |  | `{`
| 22 | `71` |  | `ResponseMessage = responseMessage;`
| 22 | `72` |  | `}`
|  | `73` |  | ``
|  | `74` |  | `/// <summary>`
|  | `75` |  | `/// The with status code.`
|  | `76` |  | `/// </summary>`
|  | `77` |  | `/// <param name="code">The code.</param>`
|  | `78` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>\`
|  | `79` |  | `[PublicAPI]`
|  | `80` |  | `public IResponseBuilder WithStatusCode(int code)`
| 13 | `81` |  | `{`
| 13 | `82` |  | `ResponseMessage.StatusCode = code;`
| 13 | `83` |  | `return this;`
| 13 | `84` |  | `}`
|  | `85` |  | ``
|  | `86` |  | `/// <summary>`
|  | `87` |  | `/// The with status code.`
|  | `88` |  | `/// </summary>`
|  | `89` |  | `/// <param name="code">The code.</param>`
|  | `90` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `91` |  | `[PublicAPI]`
|  | `92` |  | `public IResponseBuilder WithStatusCode(HttpStatusCode code)`
| 0 | `93` |  | `{`
| 0 | `94` |  | `return WithStatusCode((int)code);`
| 0 | `95` |  | `}`
|  | `96` |  | ``
|  | `97` |  | `/// <summary>`
|  | `98` |  | `/// The with Success status code (200).`
|  | `99` |  | `/// </summary>`
|  | `100` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `101` |  | `[PublicAPI]`
|  | `102` |  | `public IResponseBuilder WithSuccess()`
| 0 | `103` |  | `{`
| 0 | `104` |  | `return WithStatusCode((int)HttpStatusCode.OK);`
| 0 | `105` |  | `}`
|  | `106` |  | ``
|  | `107` |  | `/// <summary>`
|  | `108` |  | `/// The with NotFound status code (404).`
|  | `109` |  | `/// </summary>`
|  | `110` |  | `/// <returns>The <see cref="IResponseBuilder"/>.</returns>`
|  | `111` |  | `[PublicAPI]`
|  | `112` |  | `public IResponseBuilder WithNotFound()`
| 0 | `113` |  | `{`
| 0 | `114` |  | `return WithStatusCode((int)HttpStatusCode.NotFound);`
| 0 | `115` |  | `}`
|  | `116` |  | ``
|  | `117` |  | `/// <summary>`
|  | `118` |  | `/// The with header.`
|  | `119` |  | `/// </summary>`
|  | `120` |  | `/// <param name="name">The name.</param>`
|  | `121` |  | `/// <param name="value">The value.</param>`
|  | `122` |  | `/// <returns>The <see cref="IResponseBuilder"/>.</returns>`
|  | `123` |  | `public IResponseBuilder WithHeader(string name, string value)`
| 2 | `124` |  | `{`
| 2 | `125` |  | `Check.NotNull(name, nameof(name));`
|  | `126` |  | ``
| 2 | `127` |  | `ResponseMessage.AddHeader(name, value);`
| 2 | `128` |  | `return this;`
| 2 | `129` |  | `}`
|  | `130` |  | ``
|  | `131` |  | `/// <summary>`
|  | `132` |  | `/// The with headers.`
|  | `133` |  | `/// </summary>`
|  | `134` |  | `/// <param name="headers">The headers.</param>`
|  | `135` |  | `/// <returns></returns>`
|  | `136` |  | `public IResponseBuilder WithHeaders(IDictionary<string, string> headers)`
| 4 | `137` |  | `{`
| 4 | `138` |  | `ResponseMessage.Headers = headers;`
| 4 | `139` |  | `return this;`
| 4 | `140` |  | `}`
|  | `141` |  | ``
|  | `142` |  | `/// <summary>`
|  | `143` |  | `/// The with body.`
|  | `144` |  | `/// </summary>`
|  | `145` |  | `/// <param name="body">The body.</param>`
|  | `146` |  | `/// <param name="encoding">The body encoding.</param>`
|  | `147` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `148` |  | `public IResponseBuilder WithBody(string body, Encoding encoding = null)`
| 15 | `149` |  | `{`
| 15 | `150` |  | `Check.NotNull(body, nameof(body));`
|  | `151` |  | ``
| 15 | `152` |  | `ResponseMessage.Body = body;`
| 15 | `153` |  | `ResponseMessage.BodyEncoding = encoding ?? Encoding.UTF8;`
|  | `154` |  | ``
| 15 | `155` |  | `return this;`
| 15 | `156` |  | `}`
|  | `157` |  | ``
|  | `158` |  | `/// <summary>`
|  | `159` |  | `/// The with body (AsJson object).`
|  | `160` |  | `/// </summary>`
|  | `161` |  | `/// <param name="body">The body.</param>`
|  | `162` |  | `/// <param name="encoding">The body encoding.</param>`
|  | `163` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `164` |  | `public IResponseBuilder WithBodyAsJson(object body, Encoding encoding = null)`
| 1 | `165` |  | `{`
| 1 | `166` |  | `Check.NotNull(body, nameof(body));`
|  | `167` |  | ``
| 1 | `168` |  | `string jsonBody = JsonConvert.SerializeObject(body, new JsonSerializerSettings { Formatting = Formatting.Non`
|  | `169` |  | ``
| 1 | `170` |  | `if (encoding != null && !encoding.Equals(Encoding.UTF8))`
| 1 | `171` |  | `{`
| 1 | `172` |  | `jsonBody = encoding.GetString(Encoding.UTF8.GetBytes(jsonBody));`
| 1 | `173` |  | `ResponseMessage.BodyEncoding = encoding;`
| 1 | `174` |  | `}`
|  | `175` |  | ``
| 1 | `176` |  | `ResponseMessage.Body = jsonBody;`
|  | `177` |  | ``
| 1 | `178` |  | `return this;`
| 1 | `179` |  | `}`
|  | `180` |  | ``
|  | `181` |  | `/// <summary>`
|  | `182` |  | `/// The with body as base64.`
|  | `183` |  | `/// </summary>`
|  | `184` |  | `/// <param name="bodyAsbase64">The body asbase64.</param>`
|  | `185` |  | `/// <param name="encoding">The Encoding.</param>`
|  | `186` |  | `/// <returns>A <see cref="IResponseBuilder"/>.</returns>`
|  | `187` |  | `public IResponseBuilder WithBodyAsBase64(string bodyAsbase64, Encoding encoding = null)`
| 1 | `188` |  | `{`
| 1 | `189` |  | `Check.NotNull(bodyAsbase64, nameof(bodyAsbase64));`
|  | `190` |  | ``
| 1 | `191` |  | `encoding = encoding ?? Encoding.UTF8;`
|  | `192` |  | ``
| 1 | `193` |  | `ResponseMessage.Body = encoding.GetString(Convert.FromBase64String(bodyAsbase64));`
| 1 | `194` |  | `ResponseMessage.BodyEncoding = encoding;`
|  | `195` |  | ``
| 1 | `196` |  | `return this;`
| 1 | `197` |  | `}`
|  | `198` |  | ``
|  | `199` |  | `/// <summary>`
|  | `200` |  | `/// The with transformer.`
|  | `201` |  | `/// </summary>`
|  | `202` |  | `/// <returns>`
|  | `203` |  | `/// The <see cref="IResponseBuilder"/>.`
|  | `204` |  | `/// </returns>`
|  | `205` |  | `public IResponseBuilder WithTransformer()`
| 3 | `206` |  | `{`
| 3 | `207` |  | `UseTransformer = true;`
| 3 | `208` |  | `return this;`
| 3 | `209` |  | `}`
|  | `210` |  | ``
|  | `211` |  | `/// <summary>`
|  | `212` |  | `/// The with delay.`
|  | `213` |  | `/// </summary>`
|  | `214` |  | `/// <param name="delay">The TimeSpan to delay.</param>`
|  | `215` |  | `/// <returns>The <see cref="IResponseBuilder"/>.</returns>`
|  | `216` |  | `public IResponseBuilder WithDelay(TimeSpan delay)`
| 1 | `217` |  | `{`
| 2 | `218` |  | `Check.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));`
| 1 | `219` |  | `Delay = delay;`
| 1 | `220` |  | `return this;`
| 1 | `221` |  | `}`
|  | `222` |  | ``
|  | `223` |  | `/// <summary>`
|  | `224` |  | `/// The with delay.`
|  | `225` |  | `/// </summary>`
|  | `226` |  | `/// <param name="milliseconds">The milliseconds to delay.</param>`
|  | `227` |  | `/// <returns>The <see cref="IResponseBuilder"/>.</returns>`
|  | `228` |  | `public IResponseBuilder WithDelay(int milliseconds)`
| 0 | `229` |  | `{`
| 0 | `230` |  | `return WithDelay(TimeSpan.FromMilliseconds(milliseconds));`
| 0 | `231` |  | `}`
|  | `232` |  | ``
|  | `233` |  | `/// <summary>`
|  | `234` |  | `/// The provide response.`
|  | `235` |  | `/// </summary>`
|  | `236` |  | `/// <param name="requestMessage">`
|  | `237` |  | `/// The request.`
|  | `238` |  | `/// </param>`
|  | `239` |  | `/// <returns>`
|  | `240` |  | `/// The <see cref="Task"/>.`
|  | `241` |  | `/// </returns>`
|  | `242` |  | `public async Task<ResponseMessage> ProvideResponse(RequestMessage requestMessage)`
| 12 | `243` |  | `{`
|  | `244` |  | `ResponseMessage responseMessage;`
| 12 | `245` |  | `if (UseTransformer)`
| 3 | `246` |  | `{`
| 3 | `247` |  | `responseMessage = new ResponseMessage { StatusCode = ResponseMessage.StatusCode, BodyOriginal = Response`
|  | `248` |  | ``
| 3 | `249` |  | `var template = new { request = requestMessage };`
|  | `250` |  | ``
|  | `251` |  | `// Body`
| 3 | `252` |  | `var templateBody = Handlebars.Compile(ResponseMessage.Body);`
| 3 | `253` |  | `responseMessage.Body = templateBody(template);`
|  | `254` |  | ``
|  | `255` |  | `// Headers`
| 3 | `256` |  | `var newHeaders = new Dictionary<string, string>();`
| 11 | `257` |  | `foreach (var header in ResponseMessage.Headers)`
| 1 | `258` |  | `{`
| 1 | `259` |  | `var templateHeaderKey = Handlebars.Compile(header.Key);`
| 1 | `260` |  | `var templateHeaderValue = Handlebars.Compile(header.Value);`
|  | `261` |  | ``
| 1 | `262` |  | `newHeaders.Add(templateHeaderKey(template), templateHeaderValue(template));`
| 1 | `263` |  | `}`
| 3 | `264` |  | `responseMessage.Headers = newHeaders;`
| 3 | `265` |  | `}`
|  | `266` |  | `else`
| 9 | `267` |  | `{`
| 9 | `268` |  | `responseMessage = ResponseMessage;`
| 9 | `269` |  | `}`
|  | `270` |  | ``
| 12 | `271` |  | `if (Delay != null)`
| 1 | `272` |  | `await Task.Delay(Delay.Value);`
|  | `273` |  | ``
| 12 | `274` |  | `return responseMessage;`
| 12 | `275` |  | `}`
|  | `276` |  | `}`
|  | `277` |  | `}`

# Methods/Properties

Delay()
Delay(System.Nullable`1<System.TimeSpan>)
UseTransformer()
UseTransformer(System.Boolean)
ResponseMessage()
Create(WireMock.ResponseMessage)
Create(System.Func`1<WireMock.ResponseMessage>)
.ctor(WireMock.ResponseMessage)
WithStatusCode(System.Int32)
WithStatusCode(System.Net.HttpStatusCode)
WithSuccess()
WithNotFound()
WithHeader(System.String,System.String)
WithHeaders(System.Collections.Generic.IDictionary`2<System.String,System.String>)
WithBody(System.String,System.Text.Encoding)
WithBodyAsJson(System.Object,System.Text.Encoding)
WithBodyAsBase64(System.String,System.Text.Encoding)
WithTransformer()
WithDelay(System.TimeSpan)
WithDelay(System.Int32)
ProvideResponse()