unit testing

main
Paul Schneider 1 year ago
parent 2b45e421dd
commit c615886a4c
22 changed files with 196 additions and 171 deletions

@ -1,5 +0,0 @@
mode: Mainline
branches: {}
ignore:
sha: []
merge-message-formats: {}

@ -1,4 +1,6 @@
= URL's
<http://localhost:5000/v3.4.0/registration/yavsc.abstract/index.json>
https://isn.pschneider.fr/v3/registration/isn.abst/1.0.1.json
https://api.nuget.org/v3/catalog0/data/2019.09.08.16.31.23/yavsc.abstract.1.0.6-rc06.json

@ -0,0 +1,27 @@
{
"AssemblySemFileVer": "1.1.1.0",
"AssemblySemVer": "1.1.1.0",
"BranchName": "main",
"BuildMetaData": null,
"CommitDate": "2024-10-09",
"CommitsSinceVersionSource": 19,
"EscapedBranchName": "main",
"FullBuildMetaData": "Branch.main.Sha.2b45e421dda285b73bf7eb3387915030cd751b88",
"FullSemVer": "1.1.1-19",
"InformationalVersion": "1.1.1-19+Branch.main.Sha.2b45e421dda285b73bf7eb3387915030cd751b88",
"Major": 1,
"MajorMinorPatch": "1.1.1",
"Minor": 1,
"Patch": 1,
"PreReleaseLabel": "",
"PreReleaseLabelWithDash": "",
"PreReleaseNumber": 19,
"PreReleaseTag": "19",
"PreReleaseTagWithDash": "-19",
"SemVer": "1.1.1-19",
"Sha": "2b45e421dda285b73bf7eb3387915030cd751b88",
"ShortSha": "2b45e42",
"UncommittedChanges": 20,
"VersionSourceSha": "72839e8251297935a4ab138a99152733f07a23f2",
"WeightedPreReleaseNumber": 55019
}

@ -16,6 +16,8 @@ namespace isnd.Entities
public const string Content = "/content";
public const string Nuget = "/nuget";
public const string PackageDetailUriTemplate = Package+"/{id}/{version}";
[Obsolete("use the V3 search")]
public const string V2Find = "/v2/FindPackagesById()"; // /FindPackagesById()??$filter=IsLatestVersion&$orderby=Version desc&$top=1&id='isn.abst'

@ -15,11 +15,11 @@
<InformationalVersion>1.0.7+Branch.main.Sha.3695c1742965d93eba0ad851656cfaa3e44ba327</InformationalVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
<PackageReference Include="Mono.Options" Version="5.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="unleash.client" Version="4.1.6" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0" />
<PackageReference Include="unleash.client" Version="4.1.13" />
<PackageReference Include="GitVersion.MsBuild" Version="6.0.3" />
<ProjectReference Include="../isn.abst/isn.abst.csproj" />
</ItemGroup>
</Project>

@ -33,7 +33,7 @@ namespace isnd.Controllers
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Index)]
public IActionResult ApiIndex()
{
return Ok(new ApiIndexViewModel(packageManager.CatalogBaseUrl){ Version = PackageManager.BASE_API_LEVEL, Resources = resources });
return Ok(new ApiIndexViewModel(packageManager.CatalogBaseUrl + "/index.json"){ Version = PackageManager.BASE_API_LEVEL, Resources = resources });
}
}

@ -0,0 +1,18 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using isnd.Entities;
using isn.abst;
namespace isnd.Controllers
{
public partial class PackagesController
{
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.PackageDetailUriTemplate)]
public async Task<IActionResult> Details(string id, string version)
{
var result = await packageManager.GetPackageDetailsAsync(id, version);
if (result==null) return NotFound();
return Ok(result);
}
}
}

@ -32,8 +32,8 @@ namespace isnd.Controllers
return Ok(index);
}
// return a Package
var leaf = await packageManager.GetCatalogEntryAsync(id, version, null);
// return Package details
var leaf = await packageManager.GetPackageDetailsAsync(id, version, null);
if (null == leaf) return NotFound(new { id, version });
return Ok(leaf);

@ -27,10 +27,10 @@ namespace isnd.Controllers
Source = packageManager.CatalogBaseUrl+ApiConfig.Index,
Query = model
};
List<PackageRegistration> registrations = new List<PackageRegistration>();
List<Catalog> registrations = new List<Catalog>();
foreach (var pk in pkgs.data.GroupBy(x => x.PackageId))
{
registrations.Add(new PackageRegistration(apiBase, pk.Key, pkgs.GetResults().Single(p=>p.Id == pk.Key).Versions));
registrations.Add(new Catalog(apiBase, pk.Key, pkgs.GetResults().Single(p=>p.Id == pk.Key).Versions));
}
return View(new RegistrationPageIndexQueryAndResult
@ -81,7 +81,7 @@ namespace isnd.Controllers
&& (pkgtype!=null && m.Type == pkgtype || m.Type != "Delete" ));
if (packageVersion == null) return NotFound();
if (!User.IsOwner(packageVersion)) return Unauthorized();
var pkg = await packageManager.GetPackageAsync(pkgid, version, pkgtype);
var pkg = await packageManager.GetPackageDetailsAsync(pkgid, version, pkgtype);
return View(pkg);
}

@ -16,7 +16,7 @@ using isnd.Entities;
namespace isnd.Data.Catalog
{
public class PackageDetails : Permalink, IObject, IPackageSearchMetadata
public class PackageDetails : Permalink, IObject
{
/// <summary>
/// Creates a catalog entry
@ -24,7 +24,7 @@ namespace isnd.Data.Catalog
/// <param name="pkg">package id</param>
/// <param name="apiBase">api Base</param>
/// <returns></returns>
public PackageDetails(PackageVersion pkg, string apiBase): base( apiBase + ApiConfig.Registration + "/" + pkg.PackageId + "/" + pkg.FullString + ".json")
public PackageDetails(PackageVersion pkg, string apiBase): base( apiBase + ApiConfig.Package + "/" + pkg.PackageId + "/" + pkg.FullString)
{
Title = PackageId = pkg.Package.Id;
Version = pkg.FullString;
@ -32,80 +32,18 @@ namespace isnd.Data.Catalog
packageContent = apiBase + pkg.NugetLink;
CommitId = pkg.CommitId;
Published = CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
IsListed = !pkg.IsDeleted && pkg.Package.Public;
Listed = !pkg.IsDeleted && pkg.Package.Public;
if (pkg.DependencyGroups!=null)
{
DependencySets = pkg.DependencyGroups;
}
PackageDetailsUrl = new Uri(this.id);
// TODO Licence Project Urls, Summary, Title, Owners, etc ...
}
[JsonProperty("@type")]
public string[] RefType { get; protected set; } = new string[] { "PackageDetails" };
/// <summary>
///
/// </summary>
/// <param name="apiBase"></param>
/// <param name="pkgId"></param>
/// <param name="pkgVersionString"></param>
/// <param name="commitId"></param>
/// <param name="commitTimeStamp"></param>
/// <param name="authors"></param>
/// <param name="deprecation"></param>
/// <param name="description"></param>
/// <param name="iconUrl"></param>
/// <param name="language"></param>
/// <param name="licenseUrl"></param>
/// <param name="licenseExpression"></param>
/// <param name="minClientVersion"></param>
/// <param name="projectUrl"></param>
/// <param name="requireLicenseAcceptance"></param>
/// <param name="summary"></param>
/// <param name="tags"></param>
/// <param name="title"></param>
/// <param name="packageContent"></param>
/// <param name="version"></param>
/// <param name="identity"></param>
/// <param name="readmeUrl"></param>
/// <param name="reportAbuseUrl"></param>
/// <param name="packageDetailsUrl"></param>
/// <param name="owners"></param>
/// <param name="isListed"></param>
/// <param name="prefixReserved"></param>
/// <param name="licenseMetadata"></param>
public PackageDetails(string apiBase, string pkgId, string pkgVersionString, string commitId, DateTimeOffset commitTimeStamp, string authors, Deprecation deprecation, string description, Uri iconUrl, string language, Uri licenseUrl, string licenseExpression, string minClientVersion, Uri projectUrl, bool requireLicenseAcceptance, string summary, string tags, string title, string packageContent, string version, PackageIdentity identity, Uri readmeUrl, Uri reportAbuseUrl, Uri packageDetailsUrl, string owners, bool isListed, bool prefixReserved, LicenseMetadata licenseMetadata)
: base( apiBase + ApiConfig.Registration + "/" + pkgId + "/" + pkgVersionString + ".json")
{
this.CommitId = commitId;
this.CommitTimeStamp = commitTimeStamp;
this.Authors = authors;
this.deprecation = deprecation;
this.Description = description;
this.IconUrl = iconUrl;
this.language = language;
this.LicenseUrl = licenseUrl;
this.licenseExpression = licenseExpression;
this.minClientVersion = minClientVersion;
this.ProjectUrl = projectUrl;
this.RequireLicenseAcceptance = requireLicenseAcceptance;
this.Summary = summary;
this.Tags = tags;
this.Title = title;
this.packageContent = packageContent;
this.Version = version;
this.Identity = identity;
this.ReadmeUrl = readmeUrl;
this.ReportAbuseUrl = reportAbuseUrl;
this.PackageDetailsUrl = packageDetailsUrl;
this.Owners = owners;
this.IsListed = isListed;
this.PrefixReserved = prefixReserved;
this.LicenseMetadata = licenseMetadata;
}
[JsonProperty("commitId")]
public string CommitId { get; set; }
@ -198,22 +136,19 @@ namespace isnd.Data.Catalog
public Uri ReportAbuseUrl { get; set; }
public Uri PackageDetailsUrl { get; set; }
public string Owners { get; set; }
[JsonProperty("isListed")]
public bool IsListed { get; set; }
public bool Listed { get; set; }
public bool PrefixReserved { get; set; }
public LicenseMetadata LicenseMetadata { get; set; }
[JsonProperty("dependencyGroups")]
public IEnumerable<PackageDependencyGroup> DependencySets {get; set;}
IEnumerable<NuGet.Packaging.PackageDependencyGroup> IPackageSearchMetadata.DependencySets => throw new NotImplementedException();
public Task<PackageDeprecationMetadata> GetDeprecationMetadataAsync()
{
throw new NotImplementedException();

@ -7,15 +7,15 @@ using System.Linq;
namespace isnd.Data.Catalog
{
public class PackageRegistration : Permalink
public class Catalog : Permalink
{
public PackageRegistration(string url) : base(url)
public Catalog(string url) : base(url)
{
Items = new List<RegistrationPage>();
}
public PackageRegistration(string apiBase, string pkgId, IEnumerable<PackageVersion> versions) : base($"{apiBase}{ApiConfig.Registration}/{pkgId}/index.json")
public Catalog(string apiBase, string pkgId, IEnumerable<PackageVersion> versions) : base($"{apiBase}{ApiConfig.Registration}/{pkgId}/index.json")
{
Items = new List<RegistrationPage>
{

@ -18,15 +18,15 @@ namespace isnd.Interfaces
string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25);
IEnumerable<Resource> GetResources();
Task<PackageRegistration> UpdateCatalogForAsync(Commit commit);
Task<Catalog> UpdateCatalogForAsync(Commit commit);
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
Task<PackageDetails> GetPackageDetailsAsync(string pkgid, string version, string type=null);
Task<Data.Catalog.RegistrationLeaf> GetCatalogEntryAsync(string pkgId, string version, string pkgType);
IEnumerable<Data.Catalog.RegistrationLeaf> SearchCatalogEntriesById(string pkgId, string semver, string pkgType, bool preRelease);
Task<PackageRegistration> GetCatalogIndexAsync();
Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
Task<Catalog> GetCatalogIndexAsync();
Task<Catalog> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
Task<PackageSearchResult> SearchPackageAsync(PackageRegistrationQuery query);

@ -47,7 +47,7 @@ namespace isnd.Services
},
// under dev, only leash in release mode
new Resource(apiBase + ApiConfig.Package + "/{id}/{version}",
new Resource(apiBase + ApiConfig.PackageDetailUriTemplate,
"PackageDetailsUriTemplate/5.1.0")
{
Comment = "URI template used by NuGet Client to construct details URL for packages"
@ -141,19 +141,19 @@ namespace isnd.Services
private IsndSettings isndSettings;
private readonly string apiBase;
public virtual async Task<PackageRegistration> GetCatalogIndexAsync()
public virtual async Task<Catalog> GetCatalogIndexAsync()
{
return await UpdateCatalogForAsync(null);
}
public async Task<PackageRegistration> UpdateCatalogForAsync
public async Task<Catalog> UpdateCatalogForAsync
(Commit reason = null)
{
int i = 0;
string baseId = apiBase + ApiConfig.Catalog;
string baseRegistrationId = $"{apiBase}{ApiConfig.Registration}";
PackageRegistration index = new PackageRegistration(baseId);
Catalog index = new Catalog(baseId);
var scope = await dbContext.Commits.OrderBy(c => c.TimeStamp).ToArrayAsync();
@ -214,14 +214,25 @@ namespace isnd.Services
return new PackageDeletionReport { Deleted = true, DeletedVersion = pkg };
}
public async Task<PackageVersion> GetPackageAsync
public async Task<PackageDetails> GetPackageDetailsAsync
(string pkgId, string version, string type)
{
return await dbContext.PackageVersions.SingleOrDefaultAsync(
var pkg = await dbContext.PackageVersions
.Include(v=>v.Package)
.Include(v=>v.Package.Owner)
.Include(v=>v.LatestCommit)
.Include(v=>v.DependencyGroups)
.SingleOrDefaultAsync(
v => v.PackageId == pkgId &&
v.FullString == version &&
(type==null || v.Type == type)
);
(type==null || v.Type == type))
;
if (pkg == null) return null;
foreach (var g in pkg.DependencyGroups)
{
g.Dependencies = dbContext.Dependencies.Where(d => d.DependencyGroupId == g.Id).ToList();
}
return new PackageDetails(pkg, apiBase);
}
public async Task<Data.Catalog.RegistrationLeaf> GetCatalogEntryAsync
@ -286,7 +297,7 @@ namespace isnd.Services
&& (pkgType == null || pkgType == v.Type));
}
public async Task<PackageRegistration> GetPackageRegistrationIndexAsync
public async Task<Catalog> GetPackageRegistrationIndexAsync
(PackageRegistrationQuery query)
{
if (string.IsNullOrWhiteSpace(query.Query)) return null;
@ -306,7 +317,7 @@ namespace isnd.Services
.ToList();
version.LatestCommit = dbContext.Commits.Single(c => c.Id == version.CommitNId);
}
return new PackageRegistration(apiBase, query.Query, scope);
return new Catalog(apiBase, query.Query, scope);
}
public async Task<PackageSearchResult> SearchPackageAsync(PackageRegistrationQuery query)

@ -7,6 +7,6 @@ namespace isnd
{
public string Source { get; set; }
public PackageRegistrationQuery Query { get; set; }
public PackageRegistration[] Result { get; set; }
public Catalog[] Result { get; set; }
}
}

@ -13,33 +13,33 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" IncludeAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" IncludeAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NuGet.Packaging.Core" Version="6.9.1" />
<PackageReference Include="MailKit" Version="4.4.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PackageReference Include="MailKit" Version="4.8.0" />
<PackageReference Include="GitVersion.MsBuild" Version="6.0.3">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../isn.abst/isn.abst.csproj" />

@ -9,11 +9,11 @@
<Version>1.0.7</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<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.5.7" PrivateAssets="All" />
</ItemGroup>

@ -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()
{
PackageDependencyGroup g = new PackageDependencyGroup
{
TargetFramework="net7.0"
};
// not yet from testing url a [Fact]
public async Task TestGetPackageUri()
{
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>

@ -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
}
}
Loading…