No release yet
This commit is contained in:
115
test/isnd.tests/UnitTestWebHost.cs
Normal file
115
test/isnd.tests/UnitTestWebHost.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System.Threading;
|
||||
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;
|
||||
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>
|
||||
{
|
||||
const string apiindex = "/v3/index";
|
||||
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 myDependency = services.GetRequiredService<ApplicationDbContext>();
|
||||
myDependency.Database.Migrate();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
void TestDropUser()
|
||||
{
|
||||
|
||||
using (var serviceScope = server.Host.Services.CreateScope())
|
||||
{
|
||||
var services = serviceScope.ServiceProvider;
|
||||
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()
|
||||
{
|
||||
using (var serviceScope = server.Host.Services.CreateScope())
|
||||
{ var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value;
|
||||
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex;
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
||||
[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 + apiindex;
|
||||
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/registration"));
|
||||
}
|
||||
}
|
||||
|
||||
[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 + apiindex;
|
||||
var prov = new RegistrationResourceV3Provider();
|
||||
var source = new PackageSource(pkgSourceUrl);
|
||||
var repo = new SourceRepository(source, new INuGetResourceProvider[]{ prov });
|
||||
prov.TryCreate(repo, CancellationToken.None);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Task<HttpHandlerResource> PkgSourceMessageHandler()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
11
test/isnd.tests/WebServerCollection.cs
Normal file
11
test/isnd.tests/WebServerCollection.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Xunit;
|
||||
|
||||
namespace isnd.tests
|
||||
{
|
||||
public class WebServerCollection : ICollectionFixture<WebServerFixture>
|
||||
{
|
||||
// This class has no code, and is never created. Its purpose is simply
|
||||
// to be the place to apply [CollectionDefinition] and all the
|
||||
// ICollectionFixture<> interfaces.
|
||||
}
|
||||
}
|
64
test/isnd.tests/WebServerFixture.cs
Normal file
64
test/isnd.tests/WebServerFixture.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace isnd.tests
|
||||
{
|
||||
|
||||
[CollectionDefinition("Web server collection")]
|
||||
|
||||
|
||||
public class WebServerFixture : IDisposable
|
||||
{
|
||||
public IWebHost Host { get; private set;}
|
||||
public List<string> Addresses { get; private set; } = new List<string>();
|
||||
|
||||
public WebServerFixture()
|
||||
{
|
||||
SetupHost();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Host.StopAsync().Wait();
|
||||
Host.Dispose();
|
||||
}
|
||||
|
||||
public void SetupHost()
|
||||
{
|
||||
var webhostBuilder = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseIISIntegration()
|
||||
// .UseContentRoot("../../../../../src/isnd")
|
||||
.UseStartup(typeof(Startup))
|
||||
.ConfigureAppConfiguration((builderContext, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", false);
|
||||
config.AddJsonFile("appsettings.Development.json", false);
|
||||
});
|
||||
|
||||
Host = webhostBuilder.Build();
|
||||
|
||||
Host.Start(); //Starts listening on the configured addresses.
|
||||
PrintAddresses(Host.Services);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
test/isnd.tests/appsettings.json
Normal file
21
test/isnd.tests/appsettings.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"Isn": {
|
||||
"ExternalUrl": "http://localhost:5000",
|
||||
"PackagesRootDir" : "packages",
|
||||
"ProtectionTitle": "protected-data-v1",
|
||||
"MaxUserKeyCount": 5
|
||||
},
|
||||
"Smtp": {
|
||||
"Server": "localhost",
|
||||
"Port": 25,
|
||||
"SenderName": "Paul Schneider",
|
||||
"SenderEmail": "paul@pschneider.fr"
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://localhost:5005"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
test/isnd.tests/isnd.tests.csproj
Normal file
24
test/isnd.tests/isnd.tests.csproj
Normal file
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<UserSecretsId>d7144e46-4e63-4391-ba86-64b61f6e7be4</UserSecretsId>
|
||||
<NoWarn>NETSDK1138</NoWarn>
|
||||
<AssemblyVersion>1.0.7.0</AssemblyVersion>
|
||||
<FileVersion>1.0.7.0</FileVersion>
|
||||
<InformationalVersion>1.0.7+Branch.main.Sha.3695c1742965d93eba0ad851656cfaa3e44ba327</InformationalVersion>
|
||||
<Version>1.0.7</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.70" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.runner.reporters" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\isnd\isnd.csproj" />
|
||||
<ProjectReference Include="..\..\src\isn\isn.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
0
test/isnd.tests/wwwroot/favicon.ico
Normal file
0
test/isnd.tests/wwwroot/favicon.ico
Normal file
Reference in New Issue
Block a user