Files
WireMock.Net/test/WireMock.Net.Tests/WireMockServerTests.WithCallback.cs
Stef Heyenrath 54edf0bebc Add link to TIOBE Index on main page + fix issues (#1137)
* Add TIOBE + include SonarAnalyzer.CSharp

* .

* cp

* Copyright © WireMock.Net

* more fixes

* fix

* xpath

* if (Matchers == null || !Matchers.Any())

* if (Matchers != null)

* ?

* .

* .
2024-07-18 18:06:04 +02:00

41 lines
1.1 KiB
C#

// Copyright © WireMock.Net
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests
{
public partial class WireMockServerTests
{
[Theory]
[InlineData(HttpStatusCode.Conflict)]
[InlineData(409)]
[InlineData("409")]
public async Task WireMockServer_WithCallback_Should_Use_StatusCodeFromResponse(object statusCode)
{
// Arrange
var server = WireMockServer.Start();
server.Given(Request.Create().UsingPost().WithPath("/foo"))
.RespondWith(Response.Create()
.WithCallback(request => new ResponseMessage
{
StatusCode = statusCode
}));
// Act
var httpClient = new HttpClient();
var response = await httpClient.PostAsync("http://localhost:" + server.Ports[0] + "/foo", new StringContent("dummy")).ConfigureAwait(false);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
server.Stop();
}
}
}