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

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

@ -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" />