unit testing

This commit is contained in:
2024-10-19 13:25:58 +01:00
parent 2b45e421dd
commit c615886a4c
22 changed files with 195 additions and 170 deletions

View File

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

View File

@ -1,4 +1,6 @@
= URL's = 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

27
gitversion.json Normal file
View File

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

View File

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

View File

@ -15,11 +15,11 @@
<InformationalVersion>1.0.7+Branch.main.Sha.3695c1742965d93eba0ad851656cfaa3e44ba327</InformationalVersion> <InformationalVersion>1.0.7+Branch.main.Sha.3695c1742965d93eba0ad851656cfaa3e44ba327</InformationalVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <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="Mono.Options" Version="5.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="unleash.client" Version="4.1.6" /> <PackageReference Include="unleash.client" Version="4.1.13" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0" /> <PackageReference Include="GitVersion.MsBuild" Version="6.0.3" />
<ProjectReference Include="../isn.abst/isn.abst.csproj" /> <ProjectReference Include="../isn.abst/isn.abst.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -33,7 +33,7 @@ namespace isnd.Controllers
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Index)] [HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Index)]
public IActionResult ApiIndex() 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 });
} }
} }

View File

@ -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);
}
}
}

View File

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

View File

@ -27,10 +27,10 @@ namespace isnd.Controllers
Source = packageManager.CatalogBaseUrl+ApiConfig.Index, Source = packageManager.CatalogBaseUrl+ApiConfig.Index,
Query = model Query = model
}; };
List<PackageRegistration> registrations = new List<PackageRegistration>(); List<Catalog> registrations = new List<Catalog>();
foreach (var pk in pkgs.data.GroupBy(x => x.PackageId)) 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 return View(new RegistrationPageIndexQueryAndResult
@ -81,7 +81,7 @@ namespace isnd.Controllers
&& (pkgtype!=null && m.Type == pkgtype || m.Type != "Delete" )); && (pkgtype!=null && m.Type == pkgtype || m.Type != "Delete" ));
if (packageVersion == null) return NotFound(); if (packageVersion == null) return NotFound();
if (!User.IsOwner(packageVersion)) return Unauthorized(); 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); return View(pkg);
} }

View File

@ -16,7 +16,7 @@ using isnd.Entities;
namespace isnd.Data.Catalog namespace isnd.Data.Catalog
{ {
public class PackageDetails : Permalink, IObject, IPackageSearchMetadata public class PackageDetails : Permalink, IObject
{ {
/// <summary> /// <summary>
/// Creates a catalog entry /// Creates a catalog entry
@ -24,7 +24,7 @@ namespace isnd.Data.Catalog
/// <param name="pkg">package id</param> /// <param name="pkg">package id</param>
/// <param name="apiBase">api Base</param> /// <param name="apiBase">api Base</param>
/// <returns></returns> /// <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; Title = PackageId = pkg.Package.Id;
Version = pkg.FullString; Version = pkg.FullString;
@ -32,80 +32,18 @@ namespace isnd.Data.Catalog
packageContent = apiBase + pkg.NugetLink; packageContent = apiBase + pkg.NugetLink;
CommitId = pkg.CommitId; CommitId = pkg.CommitId;
Published = CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp; Published = CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
IsListed = !pkg.IsDeleted && pkg.Package.Public; Listed = !pkg.IsDeleted && pkg.Package.Public;
if (pkg.DependencyGroups!=null) if (pkg.DependencyGroups!=null)
{ {
DependencySets = pkg.DependencyGroups; DependencySets = pkg.DependencyGroups;
} }
PackageDetailsUrl = new Uri(this.id);
// TODO Licence Project Urls, Summary, Title, Owners, etc ... // TODO Licence Project Urls, Summary, Title, Owners, etc ...
} }
[JsonProperty("@type")] [JsonProperty("@type")]
public string[] RefType { get; protected set; } = new string[] { "PackageDetails" }; 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")] [JsonProperty("commitId")]
public string CommitId { get; set; } public string CommitId { get; set; }
@ -198,22 +136,19 @@ namespace isnd.Data.Catalog
public Uri ReportAbuseUrl { get; set; } public Uri ReportAbuseUrl { get; set; }
public Uri PackageDetailsUrl { get; set; }
public string Owners { get; set; } public string Owners { get; set; }
[JsonProperty("isListed")] public bool Listed { get; set; }
public bool IsListed { get; set; }
public bool PrefixReserved { get; set; } public bool PrefixReserved { get; set; }
public LicenseMetadata LicenseMetadata { get; set; } public LicenseMetadata LicenseMetadata { get; set; }
[JsonProperty("dependencyGroups")] [JsonProperty("dependencyGroups")]
public IEnumerable<PackageDependencyGroup> DependencySets {get; set;} public IEnumerable<PackageDependencyGroup> DependencySets {get; set;}
IEnumerable<NuGet.Packaging.PackageDependencyGroup> IPackageSearchMetadata.DependencySets => throw new NotImplementedException();
public Task<PackageDeprecationMetadata> GetDeprecationMetadataAsync() public Task<PackageDeprecationMetadata> GetDeprecationMetadataAsync()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -7,15 +7,15 @@ using System.Linq;
namespace isnd.Data.Catalog 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>(); 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> Items = new List<RegistrationPage>
{ {

View File

@ -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); string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25);
IEnumerable<Resource> GetResources(); IEnumerable<Resource> GetResources();
Task<PackageRegistration> UpdateCatalogForAsync(Commit commit); Task<Catalog> UpdateCatalogForAsync(Commit commit);
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type); Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, 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); Task<Data.Catalog.RegistrationLeaf> GetCatalogEntryAsync(string pkgId, string version, string pkgType);
IEnumerable<Data.Catalog.RegistrationLeaf> SearchCatalogEntriesById(string pkgId, string semver, string pkgType, bool preRelease); IEnumerable<Data.Catalog.RegistrationLeaf> SearchCatalogEntriesById(string pkgId, string semver, string pkgType, bool preRelease);
Task<PackageRegistration> GetCatalogIndexAsync(); Task<Catalog> GetCatalogIndexAsync();
Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query); Task<Catalog> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
Task<PackageSearchResult> SearchPackageAsync(PackageRegistrationQuery query); Task<PackageSearchResult> SearchPackageAsync(PackageRegistrationQuery query);

View File

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

View File

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

View File

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

View File

@ -9,11 +9,11 @@
<Version>1.0.7</Version> <Version>1.0.7</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.7.0" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" /> <PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.reporters" Version="2.7.0" /> <PackageReference Include="xunit.runner.reporters" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageToolReference Include="xunit.runner.console" Version="2.5.7" PrivateAssets="All" /> <PackageToolReference Include="xunit.runner.console" Version="2.5.7" PrivateAssets="All" />
</ItemGroup> </ItemGroup>

View File

@ -15,6 +15,7 @@ using NuGet.Protocol.Core.Types;
using isn.abst; using isn.abst;
using NuGet.Common; using NuGet.Common;
using System.Collections.Generic; using System.Collections.Generic;
using NuGet.Versioning;
namespace isnd.host.tests namespace isnd.host.tests
{ {
@ -58,7 +59,6 @@ namespace isnd.host.tests
} }
[Fact]
public void NugetInstallsTest() public void NugetInstallsTest()
{ {
using (var serviceScope = server.Host.Services.CreateScope()) using (var serviceScope = server.Host.Services.CreateScope())
@ -83,7 +83,7 @@ namespace isnd.host.tests
using (var serviceScope = server.Host.Services.CreateScope()) using (var serviceScope = server.Host.Services.CreateScope())
{ {
var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value; 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(); NullThrottle throttle = new NullThrottle();
PackageSource packageSource = new PackageSource(pkgSourceUrl); PackageSource packageSource = new PackageSource(pkgSourceUrl);
@ -99,7 +99,7 @@ namespace isnd.host.tests
using (var serviceScope = server.Host.Services.CreateScope()) using (var serviceScope = server.Host.Services.CreateScope())
{ {
var isnSettings = serviceScope.ServiceProvider.GetService<IOptions<isnd.Entities.IsndSettings>>().Value; 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 prov = new RegistrationResourceV3Provider();
var source = new PackageSource(pkgSourceUrl); var source = new PackageSource(pkgSourceUrl);
var repo = new SourceRepository(source, new INuGetResourceProvider[] { prov }); var repo = new SourceRepository(source, new INuGetResourceProvider[] { prov });
@ -137,7 +137,7 @@ namespace isnd.host.tests
Assert.NotEmpty(packages); Assert.NotEmpty(packages);
foreach (IPackageSearchMetadata package in packages) foreach (var package in packages)
{ {
Console.WriteLine($"Version: {package.Identity.Version}"); Console.WriteLine($"Version: {package.Identity.Version}");
Console.WriteLine($"Listed: {package.IsListed}"); Console.WriteLine($"Listed: {package.IsListed}");
@ -173,6 +173,7 @@ namespace isnd.host.tests
[Fact] [Fact]
public async Task TestPackagePush() public async Task TestPackagePush()
{ {
server.EnsureUser(server.TestingUserName);
var logger = new TestLogger(); var logger = new TestLogger();
SourceRepository repository = Repository.Factory.GetCoreV3(SPIIndexURI); SourceRepository repository = Repository.Factory.GetCoreV3(SPIIndexURI);
PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>(); PackageUpdateResource pushRes = await repository.GetResourceAsync<PackageUpdateResource>();
@ -183,13 +184,16 @@ namespace isnd.host.tests
} }
[Fact] // not yet from testing url a [Fact]
public void TestDepedency() public async Task TestGetPackageUri()
{ {
PackageDependencyGroup g = new PackageDependencyGroup PackageSource source = new PackageSource("https://isn.pschneider.fr/v3/index.json");
{ source.ProtocolVersion=3;
TargetFramework="net7.0" 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) private string GetSymbolsApiKey(string apiUrl)

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using isn; using isn;
using isnd.Data; using isnd.Data;
using isnd.Entities; using isnd.Entities;
@ -31,6 +32,10 @@ namespace isnd.tests
private IsndSettings siteSettings; private IsndSettings siteSettings;
public IDataProtector DataProtector { get; private set; } 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 string ProtectedTestingApiKey { get; internal set; }
public ApplicationUser TestingUser { get; private set; } public ApplicationUser TestingUser { get; private set; }
@ -49,19 +54,19 @@ namespace isnd.tests
{ {
var builder = WebHost.CreateDefaultBuilder(new string[0]); var builder = WebHost.CreateDefaultBuilder(new string[0]);
// .UseContentRoot("../../../../../src/isnd") // .UseContentRoot("../../../../../src/isnd")
builder.UseStartup(typeof(Startup)) builder.UseStartup(typeof(Startup))
.ConfigureAppConfiguration((builderContext, config) => .ConfigureAppConfiguration((builderContext, config) =>
{ {
config.AddJsonFile("appsettings.json", true); config.AddJsonFile("appsettings.json", true);
config.AddJsonFile("appsettings.Development.json", false); config.AddJsonFile("appsettings.Development.json", false);
}); });
Host = builder.Build(); Host = builder.Build();
var logFactory = Host.Services.GetRequiredService<ILoggerFactory>(); var logFactory = Host.Services.GetRequiredService<ILoggerFactory>();
Logger = logFactory.CreateLogger<WebServerFixture>(); Logger = logFactory.CreateLogger<WebServerFixture>();
Host.Start(); //Starts listening on the configured addresses. Host.Start(); //Starts listening on the configured addresses.
var server = Host.Services.GetRequiredService<IServer>(); var server = Host.Services.GetRequiredService<IServer>();
@ -76,38 +81,47 @@ namespace isnd.tests
DataProtector = Host.Services.GetRequiredService<IDataProtectionProvider>() DataProtector = Host.Services.GetRequiredService<IDataProtectionProvider>()
.CreateProtector(siteSettings.ProtectionTitle); .CreateProtector(siteSettings.ProtectionTitle);
var dbContext = Host.Services.GetRequiredService<ApplicationDbContext>(); dbContext = Host.Services.GetRequiredService<ApplicationDbContext>();
string testingUserName = "Tester"; TestingUserName = "Tester";
TestingUser = dbContext.Users.FirstOrDefault(u=>u.UserName==testingUserName); TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
if (TestingUser==null) EnsureUser(TestingUserName);
{ var testKey = dbContext.ApiKeys.FirstOrDefault(k => k.UserId == TestingUser.Id);
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);
if (testKey == null) if (testKey == null)
{ {
var keyProvider = Host.Services.GetService<IApiKeyProvider>(); var keyProvider = Host.Services.GetService<IApiKeyProvider>();
var apiKeyQuery = new Data.ApiKeys.CreateModel var apiKeyQuery = new Data.ApiKeys.CreateModel
{ {
Name = "Testing Key", Name = "Testing Key",
UserId = TestingUser.Id, UserId = TestingUser.Id,
ValidityPeriodInDays = 1 ValidityPeriodInDays = 1
}; };
testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result; testKey = keyProvider.CreateApiKeyAsync(apiKeyQuery).Result;
} }
ProtectedTestingApiKey = DataProtector.Protect(testKey.Id); 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);
}
} }
} }
} }

View File

@ -13,9 +13,6 @@
}, },
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": {
"Url": "http://127.0.0.1:5002"
},
"Https": { "Https": {
"Url": "https://127.0.0.1:5003" "Url": "https://127.0.0.1:5003"
} }

View File

@ -10,12 +10,12 @@
<Version>1.0.7</Version> <Version>1.0.7</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="XunitXml.TestLogger" Version="3.1.20" /> <PackageReference Include="XunitXml.TestLogger" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.7.0" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" /> <PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.reporters" Version="2.7.0" /> <PackageReference Include="xunit.runner.reporters" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageToolReference Include="xunit.runner.console" Version="2.4.2" PrivateAssets="All" /> <PackageToolReference Include="xunit.runner.console" Version="2.4.2" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View 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
}
}