isn/test/isnd.tests/UnitTestWebHost.cs

73 lines
2.4 KiB
C#
Raw Normal View History

2021-05-09 13:45:55 +01:00
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore;
using Xunit;
2021-08-15 19:09:01 +01:00
using isnd.Data;
2021-05-11 20:52:39 +01:00
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
2021-09-08 01:55:00 +01:00
using Microsoft.Extensions.Options;
2022-05-25 09:07:36 +01:00
using System.Diagnostics;
2022-06-16 17:03:38 +01:00
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
2023-01-29 13:04:50 +00:00
using Microsoft.Extensions.Configuration;
using isnd.tests;
2021-09-08 01:55:00 +01:00
2021-08-13 18:55:25 +01:00
namespace isnd.host.tests
2021-05-09 13:45:55 +01:00
{
2023-01-29 13:04:50 +00:00
[Collection("Web server collection")]
public class UnitTestWebHost : IClassFixture<WebServerFixture>
2021-05-09 13:45:55 +01:00
{
2023-01-29 13:04:50 +00:00
WebServerFixture server;
public UnitTestWebHost(WebServerFixture server)
{
this.server = server;
}
[Fact]
2021-07-05 21:24:37 +01:00
public void TestHaveTestDbContextAndMigrate()
2021-05-09 13:45:55 +01:00
{
2023-01-29 13:04:50 +00:00
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();
}
}
2021-05-11 20:52:39 +01:00
2023-01-29 13:04:50 +00:00
[Fact]
void TestDropUser()
{
using (var serviceScope = server.Host.Services.CreateScope())
2021-05-11 20:52:39 +01:00
{
var services = serviceScope.ServiceProvider;
2023-01-29 13:04:50 +00:00
var isnSettings = services.GetRequiredService<IOptions<isn.Settings>>().Value;
var dbContext = services.GetRequiredService<ApplicationDbContext>();
2023-02-06 00:41:35 +00:00
var paul = dbContext.Users.FirstOrDefaultAsync(u => u.Email == "paul@pschneider.fr").Result;
2023-01-29 13:04:50 +00:00
if (paul!=null)
2023-02-06 00:41:35 +00:00
{
2023-01-29 13:04:50 +00:00
dbContext.Users.Remove(paul);
2023-02-06 00:41:35 +00:00
dbContext.SaveChanges();
}
2021-05-11 20:52:39 +01:00
}
2021-05-09 13:45:55 +01:00
}
2022-06-16 17:03:38 +01:00
2021-05-11 20:52:39 +01:00
2022-05-25 09:07:36 +01:00
[Fact]
2022-04-09 19:53:26 +01:00
2023-01-29 13:04:50 +00:00
public void NugetInstallsTest()
2022-04-09 19:53:26 +01:00
{
2022-05-25 09:07:36 +01:00
ProcessStartInfo psi = new ProcessStartInfo("nuget");
psi.ArgumentList.Add("install");
2022-06-16 17:03:38 +01:00
psi.ArgumentList.Add("gitversion");
psi.ArgumentList.Add("-PreRelease");
psi.ArgumentList.Add("-Source");
psi.ArgumentList.Add("http://localhost:5000");
2022-05-25 09:07:36 +01:00
Process p = Process.Start(psi);
p.WaitForExit();
2022-06-16 17:03:38 +01:00
Assert.True(p.ExitCode == 0, "nuget install failed!");
2022-04-09 19:53:26 +01:00
}
2021-05-09 13:45:55 +01:00
}
}