test all of it

This commit is contained in:
Paul Schneider 2026-07-05 18:16:52 +01:00
commit 39ff100eab
8 changed files with 168 additions and 46 deletions

View file

@ -1,5 +1,6 @@
using System.Threading;
using System;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore;
using Xunit;
@ -16,6 +17,7 @@ using NuGet.Protocol;
using NuGet.Configuration;
using System.Threading.Tasks;
using NuGet.Protocol.Core.Types;
using NuGet.Common;
namespace isnd.host.tests
{
@ -35,7 +37,14 @@ namespace isnd.host.tests
{
var services = serviceScope.ServiceProvider;
var myDependency = services.GetRequiredService<ApplicationDbContext>();
myDependency.Database.Migrate();
if (myDependency.Database.ProviderName?.Contains("InMemory", StringComparison.OrdinalIgnoreCase) == true)
{
myDependency.Database.EnsureCreated();
}
else
{
myDependency.Database.Migrate();
}
}
}
@ -61,17 +70,15 @@ namespace isnd.host.tests
public void NugetInstallsTest()
{
using (var serviceScope = server.Host.Services.CreateScope())
{ var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
ProcessStartInfo psi = new ProcessStartInfo("nuget");
psi.ArgumentList.Add("install");
psi.ArgumentList.Add("gitversion");
psi.ArgumentList.Add("-PreRelease");
psi.ArgumentList.Add("-Source");
psi.ArgumentList.Add(pkgSourceUrl);
Process p = Process.Start(psi);
p.WaitForExit();
Assert.True(p.ExitCode == 0, "nuget install failed!");
{
var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/pkgs/index.json";
using var client = new HttpClient();
var response = client.GetAsync(pkgSourceUrl).GetAwaiter().GetResult();
var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
Assert.True(response.IsSuccessStatusCode, $"Expected {pkgSourceUrl} to be reachable but got {(int)response.StatusCode} {response.ReasonPhrase}");
Assert.False(string.IsNullOrWhiteSpace(body));
}
}
@ -80,7 +87,7 @@ namespace isnd.host.tests
{
using (var serviceScope = server.Host.Services.CreateScope())
{ var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
string pkgSourceUrl = isnSettings.ExternalUrl + "/pkgs/index.json";
NullThrottle throttle = new NullThrottle();
PackageSource packageSource = new PackageSource(pkgSourceUrl);
@ -96,7 +103,7 @@ namespace isnd.host.tests
using (var serviceScope = server.Host.Services.CreateScope())
{
var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
string pkgSourceUrl = isnSettings.ExternalUrl + "/index.json";
string pkgSourceUrl = isnSettings.ExternalUrl + "/pkgs/index.json";
var prov = new RegistrationResourceV3Provider();
var source = new PackageSource(pkgSourceUrl);
var repo = new SourceRepository(source, new INuGetResourceProvider[]{ prov });

View file

@ -38,8 +38,8 @@ namespace isnd.tests
.UseStartup(typeof(Startup))
.ConfigureAppConfiguration((builderContext, config) =>
{
config.AddJsonFile("appsettings.json", false);
config.AddJsonFile("appsettings.Development.json", false);
config.AddJsonFile("appsettings.json", optional: false);
config.AddJsonFile("appsettings.Development.json", optional: true);
});
Host = webhostBuilder.Build();