using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
///
/// The requests.
///
public class Request : RequestMessageCompositeMatcher, IRequestBuilder
{
private readonly IList _requestMatchers;
///
/// Creates this instance.
///
/// The .
public static IRequestBuilder Create()
{
return new Request(new List());
}
///
/// Initializes a new instance of the class.
///
/// The request matchers.
private Request(IList requestMatchers) : base(requestMatchers)
{
_requestMatchers = requestMatchers;
}
///
/// The with url.
///
/// The url.
/// The .
public IUrlAndPathRequestBuilder WithUrl(string url)
{
_requestMatchers.Add(new RequestMessageUrlMatcher(url));
return this;
}
///
/// The with url.
///
/// The url func.
/// The .
public IUrlAndPathRequestBuilder WithUrl(Func func)
{
_requestMatchers.Add(new RequestMessageUrlMatcher(func));
return this;
}
///
/// The with path.
///
/// The path.
/// The .
public IUrlAndPathRequestBuilder WithPath(string path)
{
_requestMatchers.Add(new RequestMessagePathMatcher(path));
return this;
}
///
/// The with path.
///
/// The path func.
/// The .
public IUrlAndPathRequestBuilder WithPath(Func func)
{
_requestMatchers.Add(new RequestMessagePathMatcher(func));
return this;
}
///
/// The using get.
///
///
/// The .
///
public IHeadersRequestBuilder UsingGet()
{
_requestMatchers.Add(new RequestMessageVerbMatcher("get"));
return this;
}
///
/// The using post.
///
///
/// The .
///
public IHeadersRequestBuilder UsingPost()
{
_requestMatchers.Add(new RequestMessageVerbMatcher("post"));
return this;
}
///
/// The using put.
///
///
/// The .
///
public IHeadersRequestBuilder UsingPut()
{
_requestMatchers.Add(new RequestMessageVerbMatcher("put"));
return this;
}
///
/// The using delete.
///
///
/// The .
///
public IHeadersRequestBuilder UsingDelete()
{
_requestMatchers.Add(new RequestMessageVerbMatcher("delete"));
return this;
}
///
/// The using head.
///
///
/// The .
///
public IHeadersRequestBuilder UsingHead()
{
_requestMatchers.Add(new RequestMessageVerbMatcher("head"));
return this;
}
///
/// The using any verb.
///
///
/// The .
///
public IHeadersRequestBuilder UsingAnyVerb()
{
var matchers = _requestMatchers.Where(m => m is RequestMessageVerbMatcher).ToList();
foreach (var matcher in matchers)
{
_requestMatchers.Remove(matcher);
}
return this;
}
///
/// The using verb.
///
///
/// The verb.
///
///
/// The .
///
public IHeadersRequestBuilder UsingVerb(string verb)
{
_requestMatchers.Add(new RequestMessageVerbMatcher(verb));
return this;
}
///
/// The with body.
///
///
/// The body.
///
///
/// The .
///
public IRequestMatcher WithBody(string body)
{
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
return this;
}
///
/// The with body byte[].
///
///
/// The body as byte[].
///
///
/// The .
///
public IRequestMatcher WithBody(byte[] body)
{
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
return this;
}
///
/// The with body.
///
///
/// The body function.
///
///
/// The .
///
public IRequestMatcher WithBody(Func func)
{
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
///
/// The with body.
///
///
/// The body function.
///
///
/// The .
///
public IRequestMatcher WithBody(Func func)
{
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
///
/// The with body.
///
/// The matcher.
///
/// The .
///
public IRequestMatcher WithBody(IMatcher matcher)
{
_requestMatchers.Add(new RequestMessageBodyMatcher(matcher));
return this;
}
///
/// The with parameters.
///
///
/// The key.
///
///
/// The values.
///
///
/// The .
///
public IRequestMatcher WithParam(string key, params string[] values)
{
_requestMatchers.Add(new RequestMessageParamMatcher(key, values.ToList()));
return this;
}
///
/// The with parameters.
///
///
/// The func.
///
///
/// The .
///
public IRequestMatcher WithParam(Func>, bool> func)
{
_requestMatchers.Add(new RequestMessageParamMatcher(func));
return this;
}
///
/// The with header.
///
///
/// The name.
///
///
/// The value.
///
/// ignore Case
///
/// The .
///
public IHeadersRequestBuilder WithHeader(string name, string value, bool ignoreCase = true)
{
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, value, ignoreCase));
return this;
}
///
/// The with header.
///
///
/// The func.
///
///
/// The .
///
public IHeadersRequestBuilder WithHeader(Func, bool> func)
{
_requestMatchers.Add(new RequestMessageHeaderMatcher(func));
return this;
}
}
}