StatusCode not built correctly when loaded from mapping file. #238

Closed
opened 2025-12-29 15:18:56 +01:00 by adam · 2 comments
Owner

Originally created by @FrostyZoob on GitHub (Jan 9, 2020).

Scenario:
Using WireMock.Net v1.1.0.0

All requests that match the attached mapping (Returns500Response.txt) get a response whose StatusCode is 200.

Expectation:
The response should have the StatusCode that is specified in the mapping file. (500)

Analysis:
The problem appears to be here: (WireMockServer.Admin.cs, line 811)

switch (responseModel.StatusCode)
{
    case int statusCodeAsInteger:
        responseBuilder = responseBuilder.WithStatusCode(statusCodeAsInteger);
        break;

    case string statusCodeAsString:
        responseBuilder = responseBuilder.WithStatusCode(statusCodeAsString);
        break;
}

When stepping through the code, responseModel.StatusCode is 500. (Which is correct.) However, according to the debugger it has been deserialized as a long. Because of that, it skips over the switch statement entirely and responseBuilder.ResponseMessage.StatusCode ends up being set to 200.

Originally created by @FrostyZoob on GitHub (Jan 9, 2020). **Scenario:** Using WireMock.Net v1.1.0.0 All requests that match the attached mapping ([Returns500Response.txt](https://github.com/WireMock-Net/WireMock.Net/files/4041996/Returns500Response.txt)) get a response whose StatusCode is 200. **Expectation:** The response should have the StatusCode that is specified in the mapping file. (500) **Analysis:** The problem appears to be here: (WireMockServer.Admin.cs, line 811) ``` switch (responseModel.StatusCode) { case int statusCodeAsInteger: responseBuilder = responseBuilder.WithStatusCode(statusCodeAsInteger); break; case string statusCodeAsString: responseBuilder = responseBuilder.WithStatusCode(statusCodeAsString); break; } ``` When stepping through the code, `responseModel.StatusCode` is 500. (Which is correct.) However, according to the debugger it has been deserialized as a _long_. Because of that, it skips over the switch statement entirely and responseBuilder.ResponseMessage.StatusCode ends up being set to 200.
adam added the bug label 2025-12-29 15:18:56 +01:00
adam closed this issue 2025-12-29 15:18:56 +01:00
Author
Owner

@StefH commented on GitHub (Jan 9, 2020):

Thanks a lot for finding this issue!

@StefH commented on GitHub (Jan 9, 2020): Thanks a lot for finding this issue!
Author
Owner

@StefH commented on GitHub (Jan 9, 2020):

PR was already created, merged to master.

@StefH commented on GitHub (Jan 9, 2020): PR was already created, merged to master.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#238