No release yet
This commit is contained in:
10
test/data/test-isn/ANuGet.Config
Normal file
10
test/data/test-isn/ANuGet.Config
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<apikeys>
|
||||
</apikeys>
|
||||
<packageSources>
|
||||
<add key="dev" value="http://localhost:5000/index.json" protocolVersion="3" />
|
||||
<!-- <add key="isn-prod" value="https://isn.pschneider.fr/index.json" protocolVersion="3" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> -->
|
||||
</packageSources>
|
||||
</configuration>
|
2
test/data/test-isn/Program.cs
Normal file
2
test/data/test-isn/Program.cs
Normal file
@ -0,0 +1,2 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
13
test/data/test-isn/test-isn.csproj
Normal file
13
test/data/test-isn/test-isn.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>test_isn</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<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>
|
||||
</Project>
|
5
test/data/test-isn/test.sh
Executable file
5
test/data/test-isn/test.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
nuget locals all -clear && dotnet nuget locals all --clear && \
|
||||
nuget install -NoCache -Verbosity detailed -ConfigFile ANuGet.Config Yavsc.Abstract
|
||||
|
1
test/data/test-isn/testcmd
Normal file
1
test/data/test-isn/testcmd
Normal file
@ -0,0 +1 @@
|
||||
nuget install -NoCache -Verbosity detailed -ConfigFile ANuGet.Config Yavsc.Abstract
|
65
test/isn.tests/PushTest.cs
Normal file
65
test/isn.tests/PushTest.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Net.Http;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using isn.Abstract;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using isn.abst;
|
||||
using isnd.Entities;
|
||||
|
||||
namespace isn.tests
|
||||
{
|
||||
public class Tests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void HaveADefaultDataProtector()
|
||||
{
|
||||
string pass = "a lame and big pass";
|
||||
isn.IDataProtector _protector = new isn.DefaultDataProtector();
|
||||
string protectedpass = _protector.Protect(pass);
|
||||
string unprotectedpass = _protector.UnProtect(protectedpass);
|
||||
Console.WriteLine(protectedpass);
|
||||
Assert.Equal(pass, unprotectedpass);
|
||||
Assert.True(protectedpass != null);
|
||||
Assert.True(protectedpass.Length > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestHttpClient()
|
||||
{
|
||||
string url = "https://isn.pschneider.fr/v3/index.json" ;
|
||||
HttpClient client = new HttpClient();
|
||||
// var json = await client.GetStringAsync(new System.Uri(url));
|
||||
var response = await client.GetAsync(url);
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var vm = JsonConvert.DeserializeObject<ApiIndexViewModel>(json);
|
||||
Console.WriteLine(JsonConvert.SerializeObject(vm));
|
||||
Assert.NotNull(vm);
|
||||
Assert.NotNull(vm.Resources);
|
||||
}
|
||||
[Fact]
|
||||
public void TestPush()
|
||||
{
|
||||
Program.LoadConfig();
|
||||
var report = Program.PushPkg(new string[] { "./src/isn.abst/bin/Debug/isn.abst.1.0.1.nupkg"
|
||||
+ Constants.PaquetFileEstension });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetServerResourcesUsingHttpClientAsyncTest()
|
||||
{
|
||||
var model = SourceHelpers.GetServerResources("Https://isn.pschneider.fr/index.json");
|
||||
Console.WriteLine(JsonConvert.SerializeObject(model));
|
||||
Assert.NotNull(model.Resources);
|
||||
var pub = model.Resources.FirstOrDefault((r) => r.Type.StartsWith("PackagePublish/"));
|
||||
Assert.True(pub != null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
23
test/isn.tests/isn.tests.csproj
Normal file
23
test/isn.tests/isn.tests.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0</TargetFrameworks>
|
||||
<IsPackable>false</IsPackable>
|
||||
<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="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" />
|
||||
<PackageToolReference Include="xunit.runner.console" Version="2.4.2" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\isn\isn.csproj" />
|
||||
<ProjectReference Include="..\..\src\isn.abst\isn.abst.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
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