From 1c88f5d97de5e086dd809af127dcb3868692be77 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 9 Jul 2020 21:37:39 +0200 Subject: [PATCH] fix (#487) --- .../Serialization/MappingConverter.cs | 2 +- .../WireMockAdminApiTests.cs | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs index 0dc735a2..90cbf966 100644 --- a/src/WireMock.Net/Serialization/MappingConverter.cs +++ b/src/WireMock.Net/Serialization/MappingConverter.cs @@ -87,7 +87,7 @@ namespace WireMock.Serialization } }; - if (methodMatcher?.Methods != null && methodMatcher.Methods.All(m => m != "get") && bodyMatcher?.Matchers != null) + if (bodyMatcher?.Matchers != null) { mappingModel.Request.Body = new BodyModel(); diff --git a/test/WireMock.Net.Tests/WireMockAdminApiTests.cs b/test/WireMock.Net.Tests/WireMockAdminApiTests.cs index 8653b913..99a18d19 100644 --- a/test/WireMock.Net.Tests/WireMockAdminApiTests.cs +++ b/test/WireMock.Net.Tests/WireMockAdminApiTests.cs @@ -4,6 +4,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; +using FluentAssertions; using Moq; using NFluent; using RestEase; @@ -95,7 +96,7 @@ namespace WireMock.Net.Tests [InlineData(0, 0)] [InlineData(200, 200)] [InlineData("200", "200")] - public async Task IWireMockAdminApi_PostMappingAsync(object statusCode, object expectedStatusCode) + public async Task IWireMockAdminApi_PostMappingAsync_WithStatusCode(object statusCode, object expectedStatusCode) { // Arrange var server = WireMockServer.StartWithAdminInterface(); @@ -241,6 +242,49 @@ namespace WireMock.Net.Tests Check.That(requestLogged.Request.Body).Contains("T000001"); } + [Fact] + public async Task IWireMockAdminApi_GetMappingAsync_WithBodyModelMatcherModel_WithoutMethods_ShouldReturnCorrectMappingModel() + { + // Arrange + var guid = Guid.NewGuid(); + var server = WireMockServer.StartWithAdminInterface(); + var api = RestClient.For(server.Urls[0]); + + // Act + var model = new MappingModel + { + Guid = guid, + Request = new RequestModel + { + Path = "/1", + Body = new BodyModel + { + Matcher = new MatcherModel + { + Name = "RegexMatcher", + Pattern = "hello", + IgnoreCase = true + } + } + }, + Response = new ResponseModel { Body = "world" } + }; + var postMappingResult = await api.PostMappingAsync(model); + + // Assert + postMappingResult.Should().NotBeNull(); + + var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid); + mapping.Should().NotBeNull(); + + var getMappingResult = await api.GetMappingAsync(guid); + getMappingResult.Should().NotBeNull(); + + getMappingResult.Request.Body.Should().BeEquivalentTo(model.Request.Body); + + server.Stop(); + } + [Fact] public async Task IWireMockAdminApi_GetRequestsAsync_Json() {