ProxySettings : Add logic to not save some requests depending on HttpMethods (#900)

* Add ExcludedHttpMethods to ProxySettings

* tst

* fix

* SaveMappingSettings

* .
This commit is contained in:
Stef Heyenrath
2023-03-09 15:28:52 +01:00
committed by GitHub
parent 61cdc13fae
commit 674fa89c3e
9 changed files with 140 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using VerifyTests;
using VerifyXunit;
@@ -70,7 +71,7 @@ public class ProxyMappingConverterTests
var responseMessage = new ResponseMessage();
// Act
var proxyMapping = _sut.ToMapping(mappingMock.Object, proxyAndRecordSettings, requestMessageMock.Object, responseMessage);
var proxyMapping = _sut.ToMapping(mappingMock.Object, proxyAndRecordSettings, requestMessageMock.Object, responseMessage)!;
// Assert
var model = _mappingConverter.ToMappingModel(proxyMapping);

View File

@@ -248,6 +248,45 @@ public class WireMockServerProxyTests
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Fact]
public async Task WireMockServer_Proxy_With_DoNotSaveMappingForHttpMethod_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,
SaveMappingSettings = new ProxySaveMappingSettings
{
HttpMethods = new ProxySaveMappingSetting<string[]>(new string[] { "GET" }, MatchBehaviour.RejectOnMatch) // To 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).ConfigureAwait(false);
// Assert
server.Mappings.Should().HaveCount(1);
// Verify
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
[Fact]
public async Task WireMockServer_Proxy_Should_log_proxied_requests()
{