63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
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;
|
|
|
|
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()
|
|
{
|
|
IWebHost webhost = BuildWebHost(new string[0]);
|
|
Task running = Task.Run(async () => await webhost.StartAsync());
|
|
ProcessStartInfo psi = new ProcessStartInfo("nuget");
|
|
psi.ArgumentList.Add("install");
|
|
psi.ArgumentList.Add("isn");
|
|
Process p = Process.Start(psi);
|
|
p.WaitForExit();
|
|
await webhost.StopAsync();
|
|
}
|
|
|
|
}
|
|
}
|