Fixed issue with same Mapping Guid (#73)

This commit is contained in:
Stef Heyenrath
2017-12-20 20:51:51 +01:00
parent d0fc889f42
commit 71196b51c9
4 changed files with 24 additions and 20 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description> <Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle> <AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Version>1.0.2.10</Version> <Version>1.0.2.11</Version>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -363,18 +363,18 @@ namespace WireMock.Server
return new RespondWithAProvider(RegisterMapping, requestMatcher); return new RespondWithAProvider(RegisterMapping, requestMatcher);
} }
/// <summary>
/// The register mapping.
/// </summary>
/// <param name="mapping">
/// The mapping.
/// </param>
private void RegisterMapping(Mapping mapping) private void RegisterMapping(Mapping mapping)
{ {
// Check a mapping exists with the same GUID, if so, remove it first. // Check a mapping exists with the same Guid, if so, replace it.
DeleteMapping(mapping.Guid); var existingMapping = _options.Mappings.FirstOrDefault(m => m.Guid == mapping.Guid);
if (existingMapping != null)
_options.Mappings.Add(mapping); {
_options.Mappings[_options.Mappings.IndexOf(existingMapping)] = mapping;
}
else
{
_options.Mappings.Add(mapping);
}
} }
} }
} }

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description> <Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle> <AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.2.10</Version> <Version>1.0.2.11</Version>
<Authors>Alexandre Victoor;Stef Heyenrath</Authors> <Authors>Alexandre Victoor;Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -117,20 +117,24 @@ namespace WireMock.Net.Tests
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05"); var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
_server = FluentMockServer.Start(); _server = FluentMockServer.Start();
_server.Given(Request.Create().WithPath("/1").UsingGet()) var response1 = Response.Create().WithStatusCode(500);
_server.Given(Request.Create().UsingGet())
.WithGuid(guid) .WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(500)); .RespondWith(response1);
var mappings = _server.Mappings.ToArray(); var mappings1 = _server.Mappings.ToArray();
Check.That(mappings).HasSize(1); Check.That(mappings1).HasSize(1);
Check.That(mappings.First().Guid).Equals(guid); Check.That(mappings1.First().Guid).Equals(guid);
var response2 = Response.Create().WithStatusCode(400);
_server.Given(Request.Create().WithPath("/2").UsingGet()) _server.Given(Request.Create().WithPath("/2").UsingGet())
.WithGuid(guid) .WithGuid(guid)
.RespondWith(Response.Create().WithStatusCode(500)); .RespondWith(response2);
Check.That(mappings).HasSize(1); var mappings2 = _server.Mappings.ToArray();
Check.That(mappings.First().Guid).Equals(guid); Check.That(mappings2).HasSize(1);
Check.That(mappings2.First().Guid).Equals(guid);
Check.That(mappings2.First().Provider).Equals(response2);
} }
[Fact] [Fact]