ICallbackResponseBuilder + added more unit-tests (#101)

* Callback

* Add more tests
This commit is contained in:
Stef Heyenrath
2018-03-02 09:12:36 +00:00
committed by GitHub
parent 22298114d7
commit 977d91109e
18 changed files with 277 additions and 72 deletions

View File

@@ -89,13 +89,12 @@ namespace WireMock.Net.Tests
}
[Fact]
public void FluentMockServer_Admin_Mappings_Get()
public void FluentMockServer_Admin_Mappings_WithGuid_Get()
{
Guid guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
_server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/foo1").UsingGet())
.WithGuid(guid)
_server.Given(Request.Create().WithPath("/foo1").UsingGet()).WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(201).WithBody("1"));
_server.Given(Request.Create().WithPath("/foo2").UsingGet())
@@ -105,6 +104,19 @@ namespace WireMock.Net.Tests
Check.That(mappings).HasSize(2);
}
[Fact]
public void FluentMockServer_Admin_Mappings_WithGuidAsString_Get()
{
string guid = "90356dba-b36c-469a-a17e-669cd84f1f05";
_server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/foo1").UsingGet()).WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(201).WithBody("1"));
var mappings = _server.Mappings.ToArray();
Check.That(mappings).HasSize(1);
}
[Fact]
public void FluentMockServer_Admin_Mappings_Add_SameGuid()
{
@@ -432,6 +444,23 @@ namespace WireMock.Net.Tests
Check.That(requestLoggedB.RequestMessage.Path).EndsWith("/foo3");
}
[Fact]
public async Task FluentMockServer_Should_respond_to_request_callback()
{
// Assign
_server = FluentMockServer.Start();
_server
.Given(Request.Create().WithPath("/foo").UsingGet())
.RespondWith(Response.Create().WithCallback(req => new ResponseMessage { Body = req.Path + "Bar" }));
// Act
string response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + "/foo");
// Assert
Check.That(response).IsEqualTo("/fooBar");
}
public void Dispose()
{
_server?.Stop();