mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-22 08:18:26 +02:00
Add support to use 'mapping' object in in reponse templating (#798)
* mapping * . * .
This commit is contained in:
@@ -1,48 +1,55 @@
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.ResponseBuilders
|
||||
namespace WireMock.Net.Tests.ResponseBuilders;
|
||||
|
||||
public class ResponseWithFaultTests
|
||||
{
|
||||
public class ResponseWithFaultTests
|
||||
private readonly WireMockServerSettings _settings = new();
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
private readonly Mock<IMapping> _mappingMock;
|
||||
|
||||
public ResponseWithFaultTests()
|
||||
{
|
||||
private readonly WireMockServerSettings _settings = new WireMockServerSettings();
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Theory]
|
||||
[InlineData(FaultType.EMPTY_RESPONSE)]
|
||||
[InlineData(FaultType.MALFORMED_RESPONSE_CHUNK)]
|
||||
public async Task Response_ProvideResponse_WithFault(FaultType faultType)
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/fault"), "GET", ClientIp);
|
||||
|
||||
// Act
|
||||
var responseBuilder = Response.Create().WithFault(faultType);
|
||||
var response = await responseBuilder.ProvideResponseAsync(request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Message.FaultType.Should().Be(faultType);
|
||||
response.Message.FaultPercentage.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(FaultType.EMPTY_RESPONSE, 0.5)]
|
||||
public async Task Response_ProvideResponse_WithFault_IncludingPercentage(FaultType faultType, double percentage)
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/fault"), "GET", ClientIp);
|
||||
|
||||
// Act
|
||||
var responseBuilder = Response.Create().WithFault(faultType, percentage);
|
||||
var response = await responseBuilder.ProvideResponseAsync(request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Message.FaultType.Should().Be(faultType);
|
||||
response.Message.FaultPercentage.Should().Be(percentage);
|
||||
}
|
||||
_mappingMock = new Mock<IMapping>();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(FaultType.EMPTY_RESPONSE)]
|
||||
[InlineData(FaultType.MALFORMED_RESPONSE_CHUNK)]
|
||||
public async Task Response_ProvideResponse_WithFault(FaultType faultType)
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/fault"), "GET", ClientIp);
|
||||
|
||||
// Act
|
||||
var responseBuilder = Response.Create().WithFault(faultType);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Message.FaultType.Should().Be(faultType);
|
||||
response.Message.FaultPercentage.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(FaultType.EMPTY_RESPONSE, 0.5)]
|
||||
public async Task Response_ProvideResponse_WithFault_IncludingPercentage(FaultType faultType, double percentage)
|
||||
{
|
||||
// Arrange
|
||||
var request = new RequestMessage(new UrlDetails("http://localhost/fault"), "GET", ClientIp);
|
||||
|
||||
// Act
|
||||
var responseBuilder = Response.Create().WithFault(faultType, percentage);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Message.FaultType.Should().Be(faultType);
|
||||
response.Message.FaultPercentage.Should().Be(percentage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user