|
|
|
using System;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.AspNetCore;
|
|
|
|
using Xunit;
|
|
|
|
using isnd.Data;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Microsoft.AspNetCore.Hosting.Server;
|
|
|
|
using Microsoft.AspNetCore.Hosting.Server.Features;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace isnd.host.tests
|
|
|
|
{
|
|
|
|
public class UnitTestWebHost
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void TestHaveTestDbContextAndMigrate()
|
|
|
|
{
|
|
|
|
string envVar = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
|
|
|
|
|
|
|
IWebHost webhost = BuildWebHost(new string[0]);
|
|
|
|
|
|
|
|
using (var serviceScope = webhost.Services.CreateScope())
|
|
|
|
{
|
|
|
|
var services = serviceScope.ServiceProvider;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var isnSettings = services.GetRequiredService<IOptions<isn.Settings>>().Value;
|
|
|
|
var myDependency = services.GetRequiredService<ApplicationDbContext>();
|
|
|
|
myDependency.Database.Migrate();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
throw new Exception("Failed " + envVar, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static IWebHost BuildWebHost(string[] args) =>
|
|
|
|
WebHost.CreateDefaultBuilder(args)
|
|
|
|
.UseStartup<Startup>().Build();
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public async Task NugetInstallsTest()
|
|
|
|
{
|
|
|
|
ProcessStartInfo psi = new ProcessStartInfo("nuget");
|
|
|
|
psi.ArgumentList.Add("install");
|
|
|
|
psi.ArgumentList.Add("gitversion");
|
|
|
|
psi.ArgumentList.Add("-PreRelease");
|
|
|
|
psi.ArgumentList.Add("-Source");
|
|
|
|
psi.ArgumentList.Add("http://localhost:5000");
|
|
|
|
Process p = Process.Start(psi);
|
|
|
|
p.WaitForExit();
|
|
|
|
Assert.True(p.ExitCode == 0, "nuget install failed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|