This commit is contained in:
Paul Schneider 2023-02-06 21:43:18 +00:00
commit 4f040be236
18 changed files with 144 additions and 99 deletions

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<NoWarn>NETSDK1138</NoWarn>
<AssemblyVersion>1.0.7.0</AssemblyVersion>
@ -18,6 +18,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\isn\isn.csproj" />
<ProjectReference Include="..\..\src\isn.abstract\isn.abstract.csproj" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>

View file

@ -11,9 +11,13 @@ using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.Extensions.Configuration;
using isnd.tests;
using NuGet.Protocol;
using NuGet.Configuration;
using System.Threading.Tasks;
using NuGet.Protocol.Core.Types;
namespace isnd.host.tests
{
{
[Collection("Web server collection")]
public class UnitTestWebHost : IClassFixture<WebServerFixture>
{
@ -29,7 +33,6 @@ namespace isnd.host.tests
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();
}
@ -42,8 +45,6 @@ namespace isnd.host.tests
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)
@ -56,18 +57,41 @@ namespace isnd.host.tests
[Fact]
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("http://localhost:5000");
psi.ArgumentList.Add(pkgSourceUrl);
Process p = Process.Start(psi);
p.WaitForExit();
Assert.True(p.ExitCode == 0, "nuget install failed!");
}
}
[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"));
}
}
private Task<HttpHandlerResource> PkgSourceMessageHandler()
{
throw new NotImplementedException();
}
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
@ -15,6 +16,8 @@ namespace isnd.tests
public class WebServerFixture : IDisposable
{
public IWebHost Host { get; private set;}
public List<string> Addresses { get; private set; } = new List<string>();
public WebServerFixture()
{
SetupHost();
@ -31,8 +34,7 @@ namespace isnd.tests
var webhostBuilder = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
.UseContentRoot("../../../../../src/isnd"
)
// .UseContentRoot("../../../../../src/isnd")
.UseStartup(typeof(Startup))
.ConfigureAppConfiguration((builderContext, config) =>
{
@ -48,12 +50,14 @@ namespace isnd.tests
void PrintAddresses(IServiceProvider services)
{
Addresses.Clear();
Console.WriteLine("Checking addresses...");
var server = services.GetRequiredService<IServer>();
var addressFeature = server.Features.Get<IServerAddressesFeature>();
foreach (var address in addressFeature.Addresses)
{
Console.WriteLine("Listing on address: " + address);
Addresses.Add(address);
}
}
}

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<UserSecretsId>d7144e46-4e63-4391-ba86-64b61f6e7be4</UserSecretsId>
<NoWarn>NETSDK1138</NoWarn>
@ -17,7 +17,6 @@
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.reporters" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\isnd\isnd.csproj" />