mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 16:58:27 +02:00
Refactor fluent interfaces
This commit is contained in:
@@ -20,48 +20,48 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
Console.WriteLine("FluentMockServer running at {0}", server.Port);
|
Console.WriteLine("FluentMockServer running at {0}", server.Port);
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl(u => u.Contains("x")).UsingGet())
|
.Given(Request.Create().WithUrl(u => u.Contains("x")).UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""/x with FUNC 200""}"));
|
.WithBody(@"{ ""result"": ""/x with FUNC 200""}"));
|
||||||
|
|
||||||
// http://localhost:8080/gffgfgf/sddsds?start=1000&stop=1&stop=2
|
// http://localhost:8080/gffgfgf/sddsds?start=1000&stop=1&stop=2
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl("/*").UsingGet())
|
.Given(Request.Create().WithUrl("/*").UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||||
.WithBody(@"{""msg"": ""Hello world! : {{request.url}} : {{request.path}} : {{request.query.start}} : {{request.query.stop.[0]}}""")
|
.WithBody(@"{""msg"": ""Hello world! : {{request.url}} : {{request.path}} : {{request.query.start}} : {{request.query.stop.[0]}}""")
|
||||||
.AfterDelay(TimeSpan.FromMilliseconds(100))
|
|
||||||
.WithTransformer()
|
.WithTransformer()
|
||||||
|
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||||
);
|
);
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl("/data").UsingPost().WithBody(b => b.Contains("e")))
|
.Given(Request.Create().WithUrl("/data").UsingPost().WithBody(b => b.Contains("e")))
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(201)
|
.WithStatusCode(201)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""data posted with FUNC 201""}"));
|
.WithBody(@"{ ""result"": ""data posted with FUNC 201""}"));
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl("/data").UsingPost())
|
.Given(Request.Create().WithUrl("/data").UsingPost())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(201)
|
.WithStatusCode(201)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""data posted with 201""}"));
|
.WithBody(@"{ ""result"": ""data posted with 201""}"));
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")))
|
.Given(Request.Create().WithUrl("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")))
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(201)
|
.WithStatusCode(201)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""json posted with 201""}"));
|
.WithBody(@"{ ""result"": ""json posted with 201""}"));
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.WithUrl("/data").UsingDelete())
|
.Given(Request.Create().WithUrl("/data").UsingDelete())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace WireMock
|
|||||||
/// The listener request.
|
/// The listener request.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="Request"/>.
|
/// The <see cref="AndPathRequest"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public RequestMessage Map(HttpListenerRequest listenerRequest)
|
public RequestMessage Map(HttpListenerRequest listenerRequest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The composite request matcher.
|
/// The composite request matcher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestMessageCompositeMatcher : IRequestMatcher
|
public abstract class RequestMessageCompositeMatcher : IRequestMatcher
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<IRequestMatcher> _requestMatchers;
|
private readonly IEnumerable<IRequestMatcher> _requestMatchers;
|
||||||
|
|
||||||
|
|||||||
6
src/WireMock/RequestBuilders/IAndPathRequestBuilder.cs
Normal file
6
src/WireMock/RequestBuilders/IAndPathRequestBuilder.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
public interface IRequestBuilder : IUrlAndPathRequestBuilder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/WireMock/RequestBuilders/IUrlAndPathRequestBuilder.cs
Normal file
39
src/WireMock/RequestBuilders/IUrlAndPathRequestBuilder.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IUrlAndPathRequestBuilder
|
||||||
|
/// </summary>
|
||||||
|
public interface IUrlAndPathRequestBuilder : IVerbRequestBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with url.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">The url.</param>
|
||||||
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
|
IUrlAndPathRequestBuilder WithUrl([NotNull] string url);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with url.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="func">The url func.</param>
|
||||||
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
|
IUrlAndPathRequestBuilder WithUrl([NotNull] Func<string, bool> func);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
|
IUrlAndPathRequestBuilder WithPath([NotNull] string path);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="func">The path func.</param>
|
||||||
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
|
IUrlAndPathRequestBuilder WithPath([NotNull] Func<string, bool> func);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,47 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
|
||||||
"SA1101:PrefixLocalCallsWithThis",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
|
||||||
"SA1126:PrefixCallsCorrectly",
|
|
||||||
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.RequestBuilders
|
namespace WireMock.RequestBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The requests.
|
/// The requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Request : RequestMessageCompositeMatcher, IVerbRequestBuilder
|
public class Request : RequestMessageCompositeMatcher, IRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The _request matchers.
|
|
||||||
/// </summary>
|
|
||||||
private readonly IList<IRequestMatcher> _requestMatchers;
|
private readonly IList<IRequestMatcher> _requestMatchers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates this instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
public static IRequestBuilder Create()
|
||||||
|
{
|
||||||
|
return new Request(new List<IRequestMatcher>());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Request"/> class.
|
/// Initializes a new instance of the <see cref="Request"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestMatchers">
|
/// <param name="requestMatchers">The request matchers.</param>
|
||||||
/// The request matchers.
|
|
||||||
/// </param>
|
|
||||||
private Request(IList<IRequestMatcher> requestMatchers) : base(requestMatchers)
|
private Request(IList<IRequestMatcher> requestMatchers) : base(requestMatchers)
|
||||||
{
|
{
|
||||||
_requestMatchers = requestMatchers;
|
_requestMatchers = requestMatchers;
|
||||||
@@ -50,65 +35,45 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with url.
|
/// The with url.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">
|
/// <param name="url">The url.</param>
|
||||||
/// The url.
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
/// </param>
|
public IUrlAndPathRequestBuilder WithUrl(string url)
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IVerbRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public static IVerbRequestBuilder WithUrl(string url)
|
|
||||||
{
|
{
|
||||||
var specs = new List<IRequestMatcher> { new RequestMessageUrlMatcher(url) };
|
_requestMatchers.Add(new RequestMessageUrlMatcher(url));
|
||||||
|
return this;
|
||||||
return new Request(specs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with url.
|
/// The with url.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">
|
/// <param name="func">The url func.</param>
|
||||||
/// The url func.
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
/// </param>
|
public IUrlAndPathRequestBuilder WithUrl(Func<string, bool> func)
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IVerbRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public static IVerbRequestBuilder WithUrl(Func<string, bool> func)
|
|
||||||
{
|
{
|
||||||
var specs = new List<IRequestMatcher> { new RequestMessageUrlMatcher(func) };
|
_requestMatchers.Add(new RequestMessageUrlMatcher(func));
|
||||||
|
return this;
|
||||||
return new Request(specs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// The with path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">
|
/// <param name="path">The path.</param>
|
||||||
/// The path.
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
/// </param>
|
public IUrlAndPathRequestBuilder WithPath(string path)
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IVerbRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public static IVerbRequestBuilder WithPath(string path)
|
|
||||||
{
|
{
|
||||||
var specs = new List<IRequestMatcher> { new RequestMessagePathMatcher(path) };
|
_requestMatchers.Add(new RequestMessagePathMatcher(path));
|
||||||
|
return this;
|
||||||
return new Request(specs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with path.
|
/// The with path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">
|
/// <param name="func">The path func.</param>
|
||||||
/// The path func.
|
/// <returns>The <see cref="IUrlAndPathRequestBuilder"/>.</returns>
|
||||||
/// </param>
|
public IUrlAndPathRequestBuilder WithPath(Func<string, bool> func)
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IVerbRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public static IVerbRequestBuilder WithPath([NotNull] Func<string, bool> func)
|
|
||||||
{
|
{
|
||||||
var specs = new List<IRequestMatcher> { new RequestMessagePathMatcher(func) };
|
_requestMatchers.Add(new RequestMessagePathMatcher(func));
|
||||||
|
return this;
|
||||||
return new Request(specs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -179,6 +144,12 @@ namespace WireMock.RequestBuilders
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public IHeadersRequestBuilder UsingAnyVerb()
|
public IHeadersRequestBuilder UsingAnyVerb()
|
||||||
{
|
{
|
||||||
|
var matchers = _requestMatchers.Where(m => m is RequestMessageVerbMatcher).ToList();
|
||||||
|
foreach (var matcher in matchers)
|
||||||
|
{
|
||||||
|
_requestMatchers.Remove(matcher);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The BodyResponseBuilder interface.
|
/// The BodyResponseBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBodyResponseBuilder : IDelayResponseBuilder
|
public interface IBodyResponseBuilder : ITransformResponseBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body.
|
/// The with body.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="ITransformResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBody([NotNull] string body);
|
ITransformResponseBuilder WithBody([NotNull] string body);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with body as base64.
|
/// The with body as base64.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bodyAsbase64">The body asbase64.</param>
|
/// <param name="bodyAsbase64">The body asbase64.</param>
|
||||||
/// <param name="encoding">The Encoding.</param>
|
/// <param name="encoding">The Encoding.</param>
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
/// <returns>A <see cref="ITransformResponseBuilder"/>.</returns>
|
||||||
IResponseBuilder WithBodyAsBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
|
ITransformResponseBuilder WithBodyAsBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,8 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The after delay.
|
/// The after delay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delay">
|
/// <param name="delay">The delay.</param>
|
||||||
/// The delay.
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
/// </param>
|
IResponseBuilder WithDelay(TimeSpan delay);
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IResponseBuilder AfterDelay(TimeSpan delay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace WireMock.ResponseBuilders
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace WireMock.ResponseBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The HeadersResponseBuilder interface.
|
/// The HeadersResponseBuilder interface.
|
||||||
@@ -8,15 +10,9 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with header.
|
/// The with header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">
|
/// <param name="name">The name.</param>
|
||||||
/// The name.
|
/// <param name="value">The value.</param>
|
||||||
/// </param>
|
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
|
||||||
/// <param name="value">
|
IHeadersResponseBuilder WithHeader([NotNull] string name, string value);
|
||||||
/// The value.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IResponseBuilder WithHeader(string name, string value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ResponseBuilder interface.
|
/// The ResponseBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IResponseBuilder : ITransformResponseBuilder
|
public interface IResponseBuilder : IStatusCodeResponseBuilder
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
40
src/WireMock/ResponseBuilders/IStatusCodeResponseBuilder.cs
Normal file
40
src/WireMock/ResponseBuilders/IStatusCodeResponseBuilder.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace WireMock.ResponseBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The StatusCodeResponseBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IStatusCodeResponseBuilder : IHeadersResponseBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with status code.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="code">
|
||||||
|
/// The code.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
|
||||||
|
IHeadersResponseBuilder WithStatusCode(int code);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with status code.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="code">
|
||||||
|
/// The code.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
|
||||||
|
IHeadersResponseBuilder WithStatusCode(HttpStatusCode code);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with Success status code (200).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
IHeadersResponseBuilder WithSuccess();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with NotFound status code (404).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
IHeadersResponseBuilder WithNotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,14 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The BodyResponseBuilder interface.
|
/// The BodyResponseBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITransformResponseBuilder : IHeadersResponseBuilder
|
public interface ITransformResponseBuilder : IDelayResponseBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with transformer.
|
/// The with transformer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
/// The <see cref="IDelayResponseBuilder"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
IResponseBuilder WithTransformer();
|
IDelayResponseBuilder WithTransformer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,33 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
|
||||||
using HandlebarsDotNet;
|
using HandlebarsDotNet;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
[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
|
namespace WireMock.ResponseBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The responses.
|
/// The Response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Response : IResponseBuilder
|
public class Response : IResponseBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The _response.
|
|
||||||
/// </summary>
|
|
||||||
private readonly ResponseMessage _responseMessage;
|
private readonly ResponseMessage _responseMessage;
|
||||||
|
private TimeSpan _delay = TimeSpan.Zero;
|
||||||
|
private bool _useTransformer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _delay.
|
/// Creates this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private TimeSpan _delay = TimeSpan.Zero;
|
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
[PublicAPI]
|
||||||
private bool _useTransformer;
|
public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null)
|
||||||
|
{
|
||||||
|
var message = responseMessage ?? new ResponseMessage { StatusCode = (int) HttpStatusCode.OK };
|
||||||
|
return new Response(message);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Response"/> class.
|
/// Initializes a new instance of the <see cref="Response"/> class.
|
||||||
@@ -47,42 +35,120 @@ namespace WireMock.ResponseBuilders
|
|||||||
/// <param name="responseMessage">
|
/// <param name="responseMessage">
|
||||||
/// The response.
|
/// The response.
|
||||||
/// </param>
|
/// </param>
|
||||||
public Response(ResponseMessage responseMessage)
|
private Response(ResponseMessage responseMessage)
|
||||||
{
|
{
|
||||||
_responseMessage = responseMessage;
|
_responseMessage = responseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with Success status code.
|
/// The with status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
/// <param name="code">The code.</param>
|
||||||
public static IResponseBuilder WithSuccess()
|
/// <returns>A <see cref="IHeadersResponseBuilder"/>.</returns>\
|
||||||
|
[PublicAPI]
|
||||||
|
public IHeadersResponseBuilder WithStatusCode(int code)
|
||||||
{
|
{
|
||||||
return WithStatusCode(200);
|
_responseMessage.StatusCode = code;
|
||||||
}
|
return this;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The with NotFound status code.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
|
||||||
public static IResponseBuilder WithNotFound()
|
|
||||||
{
|
|
||||||
return WithStatusCode(404);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The with status code.
|
/// The with status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="code">
|
/// <param name="code">The code.</param>
|
||||||
/// The code.
|
/// <returns>A <see cref="IHeadersResponseBuilder"/>.</returns>
|
||||||
/// </param>
|
[PublicAPI]
|
||||||
|
public IHeadersResponseBuilder WithStatusCode(HttpStatusCode code)
|
||||||
|
{
|
||||||
|
return WithStatusCode((int) code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with Success status code (200).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[PublicAPI]
|
||||||
|
public IHeadersResponseBuilder WithSuccess()
|
||||||
|
{
|
||||||
|
return WithStatusCode((int) HttpStatusCode.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with NotFound status code (404).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||||
|
[PublicAPI]
|
||||||
|
public IHeadersResponseBuilder WithNotFound()
|
||||||
|
{
|
||||||
|
return WithStatusCode((int)HttpStatusCode.NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
/// <returns>The <see cref="IHeadersResponseBuilder"/>.</returns>
|
||||||
|
public IHeadersResponseBuilder WithHeader(string name, string value)
|
||||||
|
{
|
||||||
|
Check.NotNull(name, nameof(name));
|
||||||
|
|
||||||
|
_responseMessage.AddHeader(name, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="body">The body.</param>
|
||||||
|
/// <returns>A <see cref="ITransformResponseBuilder"/>.</returns>
|
||||||
|
public ITransformResponseBuilder WithBody(string body)
|
||||||
|
{
|
||||||
|
Check.NotNull(body, nameof(body));
|
||||||
|
|
||||||
|
_responseMessage.Body = body;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with body as base64.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bodyAsbase64">The body asbase64.</param>
|
||||||
|
/// <param name="encoding">The Encoding.</param>
|
||||||
|
/// <returns>A <see cref="ITransformResponseBuilder"/>.</returns>
|
||||||
|
public ITransformResponseBuilder WithBodyAsBase64(string bodyAsbase64, Encoding encoding = null)
|
||||||
|
{
|
||||||
|
Check.NotNull(bodyAsbase64, nameof(bodyAsbase64));
|
||||||
|
|
||||||
|
_responseMessage.Body = (encoding ?? Encoding.UTF8).GetString(Convert.FromBase64String(bodyAsbase64));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The with transformer.
|
||||||
|
/// </summary>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
/// The <see cref="IResponseBuilder"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public static IResponseBuilder WithStatusCode(int code)
|
public IDelayResponseBuilder WithTransformer()
|
||||||
{
|
{
|
||||||
var response = new ResponseMessage { StatusCode = code };
|
_useTransformer = true;
|
||||||
return new Response(response);
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The after delay.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="delay">
|
||||||
|
/// The delay.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IProvideResponses"/>.
|
||||||
|
/// </returns>
|
||||||
|
public IResponseBuilder WithDelay(TimeSpan delay)
|
||||||
|
{
|
||||||
|
_delay = delay;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -120,81 +186,5 @@ namespace WireMock.ResponseBuilders
|
|||||||
|
|
||||||
return _responseMessage;
|
return _responseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The with header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">
|
|
||||||
/// The name.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="value">
|
|
||||||
/// The value.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public IResponseBuilder WithHeader(string name, string value)
|
|
||||||
{
|
|
||||||
_responseMessage.AddHeader(name, value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The with body.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="body">
|
|
||||||
/// The body.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public IResponseBuilder WithBody(string body)
|
|
||||||
{
|
|
||||||
Check.NotNull(body, nameof(body));
|
|
||||||
|
|
||||||
_responseMessage.Body = body;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The with body as base64.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bodyAsbase64">The body asbase64.</param>
|
|
||||||
/// <param name="encoding"></param>
|
|
||||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
|
||||||
public IResponseBuilder WithBodyAsBase64(string bodyAsbase64, Encoding encoding = null)
|
|
||||||
{
|
|
||||||
Check.NotNull(bodyAsbase64, nameof(bodyAsbase64));
|
|
||||||
|
|
||||||
_responseMessage.Body = (encoding ?? Encoding.UTF8).GetString(Convert.FromBase64String(bodyAsbase64));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The with transformer.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
public IResponseBuilder WithTransformer()
|
|
||||||
{
|
|
||||||
_useTransformer = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The after delay.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="delay">
|
|
||||||
/// The delay.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IProvideResponses"/>.
|
|
||||||
/// </returns>
|
|
||||||
public IResponseBuilder AfterDelay(TimeSpan delay)
|
|
||||||
{
|
|
||||||
_delay = delay;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,10 +44,10 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ namespace WireMock.Net.Tests
|
|||||||
// given
|
// given
|
||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server.Given(Request.WithUrl("/foo").UsingGet()).RespondWith(Response.WithSuccess().WithBodyAsBase64("SGVsbG8gV29ybGQ/"));
|
_server.Given(Request.Create().WithUrl("/foo").UsingGet()).RespondWith(Response.Create().WithBodyAsBase64("SGVsbG8gV29ybGQ/"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
|
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Port + "/foo");
|
||||||
@@ -114,7 +114,7 @@ namespace WireMock.Net.Tests
|
|||||||
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
|
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
var result = _server.SearchLogsFor(Request.WithUrl("/b.*")).ToList();
|
var result = _server.SearchLogsFor(Request.Create().WithUrl("/b.*")).ToList();
|
||||||
Check.That(result).HasSize(1);
|
Check.That(result).HasSize(1);
|
||||||
|
|
||||||
var requestLogged = result.First();
|
var requestLogged = result.First();
|
||||||
@@ -143,11 +143,10 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -165,17 +164,17 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(307)
|
.WithStatusCode(307)
|
||||||
.WithHeader("Location", "/bar"));
|
.WithHeader("Location", "/bar"));
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/bar")
|
.WithUrl("/bar")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody("REDIRECT SUCCESSFUL"));
|
.WithBody("REDIRECT SUCCESSFUL"));
|
||||||
|
|
||||||
@@ -193,12 +192,11 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/*"))
|
.WithUrl("/*"))
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
|
||||||
.WithBody(@"{ msg: ""Hello world!""}")
|
.WithBody(@"{ msg: ""Hello world!""}")
|
||||||
.AfterDelay(TimeSpan.FromMilliseconds(2000)));
|
.WithDelay(TimeSpan.FromMilliseconds(2000)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var watch = new Stopwatch();
|
var watch = new Stopwatch();
|
||||||
@@ -217,10 +215,9 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
|
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
|
||||||
_server
|
_server
|
||||||
.Given(Request
|
.Given(Request.Create()
|
||||||
.WithUrl("/*"))
|
.WithUrl("/*"))
|
||||||
.RespondWith(Response
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(200)
|
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url()
|
public void Should_specify_requests_matching_given_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo");
|
var spec = Request.Create().WithUrl("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -30,7 +30,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_prefix()
|
public void Should_specify_requests_matching_given_url_prefix()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo*");
|
var spec = Request.Create().WithUrl("/foo*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -45,7 +45,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_url()
|
public void Should_exclude_requests_not_matching_given_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo");
|
var spec = Request.Create().WithUrl("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -60,7 +60,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_path()
|
public void Should_specify_requests_matching_given_path()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithPath("/foo");
|
var spec = Request.Create().WithPath("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -75,7 +75,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method_put()
|
public void Should_specify_requests_matching_given_url_and_method_put()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingPut();
|
var spec = Request.Create().WithUrl("/foo").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -90,7 +90,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method_post()
|
public void Should_specify_requests_matching_given_url_and_method_post()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingPost();
|
var spec = Request.Create().WithUrl("/foo").UsingPost();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -105,7 +105,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method_get()
|
public void Should_specify_requests_matching_given_url_and_method_get()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingGet();
|
var spec = Request.Create().WithUrl("/foo").UsingGet();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -120,7 +120,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method_delete()
|
public void Should_specify_requests_matching_given_url_and_method_delete()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingDelete();
|
var spec = Request.Create().WithUrl("/foo").UsingDelete();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -135,7 +135,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method_head()
|
public void Should_specify_requests_matching_given_url_and_method_head()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingHead();
|
var spec = Request.Create().WithUrl("/foo").UsingHead();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -150,7 +150,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingPut();
|
var spec = Request.Create().WithUrl("/foo").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -165,7 +165,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/bar").UsingPut();
|
var spec = Request.Create().WithUrl("/bar").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -180,7 +180,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_headers()
|
public void Should_specify_requests_matching_given_url_and_headers()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -195,7 +195,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_headers()
|
public void Should_exclude_requests_not_matching_given_headers()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -210,7 +210,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false);
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -225,7 +225,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_header_prefix()
|
public void Should_specify_requests_matching_given_header_prefix()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "whatever";
|
string bodyAsString = "whatever";
|
||||||
@@ -240,7 +240,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body()
|
public void Should_specify_requests_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody("Hello world!");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody("Hello world!");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -255,7 +255,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_regex()
|
public void Should_specify_requests_matching_given_body_as_regex()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody("H.*o");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody("H.*o");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -270,7 +270,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_regexmatcher()
|
public void Should_specify_requests_matching_given_body_as_regexmatcher()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -285,7 +285,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_xpathmatcher_true()
|
public void Should_specify_requests_matching_given_body_as_xpathmatcher_true()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string xmlBodyAsString = @"
|
string xmlBodyAsString = @"
|
||||||
@@ -305,7 +305,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_xpathmatcher_false()
|
public void Should_specify_requests_matching_given_body_as_xpathmatcher_false()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string xmlBodyAsString = @"
|
string xmlBodyAsString = @"
|
||||||
@@ -325,7 +325,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_jsonpathmatcher_true()
|
public void Should_specify_requests_matching_given_body_as_jsonpathmatcher_true()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||||
@@ -340,7 +340,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_jsonpathmatcher_false()
|
public void Should_specify_requests_matching_given_body_as_jsonpathmatcher_false()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
||||||
@@ -355,7 +355,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_body()
|
public void Should_exclude_requests_not_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
var spec = Request.Create().WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "xxx";
|
string bodyAsString = "xxx";
|
||||||
@@ -370,7 +370,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_params()
|
public void Should_specify_requests_matching_given_params()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithPath("/foo").WithParam("bar", "1", "2");
|
var spec = Request.Create().WithPath("/foo").WithParam("bar", "1", "2");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -385,7 +385,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_params_func()
|
public void Should_specify_requests_matching_given_params_func()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithPath("/foo").UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
|
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
@@ -400,7 +400,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_params()
|
public void Should_exclude_requests_not_matching_given_params()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithPath("/foo").WithParam("bar", "1");
|
var spec = Request.Create().WithPath("/foo").WithParam("bar", "1");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
string bodyAsString = "Hello world!";
|
string bodyAsString = "Hello world!";
|
||||||
|
|||||||
Reference in New Issue
Block a user