mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-25 10:31:01 +01:00
Create WireMock.Net.MimePart project (#1300)
* Create WireMock.Net.MimePart project * . * REFACTOR * ILRepack * -- * ... * x * x * . * fix * public class MimePartMatcher * shared * min * . * <!--<DelaySign>true</DelaySign>--> * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user