mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-17 06:29:57 +02:00
Solve #10
This commit is contained in:
@@ -30,6 +30,20 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithBody(@"{ ""msg"": ""Hello world!""}")
|
.WithBody(@"{ ""msg"": ""Hello world!""}")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.WithUrl("/data").UsingPost())
|
||||||
|
.RespondWith(Response
|
||||||
|
.WithStatusCode(201)
|
||||||
|
.WithHeader("Content-Type", "application/json")
|
||||||
|
.WithBody(@"{ ""result"": ""data posted with 201""}"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.WithUrl("/data").UsingDelete())
|
||||||
|
.RespondWith(Response
|
||||||
|
.WithStatusCode(200)
|
||||||
|
.WithHeader("Content-Type", "application/json")
|
||||||
|
.WithBody(@"{ ""result"": ""data deleted with 201""}"));
|
||||||
|
|
||||||
Console.WriteLine("Press any key to stop the server");
|
Console.WriteLine("Press any key to stop the server");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,14 @@
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
IHeadersRequestBuilder UsingPost();
|
IHeadersRequestBuilder UsingPost();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using delete.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingDelete();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using put.
|
/// The using put.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -113,6 +113,18 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using delete.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
public IHeadersRequestBuilder UsingDelete()
|
||||||
|
{
|
||||||
|
_requestSpecs.Add(new RequestVerbSpec("delete"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The using head.
|
/// The using head.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace WireMock.Net.Tests.Http
|
|||||||
public class TinyHttpServerTests
|
public class TinyHttpServerTests
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_Call_Handler_on_Request()
|
public void Should_call_handler_on_request()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var port = Ports.FindFreeTcpPort();
|
var port = Ports.FindFreeTcpPort();
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace WireMock.Net.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_specify_requests_matching_given_url_and_method()
|
public void Should_specify_requests_matching_given_url_and_method_put()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Request.WithUrl("/foo").UsingPut();
|
var spec = Request.WithUrl("/foo").UsingPut();
|
||||||
@@ -83,6 +83,58 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_specify_requests_matching_given_url_and_method_post()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
var spec = Request.WithUrl("/foo").UsingPost();
|
||||||
|
|
||||||
|
// when
|
||||||
|
var request = new RequestMessage("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_specify_requests_matching_given_url_and_method_get()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
var spec = Request.WithUrl("/foo").UsingGet();
|
||||||
|
|
||||||
|
// when
|
||||||
|
var request = new RequestMessage("/foo", string.Empty, "GET", "whatever", new Dictionary<string, string>());
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_specify_requests_matching_given_url_and_method_delete()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
var spec = Request.WithUrl("/foo").UsingDelete();
|
||||||
|
|
||||||
|
// when
|
||||||
|
var request = new RequestMessage("/foo", string.Empty, "DELETE", "whatever", new Dictionary<string, string>());
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_specify_requests_matching_given_url_and_method_head()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
var spec = Request.WithUrl("/foo").UsingHead();
|
||||||
|
|
||||||
|
// when
|
||||||
|
var request = new RequestMessage("/foo", string.Empty, "HEAD", "whatever", new Dictionary<string, string>());
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
||||||
{
|
{
|
||||||
@@ -227,3 +279,4 @@ namespace WireMock.Net.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user