isn/test/isnd.tests/UnitTestWebHost.cs

73 lines
2.4 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.Options;
using System.Diagnostics;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.Configuration;
using isnd.tests;
namespace isnd.host.tests
{
[Collection("Web server collection")]
public class UnitTestWebHost : IClassFixture<WebServerFixture>
{
WebServerFixture server;
public UnitTestWebHost(WebServerFixture server)
{
this.server = server;
}
[Fact]
public void TestHaveTestDbContextAndMigrate()
{
using (var serviceScope = server.Host.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var isnSettings = services.GetRequiredService<IOptions<isn.Settings>>().Value;
var myDependency = services.GetRequiredService<ApplicationDbContext>();
myDependency.Database.Migrate();
}
}
[Fact]
void TestDropUser()
{
using (var serviceScope = server.Host.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var isnSettings = services.GetRequiredService<IOptions<isn.Settings>>().Value;
var dbContext = services.GetRequiredService<ApplicationDbContext>();
var paul = dbContext.Users.FirstOrDefaultAsync(u => u.Email == "paul@pschneider.fr").Result;
if (paul!=null)
{
dbContext.Users.Remove(paul);
dbContext.SaveChanges();
}
}
}
[Fact]
public void 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!");
}
}
}