public async Task VerifyDownloadModeForce()
        {
            // Arrange
            await VerifyDownloadMode(
                async (downloadFolder, entry) =>
            {
                var nupkgPath = Path.Combine(downloadFolder, $"{entry.FileBaseName}.nupkg");
                var testNupkg = TestNupkg.Create("different", "1.0.0").Save(downloadFolder);
                File.Move(testNupkg.FullName, nupkgPath);

                // Act
                var fileInfo = await entry.DownloadNupkgAsync(
                    downloadFolder,
                    DownloadMode.Force,
                    CancellationToken.None);

                // Assert
                Assert.NotNull(fileInfo);
                Assert.Equal(nupkgPath, fileInfo.FullName);
                using (var reader = new PackageArchiveReader(nupkgPath))
                {
                    Assert.Equal("a", reader.NuspecReader.GetId());
                }
            });
        }
Пример #2
0
        public async Task RunModifyNuspecVerifySuccess()
        {
            using (var workingDir = new TestFolder())
            {
                var testNupkg = new TestNupkg("a", "1.0.0");
                TestNupkg.Create(workingDir.Root);

                var args = "nuspec dependencies clear";

                var result = await CmdRunner.RunAsync(ExeUtils.NupkgWrenchExePath, workingDir, args);

                result.Success.Should().BeTrue();
                result.Errors.Should().BeNullOrEmpty();
            }
        }
        public async Task VerifyDownloadModeFailIfExists_Exists()
        {
            // Arrange
            await VerifyDownloadMode(
                async (downloadFolder, entry) =>
            {
                var nupkgPath = Path.Combine(downloadFolder, $"{entry.FileBaseName}.nupkg");
                var testNupkg = TestNupkg.Create("different", "1.0.0").Save(downloadFolder);
                File.Move(testNupkg.FullName, nupkgPath);

                // Act & Assert
                await Assert.ThrowsAsync <InvalidOperationException>(() => entry.DownloadNupkgAsync(
                                                                         downloadFolder,
                                                                         DownloadMode.FailIfExists,
                                                                         CancellationToken.None));
                using (var reader = new PackageArchiveReader(nupkgPath))
                {
                    Assert.Equal("different", reader.NuspecReader.GetId());
                }
            });
        }
        public async Task VerifyDownloadModeOverwriteIfNewer_ExistingIsNewer()
        {
            // Arrange
            await VerifyDownloadMode(
                async (downloadFolder, entry) =>
            {
                var nupkgPath = Path.Combine(downloadFolder, $"{entry.FileBaseName}.nupkg");
                var testNupkg = TestNupkg.Create("different", "1.0.0").Save(downloadFolder);
                File.Move(testNupkg.FullName, nupkgPath);
                File.SetLastWriteTimeUtc(nupkgPath, DateTime.UtcNow.AddDays(2));

                // Act
                var fileInfo = await entry.DownloadNupkgAsync(
                    downloadFolder,
                    DownloadMode.OverwriteIfNewer,
                    CancellationToken.None);

                // Assert
                using (var reader = new PackageArchiveReader(fileInfo.FullName))
                {
                    Assert.Equal("different", reader.NuspecReader.GetId());
                }
            });
        }