unit testing
This commit is contained in:
@ -15,6 +15,7 @@ using NuGet.Protocol.Core.Types;
|
||||
using isn.abst;
|
||||
using NuGet.Common;
|
||||
using System.Collections.Generic;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace isnd.host.tests
|
||||
{
|
||||
@ -58,7 +59,6 @@ namespace isnd.host.tests
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void NugetInstallsTest()
|
||||
{
|
||||
using (var serviceScope = server.Host.Services.CreateScope())
|
||||
@ -83,7 +83,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 + apiindex;
|
||||
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex+ ".json";
|
||||
NullThrottle throttle = new NullThrottle();
|
||||
|
||||
PackageSource packageSource = new PackageSource(pkgSourceUrl);
|
||||
@ -99,7 +99,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 + apiindex;
|
||||
string pkgSourceUrl = isnSettings.ExternalUrl + apiindex+ ".json";
|
||||
var prov = new RegistrationResourceV3Provider();
|
||||
var source = new PackageSource(pkgSourceUrl);
|
||||
var repo = new SourceRepository(source, new INuGetResourceProvider[] { prov });
|
||||
@ -137,7 +137,7 @@ namespace isnd.host.tests
|
||||
|
||||
Assert.NotEmpty(packages);
|
||||
|
||||
foreach (IPackageSearchMetadata package in packages)
|
||||
foreach (var package in packages)
|
||||
{
|
||||
Console.WriteLine($"Version: {package.Identity.Version}");
|
||||
Console.WriteLine($"Listed: {package.IsListed}");
|
||||
@ -173,6 +173,7 @@ namespace isnd.host.tests
|
||||
[Fact]
|
||||
public async Task TestPackagePush()
|
||||
{
|
||||
server.EnsureUser(server.TestingUserName);
|
||||
var logger = new TestLogger();
|
||||
SourceRepository repository = Repository.Factory.GetCoreV3(SPIIndexURI);
|
||||
PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>();
|
||||
@ -183,13 +184,16 @@ namespace isnd.host.tests
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDepedency()
|
||||
// not yet from testing url a [Fact]
|
||||
public async Task TestGetPackageUri()
|
||||
{
|
||||
PackageDependencyGroup g = new PackageDependencyGroup
|
||||
{
|
||||
TargetFramework="net7.0"
|
||||
};
|
||||
PackageSource source = new PackageSource("https://isn.pschneider.fr/v3/index.json");
|
||||
source.ProtocolVersion=3;
|
||||
SourceRepository repository = Repository.Factory.GetCoreV3(source);
|
||||
string index = repository.ToJson();
|
||||
PackageDetailsUriResourceV3 uriRes = await repository.GetResourceAsync<PackageDetailsUriResourceV3>();
|
||||
Assert.NotNull(uriRes);// package details Uri Resource
|
||||
Uri u = uriRes.GetUri("isn.abst", new NuGetVersion("1.0.24"));
|
||||
}
|
||||
|
||||
private string GetSymbolsApiKey(string apiUrl)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using isn;
|
||||
using isnd.Data;
|
||||
using isnd.Entities;
|
||||
@ -31,6 +32,10 @@ namespace isnd.tests
|
||||
private IsndSettings siteSettings;
|
||||
|
||||
public IDataProtector DataProtector { get; private set; }
|
||||
|
||||
public ApplicationDbContext dbContext { get; private set; }
|
||||
|
||||
public string TestingUserName { get; private set; }
|
||||
public string ProtectedTestingApiKey { get; internal set; }
|
||||
public ApplicationUser TestingUser { get; private set; }
|
||||
|
||||
@ -49,19 +54,19 @@ namespace isnd.tests
|
||||
{
|
||||
var builder = WebHost.CreateDefaultBuilder(new string[0]);
|
||||
|
||||
// .UseContentRoot("../../../../../src/isnd")
|
||||
builder.UseStartup(typeof(Startup))
|
||||
.ConfigureAppConfiguration((builderContext, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", true);
|
||||
config.AddJsonFile("appsettings.Development.json", false);
|
||||
});
|
||||
// .UseContentRoot("../../../../../src/isnd")
|
||||
builder.UseStartup(typeof(Startup))
|
||||
.ConfigureAppConfiguration((builderContext, config) =>
|
||||
{
|
||||
config.AddJsonFile("appsettings.json", true);
|
||||
config.AddJsonFile("appsettings.Development.json", false);
|
||||
});
|
||||
|
||||
Host = builder.Build();
|
||||
|
||||
var logFactory = Host.Services.GetRequiredService<ILoggerFactory>();
|
||||
Logger = logFactory.CreateLogger<WebServerFixture>();
|
||||
|
||||
|
||||
Host.Start(); //Starts listening on the configured addresses.
|
||||
var server = Host.Services.GetRequiredService<IServer>();
|
||||
|
||||
@ -76,38 +81,47 @@ namespace isnd.tests
|
||||
DataProtector = Host.Services.GetRequiredService<IDataProtectionProvider>()
|
||||
.CreateProtector(siteSettings.ProtectionTitle);
|
||||
|
||||
var dbContext = Host.Services.GetRequiredService<ApplicationDbContext>();
|
||||
string testingUserName = "Tester";
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u=>u.UserName==testingUserName);
|
||||
if (TestingUser==null)
|
||||
{
|
||||
var userManager = Host.Services.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
TestingUser = new ApplicationUser
|
||||
{
|
||||
UserName=testingUserName
|
||||
};
|
||||
|
||||
var result = userManager.CreateAsync(TestingUser).Result;
|
||||
|
||||
Assert.True(result.Succeeded);
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u=>u.UserName==testingUserName);
|
||||
}
|
||||
var testKey = dbContext.ApiKeys.FirstOrDefault(k=>k.UserId==TestingUser.Id);
|
||||
dbContext = Host.Services.GetRequiredService<ApplicationDbContext>();
|
||||
TestingUserName = "Tester";
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
|
||||
EnsureUser(TestingUserName);
|
||||
var testKey = dbContext.ApiKeys.FirstOrDefault(k => k.UserId == TestingUser.Id);
|
||||
if (testKey == null)
|
||||
{
|
||||
var keyProvider = Host.Services.GetService<IApiKeyProvider>();
|
||||
var apiKeyQuery = new Data.ApiKeys.CreateModel
|
||||
{
|
||||
Name = "Testing Key",
|
||||
UserId = TestingUser.Id,
|
||||
ValidityPeriodInDays = 1
|
||||
{
|
||||
Name = "Testing Key",
|
||||
UserId = TestingUser.Id,
|
||||
ValidityPeriodInDays = 1
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result;
|
||||
|
||||
}
|
||||
ProtectedTestingApiKey = DataProtector.Protect(testKey.Id);
|
||||
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
(sender, cert, chain, sslPolicyErrors) => true;
|
||||
|
||||
}
|
||||
|
||||
public void EnsureUser(string testingUserName)
|
||||
{
|
||||
if (TestingUser == null)
|
||||
{
|
||||
var userManager = Host.Services.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
TestingUser = new ApplicationUser
|
||||
{
|
||||
UserName = testingUserName
|
||||
};
|
||||
|
||||
var result = userManager.CreateAsync(TestingUser).Result;
|
||||
|
||||
Assert.True(result.Succeeded);
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == testingUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,9 +13,6 @@
|
||||
},
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Url": "http://127.0.0.1:5002"
|
||||
},
|
||||
"Https": {
|
||||
"Url": "https://127.0.0.1:5003"
|
||||
}
|
||||
|
@ -10,12 +10,12 @@
|
||||
<Version>1.0.7</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="3.1.20" />
|
||||
<PackageReference Include="xunit" Version="2.7.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="XunitXml.TestLogger" Version="4.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.runner.reporters" Version="2.7.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
|
||||
<PackageReference Include="xunit.runner.reporters" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
<PackageToolReference Include="xunit.runner.console" Version="2.4.2" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
20
test/isnd.tests/test-index.json
Normal file
20
test/isnd.tests/test-index.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"FeedTypeOverride": "undefined",
|
||||
"PackageSource": {
|
||||
"Name": "http://127.0.0.1:5000/v3/index.json",
|
||||
"Source": "http://127.0.0.1:5000/v3/index.json",
|
||||
"TrySourceAsUri": "http://127.0.0.1:5000/v3/index.json",
|
||||
"SourceUri": "http://127.0.0.1:5000/v3/index.json",
|
||||
"IsOfficial": false,
|
||||
"IsMachineWide": false,
|
||||
"IsEnabled": true,
|
||||
"IsPersistable": true,
|
||||
"MaxHttpRequestsPerSource": 0,
|
||||
"ProtocolVersion": 2,
|
||||
"AllowInsecureConnections": false,
|
||||
"DisableTLSCertificateValidation": false,
|
||||
"IsHttp": true,
|
||||
"IsHttps": false,
|
||||
"IsLocal": false
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user