using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.ResponseBuilders
{
///
/// The responses.
///
public class ResponseBuilder : IHeadersResponseBuilder
{
///
/// The _response.
///
private readonly Response _response;
///
/// The _delay.
///
private TimeSpan _delay = TimeSpan.Zero;
///
/// Initializes a new instance of the class.
///
///
/// The response.
///
public ResponseBuilder(Response response)
{
_response = response;
}
///
/// The with Success status code.
///
/// The .
public static IHeadersResponseBuilder WithSuccess()
{
return WithStatusCode(200);
}
///
/// The with NotFound status code.
///
/// The .
public static IHeadersResponseBuilder WithNotFound()
{
return WithStatusCode(404);
}
///
/// The with status code.
///
///
/// The code.
///
///
/// The .
///
public static IHeadersResponseBuilder WithStatusCode(int code)
{
var response = new Response { StatusCode = code };
return new ResponseBuilder(response);
}
///
/// The provide response.
///
///
/// The request.
///
///
/// The .
///
public async Task ProvideResponse(Request request)
{
await Task.Delay(_delay);
return _response;
}
///
/// The with header.
///
///
/// The name.
///
///
/// The value.
///
///
/// The .
///
public IHeadersResponseBuilder WithHeader(string name, string value)
{
_response.AddHeader(name, value);
return this;
}
///
/// The with body.
///
///
/// The body.
///
///
/// The .
///
public IDelayResponseBuilder WithBody(string body)
{
_response.Body = body;
return this;
}
///
/// The after delay.
///
///
/// The delay.
///
///
/// The .
///
public IProvideResponses AfterDelay(TimeSpan delay)
{
_delay = delay;
return this;
}
}
}