isn/test/isnd.tests/UnitTestWebHost.cs

113 lines
4.2 KiB
C#
Raw Normal View History

2023-03-14 00:15:42 +00:00
using System.Threading;
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;
2023-02-06 21:43:18 +00:00
using NuGet.Protocol;
using NuGet.Configuration;
using System.Threading.Tasks;
using NuGet.Protocol.Core.Types;
2021-09-08 01:55:00 +01:00
2021-08-13 18:55:25 +01:00
namespace isnd.host.tests
2023-02-06 21:43:18 +00: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 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 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]
2023-01-29 13:04:50 +00:00
public void NugetInstallsTest()
2022-04-09 19:53:26 +01:00
{
2023-02-06 21:43:18 +00:00
using (var serviceScope = server.Host.Services.CreateScope())
{ var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
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");
2023-02-06 21:43:18 +00:00
psi.ArgumentList.Add(pkgSourceUrl);
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!");
2023-02-06 21:43:18 +00:00
}
}
[Fact]
public void TestRegistrationV3Resource()
{
using (var serviceScope = server.Host.Services.CreateScope())
{ var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
NullThrottle throttle = new NullThrottle();
PackageSource packageSource = new PackageSource(pkgSourceUrl);
HttpSource client = new HttpSource(packageSource, PkgSourceMessageHandler, throttle);
NuGet.Protocol.RegistrationResourceV3 res = new NuGet.Protocol.RegistrationResourceV3(client ,
new Uri(isnSettings.ExternalUrl + "/v3.4.0//registration"));
}
}
2023-03-14 00:15:42 +00:00
[Fact]
public void TrueTestRegistrationV3Resource()
{
using (var serviceScope = server.Host.Services.CreateScope())
{
var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
var prov = new RegistrationResourceV3Provider();
var source = new PackageSource(pkgSourceUrl);
var repo = new SourceRepository(source, new INuGetResourceProvider[]{ prov });
prov.TryCreate(repo, CancellationToken.None);
}
}
2023-02-06 21:43:18 +00:00
private Task<HttpHandlerResource> PkgSourceMessageHandler()
{
throw new NotImplementedException();
2022-04-09 19:53:26 +01:00
}
2021-05-09 13:45:55 +01:00
}
}