mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-17 05:59:39 +02:00
Dotnet 20 preview final (#41)
* 1.0.2.3-preview2-final-01 * fixes for AspNetCoreSelfHost (Task...) * enable all target frameworks again
This commit is contained in:
@@ -45,23 +45,28 @@ namespace WireMock.Owin
|
||||
|
||||
public Task StartAsync()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.ConfigureLogging(factory => factory.AddConsole(LogLevel.None))
|
||||
IWebHost host = new WebHostBuilder()
|
||||
// .ConfigureLogging(factory => factory.AddConsole(LogLevel.None))
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
// appBuilder.UseExceptionHandler(builder => )
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
.Build();
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
return Task.Run(() =>
|
||||
{
|
||||
host.Run(_cts.Token);
|
||||
|
||||
IsStarted = true;
|
||||
}, _cts.Token);
|
||||
#else
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||
IsStarted = true;
|
||||
return host.RunAsync(_cts.Token);
|
||||
#endif
|
||||
}
|
||||
|
||||
public Task StopAsync()
|
||||
@@ -73,31 +78,5 @@ namespace WireMock.Owin
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
//var builder = new ConfigurationBuilder()
|
||||
// .SetBasePath(env.ContentRootPath)
|
||||
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
// .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
// .AddEnvironmentVariables();
|
||||
//Configuration = builder.Build();
|
||||
}
|
||||
|
||||
// public IConfigurationRoot Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
app.UseMiddleware<WireMockMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -15,7 +15,6 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private Thread _internalThread;
|
||||
|
||||
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
@@ -55,23 +54,13 @@ namespace WireMock.Owin
|
||||
{
|
||||
_cts.Cancel();
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
var timer = new System.Timers.Timer(999);
|
||||
timer.Elapsed += (sender, e) =>
|
||||
{
|
||||
if (_internalThread == null)
|
||||
{
|
||||
timer.Stop();
|
||||
tcs.SetResult(true);
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
|
||||
return tcs.Task;
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private void StartServers()
|
||||
{
|
||||
System.Console.WriteLine("WireMock.Net server using .net 4.5.x or .net 4.6.x");
|
||||
|
||||
Action<IAppBuilder> startup = app =>
|
||||
{
|
||||
app.Use<WireMockMiddleware>(_options);
|
||||
@@ -86,12 +75,16 @@ namespace WireMock.Owin
|
||||
IsStarted = true;
|
||||
|
||||
while (!_cts.IsCancellationRequested)
|
||||
Thread.Sleep(1000);
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
}
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
foreach (var server in servers)
|
||||
{
|
||||
server.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user