Compare commits

..

5 Commits

Author SHA1 Message Date
Stef Heyenrath
c96d7d31b1 1.5.44 2023-12-14 21:08:05 +01:00
Mindaugas Laganeckas
7b8e7bb684 Implement prefix for saved mapping file (#1040)
* Implement PrefixForSavedMappingFile

* Add missing new line

* Add missing new line

* Fix warning

* Fix typo

* Change from readonly to const

* Assign default value

* Use nameof()

* Change from readonly to const

* Update tests

* Update failing test

* Rename settingsMock to settings

* Create public const

* Use const from ProxyAndRecordSettings

---------

Co-authored-by: Mindaugas Laganeckas <mindaugas.laganeckas@nexigroup.com>
2023-12-14 08:28:21 +01:00
Stef Heyenrath
68ad015dcf 1.5.43 2023-12-11 17:34:39 +01:00
sameena syed
97d26338e6 Proxy all requests - even a repeated one (#1038)
* Adding proxyall

* Adding proxyAll flag

* Reverting extra spaces added

* Make proxyall to true

* Resolving review comments for proxyall

* Resolving codefactor spaces in the code

* Adding proxyall parser in wmserversettingsparser

---------

Co-authored-by: Sameena Syed <sameena.syed@nexigroup.com>
2023-12-11 17:16:30 +01:00
Stef Heyenrath
0c6129e86b Add ProxyUrlReplaceSettings to Response (#1026) 2023-12-10 09:57:37 +01:00
22 changed files with 465 additions and 69 deletions

View File

@@ -1,3 +1,14 @@
# 1.5.44 (14 December 2023)
- [#1040](https://github.com/WireMock-Net/WireMock.Net/pull/1040) - Implement prefix for saved mapping file [feature] contributed by [MindaugasLaganeckas](https://github.com/MindaugasLaganeckas)
- [#1033](https://github.com/WireMock-Net/WireMock.Net/issues/1033) - How to get a Random Long? [bug]
- [#1037](https://github.com/WireMock-Net/WireMock.Net/issues/1037) - Make mapping filenames more user friendly [feature]
# 1.5.43 (11 December 2023)
- [#1026](https://github.com/WireMock-Net/WireMock.Net/pull/1026) - Add ProxyUrlReplaceSettings to Response [feature] contributed by [StefH](https://github.com/StefH)
- [#1038](https://github.com/WireMock-Net/WireMock.Net/pull/1038) - Proxy all requests - even a repeated one [feature] contributed by [sameena-ops](https://github.com/sameena-ops)
- [#592](https://github.com/WireMock-Net/WireMock.Net/issues/592) - Proxy all requests - even a repeated one [feature]
- [#1024](https://github.com/WireMock-Net/WireMock.Net/issues/1024) - Scenario with proxy not removing route prefix [feature]
# 1.5.42 (09 December 2023)
- [#1023](https://github.com/WireMock-Net/WireMock.Net/pull/1023) - Fix Mapping[] for WireMock.Org REST API [bug] contributed by [StefH](https://github.com/StefH)
- [#1029](https://github.com/WireMock-Net/WireMock.Net/pull/1029) - Add ResponseWithHandlebarsDateTimeTests [test] contributed by [StefH](https://github.com/StefH)

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.5.42</VersionPrefix>
<VersionPrefix>1.5.44</VersionPrefix>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

View File

@@ -1,6 +1,6 @@
rem https://github.com/StefH/GitHubReleaseNotes
SET version=1.5.42
SET version=1.5.44
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%

View File

@@ -1,9 +1,6 @@
# 1.5.42 (09 December 2023)
- #1023 Fix Mapping[] for WireMock.Org REST API [bug]
- #1029 Add ResponseWithHandlebarsDateTimeTests [test]
- #1031 Calling Reset also resets the scenarios [bug]
- #1034 Workaround for: Random.Generate Type=&quot;Long&quot; [bug]
- #1021 GetAdminMappingsResult in WireMock.Org.Abstractions should contain list of mappings [bug]
- #1030 Reset resets only mappings and logentries, not scenarios. [bug]
# 1.5.44 (14 December 2023)
- #1040 Implement prefix for saved mapping file [feature]
- #1033 How to get a Random Long? [bug]
- #1037 Make mapping filenames more user friendly [feature]
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md

View File

@@ -325,6 +325,23 @@ namespace WireMock.Net.ConsoleApplication
.WithHeader("Keep-Alive-Test", "stef")
);
server
.Given(Request.Create()
.UsingGet()
.WithPath("/proxy-replace")
)
.RespondWith(Response.Create()
.WithProxy(new ProxyAndRecordSettings
{
Url = "http://localhost:9999",
ReplaceSettings = new ProxyUrlReplaceSettings
{
OldValue = "old",
NewValue = "new"
}
})
);
server
.Given(Request.Create()
.WithPath("/xpath").UsingPost()

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using WireMock.Admin.Settings;
namespace WireMock.Admin.Mappings;
@@ -103,6 +104,11 @@ public class ResponseModel
/// </summary>
public string? ProxyUrl { get; set; }
/// <summary>
/// Defines the Proxy Url Replace Settings.
/// </summary>
public ProxyUrlReplaceSettingsModel? ProxyUrlReplaceSettings { get; set; }
/// <summary>
/// The client X509Certificate2 Thumbprint or SubjectName to use.
/// </summary>

View File

@@ -70,7 +70,17 @@ public class ProxyAndRecordSettingsModel
public bool AppendGuidToSavedMappingFile { get; set; }
/// <summary>
/// Defines the Replace Settings
/// Set prefix for saved mapping file.
/// </summary>
public string PrefixForSavedMappingFile { get; set; }
/// <summary>
/// Defines the Replace Settings.
/// </summary>
public ProxyUrlReplaceSettingsModel? ReplaceSettings { get; set; }
/// <summary>
/// Proxy all Api calls, irrespective of any condition
/// </summary>
public bool ProxyAll { get; set; } = false;
}

View File

@@ -1,24 +1,23 @@
namespace WireMock.Admin.Settings
namespace WireMock.Admin.Settings;
/// <summary>
/// WebProxySettings
/// </summary>
[FluentBuilder.AutoGenerateBuilder]
public class WebProxySettingsModel
{
/// <summary>
/// WebProxySettings
/// A string instance that contains the address of the proxy server.
/// </summary>
[FluentBuilder.AutoGenerateBuilder]
public class WebProxySettingsModel
{
/// <summary>
/// A string instance that contains the address of the proxy server.
/// </summary>
public string Address { get; set; }
public string Address { get; set; } = null!;
/// <summary>
/// The user name associated with the credentials.
/// </summary>
public string? UserName { get; set; }
/// <summary>
/// The user name associated with the credentials.
/// </summary>
public string? UserName { get; set; }
/// <summary>
/// The password for the user name associated with the credentials.
/// </summary>
public string? Password { get; set; }
}
/// <summary>
/// The password for the user name associated with the credentials.
/// </summary>
public string? Password { get; set; }
}

View File

@@ -77,4 +77,6 @@ internal interface IWireMockMiddlewareOptions
bool? DoNotSaveDynamicResponseInLogEntry { get; set; }
QueryParameterMultipleValueSupport? QueryParameterMultipleValueSupport { get; set; }
public bool ProxyAll { get; set; }
}

View File

@@ -95,4 +95,7 @@ internal class WireMockMiddlewareOptions : IWireMockMiddlewareOptions
/// <inheritdoc />
public QueryParameterMultipleValueSupport? QueryParameterMultipleValueSupport { get; set; }
/// <inheritdoc />
public bool ProxyAll { get; set; }
}

View File

@@ -373,9 +373,11 @@ internal class MappingConverter
mappingModel.Response.UseTransformerForBodyAsFile = null;
mappingModel.Response.TransformerReplaceNodeOptions = null;
mappingModel.Response.BodyEncoding = null;
mappingModel.Response.ProxyUrl = response.ProxyAndRecordSettings.Url;
mappingModel.Response.Fault = null;
mappingModel.Response.WebProxy = MapWebProxy(response.ProxyAndRecordSettings.WebProxySettings);
mappingModel.Response.WebProxy = TinyMapperUtils.Instance.Map(response.ProxyAndRecordSettings.WebProxySettings);
mappingModel.Response.ProxyUrl = response.ProxyAndRecordSettings.Url;
mappingModel.Response.ProxyUrlReplaceSettings = TinyMapperUtils.Instance.Map(response.ProxyAndRecordSettings.ReplaceSettings);
}
else
{
@@ -509,16 +511,6 @@ internal class MappingConverter
return values is { } ? string.Join(", ", values.Select(ToCSharpStringLiteral)) : ToCSharpStringLiteral(defaultValue);
}
private static WebProxyModel? MapWebProxy(WebProxySettings? settings)
{
return settings != null ? new WebProxyModel
{
Address = settings.Address,
UserName = settings.UserName,
Password = settings.Password
} : null;
}
private static IDictionary<string, object> MapHeaders(IDictionary<string, WireMockList<string>> dictionary)
{
var newDictionary = new Dictionary<string, object>();

View File

@@ -0,0 +1,48 @@
using System.IO;
using System.Linq;
using Stef.Validation;
using WireMock.Settings;
namespace WireMock.Serialization;
/// <summary>
/// Creates sanitized file names for mappings
/// </summary>
public class MappingFileNameSanitizer
{
private const char ReplaceChar = '_';
private readonly WireMockServerSettings _settings;
public MappingFileNameSanitizer(WireMockServerSettings settings)
{
_settings = Guard.NotNull(settings);
}
/// <summary>
/// Creates sanitized file names for mappings
/// </summary>
public string BuildSanitizedFileName(IMapping mapping)
{
string name;
if (!string.IsNullOrEmpty(mapping.Title))
{
// remove 'Proxy Mapping for ' and an extra space character after the HTTP request method
name = mapping.Title.Replace(ProxyAndRecordSettings.DefaultPrefixForSavedMappingFile, "").Replace(' '.ToString(), string.Empty);
if (_settings.ProxyAndRecordSettings?.AppendGuidToSavedMappingFile == true)
{
name += $"{ReplaceChar}{mapping.Guid}";
}
}
else
{
name = mapping.Guid.ToString();
}
if (!string.IsNullOrEmpty(_settings.ProxyAndRecordSettings?.PrefixForSavedMappingFile))
{
name = $"{_settings.ProxyAndRecordSettings.PrefixForSavedMappingFile}{ReplaceChar}{name}";
}
return $"{Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, ReplaceChar))}.json";
}
}

View File

@@ -10,11 +10,13 @@ internal class MappingToFileSaver
{
private readonly WireMockServerSettings _settings;
private readonly MappingConverter _mappingConverter;
private readonly MappingFileNameSanitizer _fileNameSanitizer;
public MappingToFileSaver(WireMockServerSettings settings, MappingConverter mappingConverter)
{
_settings = Guard.NotNull(settings);
_mappingConverter = Guard.NotNull(mappingConverter);
_fileNameSanitizer = new MappingFileNameSanitizer(settings);
}
public void SaveMappingsToFile(IMapping[] mappings, string? folder = null)
@@ -42,7 +44,7 @@ internal class MappingToFileSaver
var model = _mappingConverter.ToMappingModel(mapping);
var filename = BuildSanitizedFileName(mapping);
var filename = _fileNameSanitizer.BuildSanitizedFileName(mapping);
var path = Path.Combine(folder, filename);
Save(model, path);
@@ -54,23 +56,4 @@ internal class MappingToFileSaver
_settings.FileSystemHandler.WriteMappingFile(path, JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsDefault));
}
private string BuildSanitizedFileName(IMapping mapping, char replaceChar = '_')
{
string name;
if (!string.IsNullOrEmpty(mapping.Title))
{
name = mapping.Title!;
if (_settings.ProxyAndRecordSettings?.AppendGuidToSavedMappingFile == true)
{
name += $"{replaceChar}{mapping.Guid}";
}
}
else
{
name = mapping.Guid.ToString();
}
return $"{Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, replaceChar))}.json";
}
}

View File

@@ -280,12 +280,8 @@ public partial class WireMockServer
{
Url = responseModel.ProxyUrl!,
ClientX509Certificate2ThumbprintOrSubjectName = responseModel.X509Certificate2ThumbprintOrSubjectName,
WebProxySettings = responseModel.WebProxy != null ? new WebProxySettings
{
Address = responseModel.WebProxy.Address,
UserName = responseModel.WebProxy.UserName,
Password = responseModel.WebProxy.Password
} : null
WebProxySettings = TinyMapperUtils.Instance.Map(responseModel.WebProxy),
ReplaceSettings = TinyMapperUtils.Instance.Map(responseModel.ProxyUrlReplaceSettings)
};
return responseBuilder.WithProxy(proxyAndRecordSettings);

View File

@@ -31,6 +31,11 @@ public partial class WireMockServer
proxyRespondProvider.AtPriority(WireMockConstants.ProxyPriority);
}
if(settings.ProxyAndRecordSettings.ProxyAll)
{
proxyRespondProvider.AtPriority(int.MinValue);
}
proxyRespondProvider.RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
}

View File

@@ -7,6 +7,11 @@ namespace WireMock.Settings;
/// </summary>
public class ProxyAndRecordSettings : HttpClientSettings
{
/// <summary>
/// Default prefix value for saved mapping file
/// </summary>
public const string DefaultPrefixForSavedMappingFile = "Proxy Mapping for ";
/// <summary>
/// The URL to proxy.
/// </summary>
@@ -94,4 +99,15 @@ public class ProxyAndRecordSettings : HttpClientSettings
/// Append an unique GUID to the filename from the saved mapping file.
/// </summary>
public bool AppendGuidToSavedMappingFile { get; set; }
}
/// <summary>
/// Set prefix for saved mapping file.
/// </summary>
public string PrefixForSavedMappingFile { get; set; } = DefaultPrefixForSavedMappingFile;
/// <summary>
/// Proxy all Api calls, irrespective of any condition
/// </summary>
[PublicAPI]
public bool ProxyAll { get; set; } = false;
}

View File

@@ -120,12 +120,14 @@ public static class WireMockServerSettingsParser
SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"),
UseDefinedRequestMatchers = parser.GetBoolValue(nameof(ProxyAndRecordSettings.UseDefinedRequestMatchers)),
AppendGuidToSavedMappingFile = parser.GetBoolValue(nameof(ProxyAndRecordSettings.AppendGuidToSavedMappingFile)),
PrefixForSavedMappingFile = parser.GetStringValue(nameof(ProxyAndRecordSettings.PrefixForSavedMappingFile), null),
Url = proxyUrl!,
SaveMappingSettings = new ProxySaveMappingSettings
{
StatusCodePattern = parser.GetStringValue("SaveMappingForStatusCodePattern", "*"),
// HttpMethods = new ProxySaveMappingSetting<string[]>(parser.GetValues("DoNotSaveMappingForHttpMethods", new string[0]), MatchBehaviour.RejectOnMatch)
}
},
ProxyAll = parser.GetBoolValue(nameof(ProxyAndRecordSettings.ProxyAll))
};
ParseWebProxyAddressSettings(proxyAndRecordSettings, parser);

View File

@@ -1,4 +1,5 @@
using Nelibur.ObjectMapper;
using WireMock.Admin.Mappings;
using WireMock.Admin.Settings;
using WireMock.Settings;
@@ -12,10 +13,12 @@ internal sealed class TinyMapperUtils
{
TinyMapper.Bind<ProxyAndRecordSettings, ProxyAndRecordSettingsModel>();
TinyMapper.Bind<WebProxySettings, WebProxySettingsModel>();
TinyMapper.Bind<WebProxySettings, WebProxyModel>();
TinyMapper.Bind<ProxyUrlReplaceSettings, ProxyUrlReplaceSettingsModel>();
TinyMapper.Bind<ProxyAndRecordSettingsModel, ProxyAndRecordSettings>();
TinyMapper.Bind<WebProxySettingsModel, WebProxySettings>();
TinyMapper.Bind<WebProxyModel, WebProxySettings>();
TinyMapper.Bind<ProxyUrlReplaceSettingsModel, ProxyUrlReplaceSettings>();
}
@@ -28,4 +31,24 @@ internal sealed class TinyMapperUtils
{
return model == null ? null : TinyMapper.Map<ProxyAndRecordSettings>(model);
}
public ProxyUrlReplaceSettingsModel? Map(ProxyUrlReplaceSettings? instance)
{
return instance == null ? null : TinyMapper.Map<ProxyUrlReplaceSettingsModel>(instance);
}
public ProxyUrlReplaceSettings? Map(ProxyUrlReplaceSettingsModel? model)
{
return model == null ? null : TinyMapper.Map<ProxyUrlReplaceSettings>(model);
}
public WebProxyModel? Map(WebProxySettings? instance)
{
return instance == null ? null : TinyMapper.Map<WebProxyModel>(instance);
}
public WebProxySettings? Map(WebProxyModel? model)
{
return model == null ? null : TinyMapper.Map<WebProxySettings>(model);
}
}

View File

@@ -0,0 +1,160 @@
using System;
using Moq;
using WireMock.Serialization;
using WireMock.Settings;
using Xunit;
namespace WireMock.Net.Tests.Serialization;
public class MappingFileNameSanitizerTests
{
private const string MappingGuid = "ce216a13-e7d6-42d7-91ac-8ae709e2add1";
private const string MappingTitle = "Proxy Mapping for POST _ordermanagement_v1_orders_cancel";
[Fact]
public void BuildSanitizedFileName_WithTitleAndGuid_AppendsGuid()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns(MappingTitle);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
AppendGuidToSavedMappingFile = true
}
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal($"Proxy Mapping for _POST_ordermanagement_v1_orders_cancel_{MappingGuid}.json", result);
}
[Fact]
public void BuildSanitizedFileName_WithoutTitle_UsesGuid()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns((string?)null);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ()
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal($"Proxy Mapping for _{MappingGuid}.json", result);
}
[Fact]
public void BuildSanitizedFileName_WithTitleAndGuid_NoAppendGuidSetting()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns(MappingTitle);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
AppendGuidToSavedMappingFile = false
}
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal("Proxy Mapping for _POST_ordermanagement_v1_orders_cancel.json", result);
}
[Fact]
public void BuildSanitizedFileName_WithPrefix_AddsPrefix()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns(MappingTitle);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
PrefixForSavedMappingFile = "Prefix"
}
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal($"Prefix_POST_ordermanagement_v1_orders_cancel.json", result);
}
[Fact]
public void BuildSanitizedFileName_WithPrefix_AddsPrefixEmptyString()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns(MappingTitle);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
PrefixForSavedMappingFile = string.Empty
}
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal($"POST_ordermanagement_v1_orders_cancel.json", result);
}
[Fact]
public void BuildSanitizedFileName_WithTitleAndGuid_WithPrefixAndAppendGuidSetting()
{
// Arrange
var mappingMock = new Mock<IMapping>();
mappingMock.Setup(m => m.Title).Returns(MappingTitle);
mappingMock.Setup(m => m.Guid).Returns(new Guid(MappingGuid));
var settings = new WireMockServerSettings
{
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
PrefixForSavedMappingFile = "Prefix",
AppendGuidToSavedMappingFile = true
}
};
var sanitizer = new MappingFileNameSanitizer(settings);
// Act
var result = sanitizer.BuildSanitizedFileName(mappingMock.Object);
// Assert
Assert.Equal($"Prefix_POST_ordermanagement_v1_orders_cancel_{MappingGuid}.json", result);
}
}

View File

@@ -0,0 +1,30 @@
{
Guid: 90356dba-b36c-469a-a17e-669cd84f1f05,
UpdatedAt: DateTime_1,
Request: {
Path: {
Matchers: [
{
Name: WildcardMatcher,
Pattern: /1,
IgnoreCase: false
}
]
},
Body: {
Matcher: {
Name: RegexMatcher,
Pattern: hello,
IgnoreCase: true
}
}
},
Response: {
ProxyUrl: https://my-proxy.com,
ProxyUrlReplaceSettings: {
OldValue: x,
NewValue: y,
IgnoreCase: true
}
}
}

View File

@@ -351,6 +351,57 @@ public class WireMockAdminApiTests
server.Stop();
}
[Fact]
public async Task IWireMockAdminApi_GetMappingAsync_WithProxy_And_ProxyUrlReplaceSettings()
{
// Arrange
var guid = Guid.Parse("90356dba-b36c-469a-a17e-669cd84f1f05");
var server = WireMockServer.StartWithAdminInterface();
var api = RestClient.For<IWireMockAdminApi>(server.Url);
// 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
{
ProxyUrl = "https://my-proxy.com",
ProxyUrlReplaceSettings = new ProxyUrlReplaceSettingsModel
{
OldValue = "x",
NewValue = "y",
IgnoreCase = true
}
}
};
var postMappingResult = await api.PostMappingAsync(model).ConfigureAwait(false);
// Assert
postMappingResult.Should().NotBeNull();
var mapping = server.Mappings.FirstOrDefault(m => m.Guid == guid);
mapping.Should().NotBeNull();
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
server.Stop();
}
[Fact]
public async Task IWireMockAdminApi_GetRequestsAsync_Json()
{

View File

@@ -174,7 +174,7 @@ public class WireMockServerProxyTests
server.Mappings.Should().HaveCount(2);
// Verify
fileSystemHandlerMock.Verify(f => f.WriteMappingFile($"m{System.IO.Path.DirectorySeparatorChar}{title}.json", It.IsRegex(stringBody)), Times.Once);
fileSystemHandlerMock.Verify(f => f.WriteMappingFile($"m{System.IO.Path.DirectorySeparatorChar}Proxy Mapping for _{title}.json", It.IsRegex(stringBody)), Times.Once);
}
[Fact]
@@ -922,4 +922,49 @@ public class WireMockServerProxyTests
server.LogEntries.Should().HaveCount(1);
server.Stop();
}
[Fact]
public async Task WireMockServer_ProxyAndRecordSettings_SameRequest_ShouldProxyAll()
{
//Arrange
var wireMockServerSettings = new WireMockServerSettings
{
Urls = new[] { "http://localhost:9091" },
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = "http://postman-echo.com",
SaveMapping = true,
ProxyAll = true,
SaveMappingToFile = false,
ExcludedHeaders = new[] { "Postman-Token" },
ExcludedCookies = new[] { "sails.sid" }
}
};
var server = WireMockServer.Start(wireMockServerSettings);
var requestBody = "{\"key1\": \"value1\", \"key2\": \"value2\"}";
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("http://localhost:9091/post"),
Content = new StringContent(requestBody)
};
var request2 = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("http://localhost:9091/post"),
Content = new StringContent(requestBody)
};
server.ResetMappings();
//Act
await new HttpClient().SendAsync(request);
await new HttpClient().SendAsync(request2);
//Assert
Check.That(server.Mappings.Count()).IsEqualTo(3);
server.Dispose();
}
}