Create dotnet-wiremock tool (#542)

* dotnet tool

* .

* c

* x

* ### As a dotnet tool

* help

* v
This commit is contained in:
Stef Heyenrath
2020-11-25 14:36:01 +00:00
committed by GitHub
parent 4fb455a1b1
commit 45713eb0d9
16 changed files with 343 additions and 127 deletions

View File

@@ -0,0 +1,58 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using WireMock.Net.StandAlone;
using WireMock.Server;
namespace WireMock
{
public class Program
{
private static int SleepTime = 30000;
private static readonly ILogger Logger = LoggerFactory.Create(o =>
{
o.SetMinimumLevel(LogLevel.Debug);
o.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
options.SingleLine = false;
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss ";
});
}).CreateLogger(string.Empty);
private static WireMockServer Server;
static async Task Main(string[] args)
{
if (!StandAloneApp.TryStart(args, out Server, new WireMockLogger(Logger)))
{
return;
}
Logger.LogInformation("Press Ctrl+C to shut down");
Console.CancelKeyPress += (s, e) =>
{
Stop("CancelKeyPress");
};
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
{
Stop("AssemblyLoadContext.Default.Unloading");
};
while (true)
{
Logger.LogInformation("WireMock.Net server running : {IsStarted}", Server.IsStarted);
await Task.Delay(SleepTime);
}
}
private static void Stop(string why)
{
Logger.LogInformation("WireMock.Net server stopping because '{why}'", why);
Server.Stop();
Logger.LogInformation("WireMock.Net server stopped");
}
}
}