diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj index 622970d0..0791252d 100644 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj +++ b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj @@ -3,7 +3,7 @@ Lightweight StandAlone Http Mocking Server for .Net. WireMock.Net.StandAlone - 1.0.2.10 + 1.0.2.11 Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true diff --git a/src/WireMock.Net/Server/FluentMockServer.cs b/src/WireMock.Net/Server/FluentMockServer.cs index 534ac7c8..7eaa7c3a 100644 --- a/src/WireMock.Net/Server/FluentMockServer.cs +++ b/src/WireMock.Net/Server/FluentMockServer.cs @@ -363,18 +363,18 @@ namespace WireMock.Server return new RespondWithAProvider(RegisterMapping, requestMatcher); } - /// - /// The register mapping. - /// - /// - /// The mapping. - /// private void RegisterMapping(Mapping mapping) { - // Check a mapping exists with the same GUID, if so, remove it first. - DeleteMapping(mapping.Guid); - - _options.Mappings.Add(mapping); + // Check a mapping exists with the same Guid, if so, replace it. + var existingMapping = _options.Mappings.FirstOrDefault(m => m.Guid == mapping.Guid); + if (existingMapping != null) + { + _options.Mappings[_options.Mappings.IndexOf(existingMapping)] = mapping; + } + else + { + _options.Mappings.Add(mapping); + } } } } \ No newline at end of file diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index 8ce020b0..9be9752f 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -3,7 +3,7 @@ Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape. WireMock.Net - 1.0.2.10 + 1.0.2.11 Alexandre Victoor;Stef Heyenrath net452;net46;netstandard1.3;netstandard2.0 true diff --git a/test/WireMock.Net.Tests/FluentMockServerTests.cs b/test/WireMock.Net.Tests/FluentMockServerTests.cs index deb1f6c7..db45d7af 100644 --- a/test/WireMock.Net.Tests/FluentMockServerTests.cs +++ b/test/WireMock.Net.Tests/FluentMockServerTests.cs @@ -117,20 +117,24 @@ namespace WireMock.Net.Tests var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05"); _server = FluentMockServer.Start(); - _server.Given(Request.Create().WithPath("/1").UsingGet()) + var response1 = Response.Create().WithStatusCode(500); + _server.Given(Request.Create().UsingGet()) .WithGuid(guid) - .RespondWith(Response.Create().WithStatusCode(500)); + .RespondWith(response1); - var mappings = _server.Mappings.ToArray(); - Check.That(mappings).HasSize(1); - Check.That(mappings.First().Guid).Equals(guid); + var mappings1 = _server.Mappings.ToArray(); + Check.That(mappings1).HasSize(1); + Check.That(mappings1.First().Guid).Equals(guid); + var response2 = Response.Create().WithStatusCode(400); _server.Given(Request.Create().WithPath("/2").UsingGet()) .WithGuid(guid) - .RespondWith(Response.Create().WithStatusCode(500)); + .RespondWith(response2); - Check.That(mappings).HasSize(1); - Check.That(mappings.First().Guid).Equals(guid); + var mappings2 = _server.Mappings.ToArray(); + Check.That(mappings2).HasSize(1); + Check.That(mappings2.First().Guid).Equals(guid); + Check.That(mappings2.First().Provider).Equals(response2); } [Fact]