diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs index af76ba36..7b55033c 100644 --- a/src/WireMock.Net/Serialization/MappingConverter.cs +++ b/src/WireMock.Net/Serialization/MappingConverter.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; +using System.Net; using System.Text; using System.Threading; +using Newtonsoft.Json; using Stef.Validation; using WireMock.Admin.Mappings; using WireMock.Constants; @@ -125,9 +126,13 @@ internal class MappingConverter // Response sb.AppendLine(" .RespondWith(Response.Create()"); - if (response.ResponseMessage.StatusCode is { } statusCode) + if (response.ResponseMessage.StatusCode is int or string) { - sb.AppendLine($" .WithStatusCode({statusCode})"); + sb.AppendLine($" .WithStatusCode({JsonConvert.SerializeObject(response.ResponseMessage.StatusCode)})"); + } + else if (response.ResponseMessage.StatusCode is HttpStatusCode httpStatusCode) + { + sb.AppendLine($" .WithStatusCode({(int)httpStatusCode})"); } if (response.ResponseMessage.Headers is { }) diff --git a/test/WireMock.Net.Tests/WireMockAdminApiTests.IWireMockAdminApi_GetMappingsCode.verified.txt b/test/WireMock.Net.Tests/WireMockAdminApiTests.IWireMockAdminApi_GetMappingsCode.verified.txt index 46248e81..1f3fa24b 100644 --- a/test/WireMock.Net.Tests/WireMockAdminApiTests.IWireMockAdminApi_GetMappingsCode.verified.txt +++ b/test/WireMock.Net.Tests/WireMockAdminApiTests.IWireMockAdminApi_GetMappingsCode.verified.txt @@ -13,14 +13,24 @@ server server .Given(Request.Create() - .UsingMethod("GET") + .UsingMethod("POST") .WithPath("/foo2") .WithParam("p2", "abc") ) .WithGuid("1b731398-4a5b-457f-a6e3-d65e541c428f") .RespondWith(Response.Create() - .WithStatusCode(201) + .WithStatusCode("201") .WithHeader("hk", "hv") .WithBody("2") ); +server + .Given(Request.Create() + .UsingMethod("DELETE") + .WithUrl("https://localhost/test") + ) + .WithGuid("f74fd144-df53-404f-8e35-da22a640bd5f") + .RespondWith(Response.Create() + .WithStatusCode(208) + ); + diff --git a/test/WireMock.Net.Tests/WireMockAdminApiTests.cs b/test/WireMock.Net.Tests/WireMockAdminApiTests.cs index 8d794a4b..f923648a 100644 --- a/test/WireMock.Net.Tests/WireMockAdminApiTests.cs +++ b/test/WireMock.Net.Tests/WireMockAdminApiTests.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Linq; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; @@ -717,6 +718,7 @@ public class WireMockAdminApiTests // Arrange var guid1 = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05"); var guid2 = Guid.Parse("1b731398-4a5b-457f-a6e3-d65e541c428f"); + var guid3 = Guid.Parse("f74fd144-df53-404f-8e35-da22a640bd5f"); var server = WireMockServer.StartWithAdminInterface(); server @@ -738,21 +740,34 @@ public class WireMockAdminApiTests Request.Create() .WithPath("/foo2") .WithParam("p2", "abc") - .UsingGet() + .UsingPost() ) .WithGuid(guid2) .RespondWith( Response.Create() - .WithStatusCode(201) + .WithStatusCode("201") .WithHeader("hk", "hv") .WithBody("2") ); + server + .Given( + Request.Create() + .WithUrl("https://localhost/test") + .UsingDelete() + ) + .WithGuid(guid3) + .RespondWith( + Response.Create() + .WithStatusCode(HttpStatusCode.AlreadyReported) + .WithBodyAsJson(new { x = 1 }) + ); + // Act var api = RestClient.For(server.Url); var mappings = await api.GetMappingsAsync().ConfigureAwait(false); - mappings.Should().HaveCount(2); + mappings.Should().HaveCount(3); var code = await api.GetMappingsCodeAsync().ConfigureAwait(false);