Test and get the nuget via the NuGet v3 protocol
This commit is contained in:
parent
ac0a195b5f
commit
4e4d7f0fd7
3 changed files with 84 additions and 6 deletions
|
|
@ -17,9 +17,11 @@ using Microsoft.AspNetCore.DataProtection;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Common;
|
||||
using NuGet.Configuration;
|
||||
using NuGet.Protocol;
|
||||
using NuGet.Protocol.Core.Types;
|
||||
using NuGet.Versioning;
|
||||
using Xunit;
|
||||
|
||||
namespace isnd.host.tests
|
||||
|
|
@ -168,6 +170,63 @@ namespace isnd.host.tests
|
|||
await AssertAutocompleteContainsPushedVersionAsync(DummyPackageId, DummyPackageVersion);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task NuGetV3ProtocolCanDownloadDummyPackage()
|
||||
{
|
||||
var apiKeyValue = $"dummy-key-{Guid.NewGuid():N}";
|
||||
var packagePath = GetDummyArtifactPath();
|
||||
Assert.True(File.Exists(packagePath), $"Missing dummy artifact at {packagePath}");
|
||||
|
||||
using (var serviceScope = server.Host.Services.CreateScope())
|
||||
{
|
||||
var dbContext = serviceScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
var userId = $"dummy-user-{Guid.NewGuid():N}";
|
||||
|
||||
await ResetDummyPackageStateAsync(serviceScope.ServiceProvider, dbContext);
|
||||
|
||||
dbContext.Users.Add(new ApplicationUser
|
||||
{
|
||||
Id = userId,
|
||||
UserName = userId,
|
||||
NormalizedUserName = userId.ToUpperInvariant(),
|
||||
Email = $"{userId}@tests.local",
|
||||
NormalizedEmail = $"{userId}@tests.local".ToUpperInvariant(),
|
||||
EmailConfirmed = true
|
||||
});
|
||||
|
||||
dbContext.ApiKeys.Add(new ApiKey
|
||||
{
|
||||
Id = apiKeyValue,
|
||||
UserId = userId,
|
||||
Name = "dummy-key",
|
||||
CreationDate = DateTime.UtcNow,
|
||||
ValidityPeriodInDays = 30
|
||||
});
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await PushPackageAsync(packagePath, apiKeyValue);
|
||||
|
||||
var indexUrl = GetServerBaseUrl() + "/" + Constants.APIPrefix + "index.json";
|
||||
var repository = Repository.Factory.GetCoreV3(indexUrl);
|
||||
var findPackageById = await repository.GetResourceAsync<FindPackageByIdResource>();
|
||||
Assert.NotNull(findPackageById);
|
||||
|
||||
await using var nupkgStream = new MemoryStream();
|
||||
using var cache = new SourceCacheContext();
|
||||
var copied = await findPackageById.CopyNupkgToStreamAsync(
|
||||
DummyPackageId,
|
||||
NuGetVersion.Parse(DummyPackageVersion),
|
||||
nupkgStream,
|
||||
cache,
|
||||
NullLogger.Instance,
|
||||
CancellationToken.None);
|
||||
|
||||
Assert.True(copied, "NuGet v3 client could not download the package from the feed.");
|
||||
Assert.True(nupkgStream.Length > 0, "Downloaded package stream is empty.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRegistrationV3Resource()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue