mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 06:13:35 +01:00
Compare commits
1 Commits
1.2.15
...
CommandLin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43177d45c3 |
32
src/WireMock.Net.StandAlone/CommandLineArguments.cs
Normal file
32
src/WireMock.Net.StandAlone/CommandLineArguments.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using CommandLineParser.Arguments;
|
||||||
|
|
||||||
|
namespace WireMock.Net.StandAlone
|
||||||
|
{
|
||||||
|
public class CommandLineArguments
|
||||||
|
{
|
||||||
|
[ValueArgument(typeof(bool), "StartAdminInterface", DefaultValue = true, Description = "Start the AdminInterface")]
|
||||||
|
public bool StartAdminInterface { get; set; }
|
||||||
|
|
||||||
|
[ValueArgument(typeof(bool), "ReadStaticMappings", DefaultValue = false, Description = "Read StaticMappings")]
|
||||||
|
public bool ReadStaticMappings { get; set; }
|
||||||
|
|
||||||
|
[ValueArgument(typeof(bool), 'w', "WatchStaticMappings", DefaultValue = false, Description = "Watch the static mapping files + folder for changes when running.")]
|
||||||
|
public bool WatchStaticMappings { get; set; }
|
||||||
|
|
||||||
|
[ValueArgument(typeof(bool), 'm', "AllowPartialMapping", DefaultValue = false, Description = "Allow PartialMapping")]
|
||||||
|
public bool AllowPartialMapping { get; set; }
|
||||||
|
|
||||||
|
[ValueArgument(typeof(string), 'u', "AdminUsername", Description = "The username needed for __admin access.")]
|
||||||
|
public string AdminUsername { get; set; }
|
||||||
|
|
||||||
|
[ValueArgument(typeof(string), 'p', "AdminPassword", Description = "The password needed for __admin access.")]
|
||||||
|
public string AdminPassword { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[BoundedValueArgument(typeof(int), 'o', "MaxRequestLogCount", MinValue = 0, Description = "The Maximum number of RequestLogs to keep")]
|
||||||
|
public int MaxRequestLogCount { get; set; }
|
||||||
|
|
||||||
|
[BoundedValueArgument(typeof(int), 'x', "RequestLogExpirationDuration", MinValue = 0, Description = "The RequestLog Expiration Duration in hours")]
|
||||||
|
public int RequestLogExpirationDuration { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,8 +38,9 @@ namespace WireMock.Net.StandAlone
|
|||||||
{
|
{
|
||||||
Check.NotNull(args, nameof(args));
|
Check.NotNull(args, nameof(args));
|
||||||
|
|
||||||
var parser = new SimpleCommandLineParser();
|
var parser = new CommandLineParser.CommandLineParser();
|
||||||
parser.Parse(args);
|
var p = new CommandLineArguments();
|
||||||
|
parser.ExtractArgumentAttributes(p);
|
||||||
|
|
||||||
var settings = new FluentMockServerSettings
|
var settings = new FluentMockServerSettings
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,6 +41,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Remove="SimpleCommandLineParser.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.19" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1">
|
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1">
|
||||||
<PrivateAssets>All</PrivateAssets>
|
<PrivateAssets>All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -102,44 +102,49 @@ namespace WireMock.Serialization
|
|||||||
mappingModel.Response.Headers = Map(response.ResponseMessage.Headers);
|
mappingModel.Response.Headers = Map(response.ResponseMessage.Headers);
|
||||||
mappingModel.Response.UseTransformer = response.UseTransformer;
|
mappingModel.Response.UseTransformer = response.UseTransformer;
|
||||||
|
|
||||||
if (response.ResponseMessage.BodyData != null)
|
MapBodyData(response, mappingModel);
|
||||||
{
|
|
||||||
switch (response.ResponseMessage.BodyData?.DetectedBodyType)
|
|
||||||
{
|
|
||||||
case BodyType.String:
|
|
||||||
mappingModel.Response.Body = response.ResponseMessage.BodyData.BodyAsString;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BodyType.Json:
|
|
||||||
mappingModel.Response.BodyAsJson = response.ResponseMessage.BodyData.BodyAsJson;
|
|
||||||
mappingModel.Response.BodyAsJsonIndented = response.ResponseMessage.BodyData.BodyAsJsonIndented;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BodyType.Bytes:
|
|
||||||
mappingModel.Response.BodyAsBytes = response.ResponseMessage.BodyData.BodyAsBytes;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BodyType.File:
|
|
||||||
mappingModel.Response.BodyAsFile = response.ResponseMessage.BodyData.BodyAsFile;
|
|
||||||
mappingModel.Response.BodyAsFileIsCached = response.ResponseMessage.BodyData.BodyAsFileIsCached;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.ResponseMessage.BodyData.Encoding != null && response.ResponseMessage.BodyData.Encoding.WebName != "utf-8")
|
|
||||||
{
|
|
||||||
mappingModel.Response.BodyEncoding = new EncodingModel
|
|
||||||
{
|
|
||||||
EncodingName = response.ResponseMessage.BodyData.Encoding.EncodingName,
|
|
||||||
CodePage = response.ResponseMessage.BodyData.Encoding.CodePage,
|
|
||||||
WebName = response.ResponseMessage.BodyData.Encoding.WebName
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mappingModel;
|
return mappingModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void MapBodyData(Response response, MappingModel mappingModel)
|
||||||
|
{
|
||||||
|
if (response.ResponseMessage.BodyData != null)
|
||||||
|
{
|
||||||
|
switch (response.ResponseMessage.BodyData?.DetectedBodyType)
|
||||||
|
{
|
||||||
|
case BodyType.String:
|
||||||
|
mappingModel.Response.Body = response.ResponseMessage.BodyData.BodyAsString;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BodyType.Json:
|
||||||
|
mappingModel.Response.BodyAsJson = response.ResponseMessage.BodyData.BodyAsJson;
|
||||||
|
mappingModel.Response.BodyAsJsonIndented = response.ResponseMessage.BodyData.BodyAsJsonIndented;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BodyType.Bytes:
|
||||||
|
mappingModel.Response.BodyAsBytes = response.ResponseMessage.BodyData.BodyAsBytes;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BodyType.File:
|
||||||
|
mappingModel.Response.BodyAsFile = response.ResponseMessage.BodyData.BodyAsFile;
|
||||||
|
mappingModel.Response.BodyAsFileIsCached = response.ResponseMessage.BodyData.BodyAsFileIsCached;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.ResponseMessage.BodyData.Encoding != null && response.ResponseMessage.BodyData.Encoding.WebName != "utf-8")
|
||||||
|
{
|
||||||
|
mappingModel.Response.BodyEncoding = new EncodingModel
|
||||||
|
{
|
||||||
|
EncodingName = response.ResponseMessage.BodyData.Encoding.EncodingName,
|
||||||
|
CodePage = response.ResponseMessage.BodyData.Encoding.CodePage,
|
||||||
|
WebName = response.ResponseMessage.BodyData.Encoding.WebName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static IDictionary<string, object> Map(IDictionary<string, WireMockList<string>> dictionary)
|
private static IDictionary<string, object> Map(IDictionary<string, WireMockList<string>> dictionary)
|
||||||
{
|
{
|
||||||
if (dictionary == null || dictionary.Count == 0)
|
if (dictionary == null || dictionary.Count == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user