예제 #1
0
        public async Task TestDeletePackage_Local_Directory_PackageSource(NuGetProtocolVersion protocolVersion)
        {
            await using var deletePackageSrcDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem);

            var packageIdentity = new PackageIdentity("test", NuGetVersion.Parse("1.0.0"));

            var packageFilenameAbsolute = _snapFilesystem.PathCombine(deletePackageSrcDirectory,
                                                                      $"{packageIdentity.Id}.{packageIdentity.Version.ToNormalizedString()}.nupkg");

            await using (var packageOutputStream = _snapFilesystem.FileReadWrite(packageFilenameAbsolute))
            {
                await using var nupkgStream = BuildNupkg(packageIdentity);
                await nupkgStream.CopyToAsync(packageOutputStream);
            }

            var packageSource = new PackageSource(deletePackageSrcDirectory, "test", true)
            {
                ProtocolVersion = (int)protocolVersion
            };

            var packageSources = new NuGetInMemoryPackageSources(deletePackageSrcDirectory, packageSource);

            await _nugetService.DeleteAsync(packageIdentity, packageSources, packageSource);

            Assert.False(_snapFilesystem.FileExists(packageFilenameAbsolute));
            Assert.Equal(new Uri(deletePackageSrcDirectory), packageSource.SourceUri);
        }
예제 #2
0
        public async Task TestPushPackage_Local_Directory_PackageSource(NuGetProtocolVersion protocolVersion)
        {
            await using var testPackageSrcDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem);

            var packageIdentity = new PackageIdentity("test", NuGetVersion.Parse("1.0.0"));

            var packageFilenameAbsolute = _snapFilesystem.PathCombine(testPackageSrcDirectory,
                                                                      $"{packageIdentity.Id}.{packageIdentity.Version.ToNormalizedString()}.nupkg");

            await using (var packageOutputStream = _snapFilesystem.FileReadWrite(packageFilenameAbsolute))
            {
                await using var nupkgStream = BuildNupkg(packageIdentity);
                await nupkgStream.CopyToAsync(packageOutputStream);
            }

            await using var publishDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem);

            var packageSource = new PackageSource(publishDirectory, "test", true)
            {
                ProtocolVersion = (int)protocolVersion
            };

            var nuGetPackageSources = new NuGetInMemoryPackageSources(publishDirectory, packageSource);

            await _nugetService.PushAsync(packageFilenameAbsolute, nuGetPackageSources, packageSource, default);

            var dstFilename = _snapFilesystem.PathCombine(publishDirectory, _snapFilesystem.PathGetFileName(packageFilenameAbsolute));

            using var packageArchiveRead = new PackageArchiveReader(dstFilename);
            Assert.Equal(packageArchiveRead.GetIdentity(), packageIdentity);
            Assert.Equal(new Uri(publishDirectory), packageSource.SourceUri);
        }
예제 #3
0
        public async Task TestGetMetadatasAsync_Local_Directory_PackageSource(NuGetProtocolVersion protocolVersion)
        {
            await using var packagesDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem);

            var packageSource = new PackageSource(packagesDirectory, "test", true)
            {
                ProtocolVersion = (int)protocolVersion
            };

            var initialPackageIdentity = new PackageIdentity("test", NuGetVersion.Parse("1.0.0"));

            var initialPackageFilenameAbsolute = _snapFilesystem.PathCombine(packagesDirectory,
                                                                             $"{initialPackageIdentity.Id}.{initialPackageIdentity.Version.ToNormalizedString()}.nupkg");

            await using (var packageOutputStream = _snapFilesystem.FileReadWrite(initialPackageFilenameAbsolute))
            {
                await using var nupkgStream = BuildNupkg(initialPackageIdentity);
                await nupkgStream.CopyToAsync(packageOutputStream);
            }

            var secondPackageIdentity = new PackageIdentity("test", NuGetVersion.Parse("2.0.0"));

            var secondPackageFilenameAbsolute = _snapFilesystem.PathCombine(packagesDirectory,
                                                                            $"{secondPackageIdentity.Id}.{secondPackageIdentity.Version.ToNormalizedString()}.nupkg");

            await using (var packageOutputStream = _snapFilesystem.FileReadWrite(secondPackageFilenameAbsolute))
            {
                await using var nupkgStream = BuildNupkg(secondPackageIdentity);
                await nupkgStream.CopyToAsync(packageOutputStream);
            }

            var differentPackageIdentity = new PackageIdentity("test2", NuGetVersion.Parse("2.0.0"));

            var differentPackageFilenameAbsolute = _snapFilesystem.PathCombine(packagesDirectory,
                                                                               $"{differentPackageIdentity.Id}.{differentPackageIdentity.Version.ToNormalizedString()}.nupkg");

            await using (var packageOutputStream = _snapFilesystem.FileReadWrite(differentPackageFilenameAbsolute))
            {
                await using var nupkgStream = BuildNupkg(differentPackageIdentity);
                await nupkgStream.CopyToAsync(packageOutputStream);
            }

            var packageSources = new NuGetInMemoryPackageSources(packagesDirectory, packageSource);

            var packages = await _nugetService
                           .GetMetadatasAsync("test", packageSources, false, cancellationToken : CancellationToken.None);

            Assert.Equal(2, packages.Count);
        }