xunit web server collection
This commit is contained in:
parent
282b0277ae
commit
3695c17429
38 changed files with 1033 additions and 140 deletions
60
test/isnd.tests/WebServerFixture.cs
Normal file
60
test/isnd.tests/WebServerFixture.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace isnd.tests
|
||||
{
|
||||
|
||||
[CollectionDefinition("Web server collection")]
|
||||
|
||||
|
||||
public class WebServerFixture : IDisposable
|
||||
{
|
||||
public IWebHost Host { get; private set;}
|
||||
public WebServerFixture()
|
||||
{
|
||||
SetupHost();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Host.StopAsync().Wait();
|
||||
Host.Dispose();
|
||||
}
|
||||
|
||||
public void SetupHost()
|
||||
{
|
||||
var webhostBuilder = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseIISIntegration()
|
||||
.UseContentRoot("../../../../../src/isnd"
|
||||
)
|
||||
.UseStartup(typeof(Startup))
|
||||
.ConfigureAppConfiguration((builderContext, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", false);
|
||||
config.AddJsonFile("appsettings.Development.json", false);
|
||||
});
|
||||
|
||||
Host = webhostBuilder.Build();
|
||||
|
||||
Host.Start(); //Starts listening on the configured addresses.
|
||||
PrintAddresses(Host.Services);
|
||||
}
|
||||
|
||||
void PrintAddresses(IServiceProvider services)
|
||||
{
|
||||
Console.WriteLine("Checking addresses...");
|
||||
var server = services.GetRequiredService<IServer>();
|
||||
var addressFeature = server.Features.Get<IServerAddressesFeature>();
|
||||
foreach (var address in addressFeature.Addresses)
|
||||
{
|
||||
Console.WriteLine("Listing on address: " + address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue