mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 11:21:51 +01:00
Add unit test for Response Handlebars
This commit is contained in:
@@ -100,7 +100,7 @@ namespace WireMock.Net.Tests
|
||||
Check.That(_server.RequestLogs).HasSize(1);
|
||||
var requestLogged = _server.RequestLogs.First();
|
||||
Check.That(requestLogged.Verb).IsEqualTo("get");
|
||||
Check.That(requestLogged.Body).IsNull();
|
||||
Check.That(requestLogged.BodyAsBytes).IsNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -8,23 +8,6 @@ using NFluent;
|
||||
using NUnit.Framework;
|
||||
using WireMock.Http;
|
||||
|
||||
[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",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
@@ -77,7 +60,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
// then
|
||||
Check.That(MapperServer.LastRequestMessage).IsNotNull();
|
||||
Check.That(MapperServer.LastRequestMessage.BodyAsString).IsEqualTo("Hello!");
|
||||
Check.That(MapperServer.LastRequestMessage.Body).IsEqualTo("Hello!");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -7,24 +6,6 @@ using NFluent;
|
||||
using NUnit.Framework;
|
||||
using WireMock.Http;
|
||||
|
||||
[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",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[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.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace WireMock.Net.Tests
|
||||
// when
|
||||
string bodyAsString = "Hello world!";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
|
||||
|
||||
// then
|
||||
Check.That(spec.IsMatch(request)).IsTrue();
|
||||
|
||||
50
test/WireMock.Net.Tests/ResponseTests.cs
Normal file
50
test/WireMock.Net.Tests/ResponseTests.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
using WireMock.ResponseBuilders;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ResponseTests
|
||||
{
|
||||
[Test]
|
||||
public async Task Response_ProvideResponse_Handlebars_body()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString);
|
||||
|
||||
var response = Response.Create().WithBody("test {{request.url}} {{request.path}} {{request.verb}}").WithTransformer();
|
||||
|
||||
// act
|
||||
var responseMessage = await response.ProvideResponse(request);
|
||||
|
||||
// then
|
||||
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo post");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Response_ProvideResponse_Handlebars_headers()
|
||||
{
|
||||
// given
|
||||
string bodyAsString = "abc";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString, new Dictionary<string, string> { { "Content-Type", "text/plain" } });
|
||||
|
||||
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer();
|
||||
|
||||
// act
|
||||
var responseMessage = await response.ProvideResponse(request);
|
||||
|
||||
// then
|
||||
Check.That(responseMessage.Body).Equals("test");
|
||||
Check.That(responseMessage.Headers).Contains(new KeyValuePair<string,string>("x", "text/plain"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RequestTests.cs" />
|
||||
<Compile Include="RequestMessageTests.cs" />
|
||||
<Compile Include="ResponseTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user