mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-07-08 05:45:17 +02:00
Do not save Mappings when SaveMappingForStatusCodePattern does not match (#566)
This commit is contained in:
@@ -261,14 +261,17 @@ namespace WireMock.Server
|
|||||||
proxyUriWithRequestPathAndQuery.AbsoluteUri
|
proxyUriWithRequestPathAndQuery.AbsoluteUri
|
||||||
);
|
);
|
||||||
|
|
||||||
if (settings.ProxyAndRecordSettings.SaveMapping)
|
if (mapping != null)
|
||||||
{
|
{
|
||||||
_options.Mappings.TryAdd(mapping.Guid, mapping);
|
if (settings.ProxyAndRecordSettings.SaveMapping)
|
||||||
}
|
{
|
||||||
|
_options.Mappings.TryAdd(mapping.Guid, mapping);
|
||||||
|
}
|
||||||
|
|
||||||
if (settings.ProxyAndRecordSettings.SaveMappingToFile)
|
if (settings.ProxyAndRecordSettings.SaveMappingToFile)
|
||||||
{
|
{
|
||||||
_mappingToFileSaver.SaveMappingToFile(mapping);
|
_mappingToFileSaver.SaveMappingToFile(mapping);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return responseMessage;
|
return responseMessage;
|
||||||
|
|||||||
@@ -116,6 +116,42 @@ namespace WireMock.Net.Tests
|
|||||||
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WireMockServer_Proxy_With_SaveMappingForStatusCodePattern_Is_False_Should_Not_SaveMapping()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||||
|
fileSystemHandlerMock.Setup(f => f.GetMappingFolder()).Returns("m");
|
||||||
|
|
||||||
|
var settings = new WireMockServerSettings
|
||||||
|
{
|
||||||
|
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||||
|
{
|
||||||
|
Url = "http://www.google.com",
|
||||||
|
SaveMapping = true,
|
||||||
|
SaveMappingToFile = true,
|
||||||
|
SaveMappingForStatusCodePattern = "999" // Just make sure that we don't want this mapping
|
||||||
|
},
|
||||||
|
FileSystemHandler = fileSystemHandlerMock.Object
|
||||||
|
};
|
||||||
|
var server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var requestMessage = new HttpRequestMessage
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Get,
|
||||||
|
RequestUri = new Uri(server.Urls[0])
|
||||||
|
};
|
||||||
|
var httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false };
|
||||||
|
await new HttpClient(httpClientHandler).SendAsync(requestMessage);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
server.Mappings.Should().HaveCount(1);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WireMockServer_Proxy_Should_log_proxied_requests()
|
public async Task WireMockServer_Proxy_Should_log_proxied_requests()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user