mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-25 02:21:00 +01:00
@@ -48,15 +48,15 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public void FluentMockServer_Admin_StartStop()
|
||||
{
|
||||
var server1 = FluentMockServer.Start("http://localhost:9091");
|
||||
var server1 = FluentMockServer.Start("http://localhost:19091");
|
||||
|
||||
Check.That(server1.Urls[0]).Equals("http://localhost:9091");
|
||||
Check.That(server1.Urls[0]).Equals("http://localhost:19091");
|
||||
|
||||
server1.Stop();
|
||||
|
||||
var server2 = FluentMockServer.Start("http://localhost:9091/");
|
||||
var server2 = FluentMockServer.Start("http://localhost:19091/");
|
||||
|
||||
Check.That(server2.Urls[0]).Equals("http://localhost:9091/");
|
||||
Check.That(server2.Urls[0]).Equals("http://localhost:19091/");
|
||||
|
||||
server2.Stop();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace WireMock.Net.Tests
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_respond_to_request_bodyAsCallback()
|
||||
{
|
||||
// given
|
||||
// Assign
|
||||
var _server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
@@ -114,14 +114,18 @@ namespace WireMock.Net.Tests
|
||||
.WithPath("/foo")
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithBody(req => $"{{ path: '{req.Path}' }}"));
|
||||
.WithStatusCode(500)
|
||||
.WithHeader("H1", "X1")
|
||||
.WithBody(req => $"path: {req.Path}"));
|
||||
|
||||
// when
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0] + "/foo");
|
||||
// Act
|
||||
var response = await new HttpClient().GetAsync("http://localhost:" + _server.Ports[0] + "/foo");
|
||||
|
||||
// then
|
||||
Check.That(response).IsEqualTo("{ path: '/foo' }");
|
||||
// Assert
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Check.That(content).IsEqualTo("path: /foo");
|
||||
Check.That((int) response.StatusCode).IsEqualTo(500);
|
||||
Check.That(response.Headers.GetValues("H1")).ContainsExactly("X1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
@@ -150,5 +149,30 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
|
||||
Check.That(((dynamic)responseMessage.BodyAsJson).value).Equals(42);
|
||||
Check.That(responseMessage.BodyEncoding).Equals(Encoding.ASCII);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_WithBody_Func()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/test"), "GET", ClientIp);
|
||||
|
||||
var response = Response.Create()
|
||||
.WithStatusCode(500)
|
||||
.WithHeader("H1", "X1")
|
||||
.WithHeader("H2", "X2")
|
||||
.WithBody(req => $"path: {req.Path}");
|
||||
|
||||
// Act
|
||||
var responseMessage = await response.ProvideResponseAsync(request);
|
||||
|
||||
// Assert
|
||||
Check.That(responseMessage.Body).IsEqualTo("path: /test");
|
||||
Check.That(responseMessage.BodyAsBytes).IsNull();
|
||||
Check.That(responseMessage.BodyAsJson).IsNull();
|
||||
Check.That(responseMessage.BodyEncoding.CodePage).Equals(Encoding.UTF8.CodePage);
|
||||
Check.That(responseMessage.StatusCode).IsEqualTo(500);
|
||||
Check.That(responseMessage.Headers["H1"].ToString()).IsEqualTo("X1");
|
||||
Check.That(responseMessage.Headers["H2"].ToString()).IsEqualTo("X2");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user