WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.39k stars 207 forks source link

v1.5.33 Returns always StatusCode 500 #988

Closed macalbert closed 1 year ago

macalbert commented 1 year ago

Describe the bug

Version 1.5.33 always returns StatusCode 500 ' Internal Server Error'.

Expected behaviour:

Should return the StatusCode provided in the ResponseBuilder.

Test to reproduce

using System.Net;
using System.Text;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;

public class SomeApiClientTests
{
    [Fact]
    public async Task Should_ReturnCreated_When_PostRequestedIsValid()
    {
        // Arrange        
        var server = WireMockServer.Start();
        server.Given(Request.Create().UsingPost().WithPath("/some/endpoint"))
              .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Created));
        var httpClient = new HttpClient { BaseAddress = new Uri(server.Url!) };
        var requestUri = new Uri(httpClient.BaseAddress!, "some/endpoint");
        var content = new StringContent(string.Empty, Encoding.UTF8, "application/json");

        // Act
        var actual = await httpClient.PostAsync(requestUri, content);

        // Assert
        actual.StatusCode.Should().Be(HttpStatusCode.Created);
    }
}

Other related info

Ran under .Net 7 with Microsoft Visual Studio Community 2022 (64-bit) -Version 17.6.5

StefH commented 1 year ago

Hello @macalbert. Thanks for reporting.

I will release a new version soon.

https://github.com/WireMock-Net/WireMock.Net/pull/989

macalbert commented 1 year ago

Thanks @StefH!! :smiley: