Ejemplo n.º 1
0
        public void ClientCertAddCommand_Fail_FileCertificateNotExist()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "add",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--path",
                    @".\MyCertificate.pfx"
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "A fileCert path specified a file that does not exist";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 2
0
        public void Restore_WithMissingConfigFile_Fails()
        {
            using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var configDir = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                    var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                    XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3");
                    XPlatTestUtils.AddDependency(spec, "fody", "1.29.4");
                    XPlatTestUtils.WriteJson(spec, specPath);

                    var log = new TestCommandOutputLogger();

                    var args = new string[]
                    {
                        "restore",
                        projectDir,
                        "--configfile",
                        Path.Combine(configDir, "DoesNotExist.config"),
                    };

                    // Act
                    var exitCode = Program.MainInternal(args, log);

                    // Assert
                    Assert.Equal(1, exitCode);
                    Assert.Equal(1, log.Errors);
                    Assert.Contains("DoesNotExist.config", log.ShowErrors()); // file does not exist
                }
        }
Ejemplo n.º 3
0
        public void ClientCertUpdateCommand_Fail_CertificateSourceNotSpecified()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "update",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "Invalid combination of arguments";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 4
0
        public void ClientCertRemoveCommand_Success_ItemCertificate()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName,
                                                                  testInfo.CertificateAbsoluteFilePath,
                                                                  testInfo.CertificatePassword,
                                                                  false,
                                                                  testInfo.ConfigFile));
                var args = new[]
                {
                    "remove",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("was successfully removed", log.ShowMessages());

                testInfo.ValidateSettings();
            }
        }
Ejemplo n.º 5
0
        public void ClientCertAddCommand_Fail_CertificateSourceCombinationSpecified()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "add",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--path",
                    testInfo.CertificateRelativeFilePath,
                    "--store-location",
                    testInfo.CertificateStoreLocation.ToString()
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Contains("Invalid combination of arguments", log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 6
0
        public void ClientCertUpdatedCommand_Fail_NotConfigured()
        {
            var updatedPath     = "MyCertificateSecond.pfx";
            var updatedPassword = "******";

            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "update",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--path",
                    updatedPath,
                    "--password",
                    updatedPassword
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "does not exist";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 7
0
        public void ClientCertAddCommand_Fail_StoreCertificateNotExist()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "add",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--find-value",
                    "SOME"
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "was not found";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 8
0
        public void ClientCertRemoveCommand_Failed_NotExist()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "remove",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("There are no client certificates configured for", log.ShowMessages());

                testInfo.ValidateSettings();
            }
        }
Ejemplo n.º 9
0
        public void ClientCertUpdateCommand_Success_StoreCertificateForce()
        {
            var updatedStoreLocation = StoreLocation.CurrentUser;
            var updatedStoreName     = StoreName.AuthRoot;
            var updatedFindBy        = X509FindType.FindByCertificatePolicy;
            var updatedFindValue     = "SOMEUpdated";

            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupInitialItems(new StoreClientCertItem(testInfo.PackageSourceName,
                                                                   testInfo.CertificateFindValue.ToString(),
                                                                   testInfo.CertificateStoreLocation,
                                                                   testInfo.CertificateStoreName,
                                                                   testInfo.CertificateFindBy));
                var args = new[]
                {
                    "update",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--store-location",
                    updatedStoreLocation.ToString(),
                    "--store-name",
                    updatedStoreName.ToString(),
                    "--find-by",
                    updatedFindBy.ToString().Replace("FindBy", string.Empty),
                    "--find-value",
                    updatedFindValue,
                    "--force"
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("was successfully updated", log.ShowMessages());

                testInfo.ValidateSettings(new StoreClientCertItem(testInfo.PackageSourceName,
                                                                  updatedFindValue,
                                                                  updatedStoreLocation,
                                                                  updatedStoreName,
                                                                  updatedFindBy));
            }
        }
Ejemplo n.º 10
0
        public void ClientCertAddCommand_Fail_NoSourceSpecified()
        {
            // Arrange
            var args = new[] { "add", "client-cert" };

            var log = new TestCommandOutputLogger();

            // Act
            var exitCode = Program.MainInternal(args.ToArray(), log);

            // Assert
            var expectedError = "Property 'PackageSource' should not be null or empty";

            Assert.Contains(expectedError, log.ShowErrors());
            Assert.Equal(1, exitCode);
        }
Ejemplo n.º 11
0
        public async Task PushToServerWhichRejectsDuplicates_SkipDuplicate_Succeeds(PackageSource packageSource)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile    = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var logFirstPush  = new TestCommandOutputLogger();
                    var logSecondPush = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name);
                    Assert.False(string.IsNullOrEmpty(apiKey));
                    var pushArgs = new List <string>
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        packageSource.Source,
                        "--api-key",
                        apiKey,
                        "--skip-duplicate"
                    };

                    // Act
                    var exitCodeFirstPush  = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logFirstPush);
                    var exitCodeSecondPush = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logSecondPush);

                    // Assert First Push - it should happen without error.
                    var outputMessagesFirstPush = logFirstPush.ShowMessages();
                    Assert.Equal(string.Empty, logFirstPush.ShowErrors());
                    Assert.Equal(0, exitCodeFirstPush);

                    // Assert Second Push - it should happen without error, even though a duplicate is present.
                    var outputMessagesSecondPush = logSecondPush.ShowMessages();

                    Assert.Equal(string.Empty, logSecondPush.ShowErrors());
                    Assert.Equal(0, exitCodeSecondPush);
                    Assert.Contains($"PUT {packageSource.Source}", outputMessagesSecondPush);
                    Assert.DoesNotContain("already exists at feed", outputMessagesSecondPush);
                    Assert.Contains("Your package was pushed.", outputMessagesSecondPush);
                }
        }
Ejemplo n.º 12
0
        public void ClientCertUpdatedCommand_Fail_StoreCertificateNotExist()
        {
            var updatedStoreLocation = StoreLocation.CurrentUser;
            var updatedStoreName     = StoreName.My;
            var updatedFindBy        = X509FindType.FindByIssuerName;
            var updatedFindValue     = "SOMEUpdated";

            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupInitialItems(new StoreClientCertItem(testInfo.PackageSourceName,
                                                                   testInfo.CertificateFindValue.ToString(),
                                                                   testInfo.CertificateStoreLocation,
                                                                   testInfo.CertificateStoreName,
                                                                   testInfo.CertificateFindBy));

                var args = new[]
                {
                    "update",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--store-location",
                    updatedStoreLocation.ToString(),
                    "--store-name",
                    updatedStoreName.ToString(),
                    "--find-by",
                    updatedFindBy.ToString().Replace("FindBy", string.Empty),
                    "--find-value",
                    updatedFindValue
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "was not found";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 13
0
        public async Task PushToServerSkipDuplicateSucceeds(PackageSource packageSource)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var log        = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name);
                    Assert.False(string.IsNullOrEmpty(apiKey));

                    var pushArgs = new List <string>
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        packageSource.Source,
                        "--api-key",
                        apiKey,
                        "--skip-duplicate"
                    };

                    // Act
                    var exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log);

                    // Assert
                    var outputMessages = log.ShowMessages();

                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);
                    Assert.Contains($"PUT {packageSource.Source}", outputMessages);


                    //info: PUT http://localhost:5000/api/v2/package/
                    //info: Conflict http://localhost:5000/api/v2/package/ 127ms
                    Assert.Contains("already exists at feed", outputMessages);
                    Assert.Contains("Your package was pushed.", outputMessages);
                }
        }
Ejemplo n.º 14
0
        public void ClientCertAddCommand_Success_StoreCertificate()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupCertificateInStorage();

                var args = new[]
                {
                    "add",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--store-location",
                    testInfo.CertificateStoreLocation.ToString(),
                    "--store-name",
                    testInfo.CertificateStoreName.ToString(),
                    "--find-by",
                    testInfo.CertificateFindBy.ToString().Replace("FindBy", string.Empty),
                    "--find-value",
                    testInfo.CertificateFindValue.ToString()
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("was successfully added", log.ShowMessages());

                testInfo.ValidateSettings(new StoreClientCertItem(testInfo.PackageSourceName,
                                                                  testInfo.CertificateFindValue.ToString(),
                                                                  testInfo.CertificateStoreLocation,
                                                                  testInfo.CertificateStoreName,
                                                                  testInfo.CertificateFindBy));
            }
        }
Ejemplo n.º 15
0
        // [InlineData(TestServers.Klondike, nameof(TestServers.Klondike), false)] // 500 Internal Server Error pushing
        // [InlineData(TestServers.NuGetServer, nameof(TestServers.NuGetServer), false)] // 500 - missing manifest?
        public async Task PushToServerSucceeds(string sourceUri, string feedName, bool mustDeleteFirst)
        {
            // Arrange
            using (var packageDir = TestDirectory.Create())
                using (TestFileSystemUtility.SetCurrentDirectory(packageDir))
                {
                    var packageId      = "XPlatPushTests.PushToServerSucceeds";
                    var packageVersion = "1.0.0";
                    var packageFile    = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion);

                    var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir);
                    var log        = new TestCommandOutputLogger();

                    var apiKey = XPlatTestUtils.ReadApiKey(feedName);
                    Assert.False(string.IsNullOrEmpty(apiKey));

                    if (mustDeleteFirst)
                    {
                        DeletePackageBeforePush(packageId, packageVersion, sourceUri, apiKey);
                    }

                    var pushArgs = new List <string>()
                    {
                        "push",
                        packageFile.FullName,
                        "--source",
                        sourceUri,
                        "--api-key",
                        apiKey
                    };

                    // Act
                    int exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log);

                    // Assert
                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);
                    Assert.Contains($"PUT {sourceUri}", log.ShowMessages());
                    Assert.Contains("Your package was pushed.", log.ShowMessages());
                }
        }
Ejemplo n.º 16
0
        public void Restore_WithConfigFileInDifferentDirectory_Succeeds(string sourceUri)
        {
            using (var packagesDir = TestDirectory.Create())
                using (var projectDir = TestDirectory.Create())
                    using (var configDir = TestDirectory.Create())
                    {
                        var configFile = XPlatTestUtils.CopyFuncTestConfig(configDir);

                        var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                        var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                        XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3");
                        XPlatTestUtils.AddDependency(spec, "fody", "1.29.4");
                        XPlatTestUtils.WriteJson(spec, specPath);

                        var log = new TestCommandOutputLogger();

                        var args = new List <string>()
                        {
                            "restore",
                            projectDir,
                            "--packages",
                            packagesDir,
                            "--source",
                            sourceUri,
                            "--no-cache",
                            "--configfile",
                            configFile
                        };

                        // Act
                        int exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(args.ToArray(), log);

                        Assert.Contains($@"OK {sourceUri}/FindPackagesById()?id='fody'", log.ShowMessages());
                        Assert.Equal(string.Empty, log.ShowErrors());
                        Assert.Equal(0, exitCode);

                        var lockFilePath = Path.Combine(projectDir, "XPlatRestoreTests", "project.lock.json");
                        Assert.True(File.Exists(lockFilePath));
                    }
        }
Ejemplo n.º 17
0
        public void ClientCertUpdatedCommand_Fail_FileCertificateNotExist()
        {
            var updatedPath     = "MyCertificateSecond.pfx";
            var updatedPassword = "******";

            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName,
                                                                  testInfo.CertificateAbsoluteFilePath,
                                                                  testInfo.CertificatePassword,
                                                                  false,
                                                                  testInfo.ConfigFile));

                var args = new[]
                {
                    "update",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    testInfo.PackageSourceName,
                    "--path",
                    updatedPath,
                    "--password",
                    updatedPassword
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                var expectedError = "A fileCert path specified a file that does not exist";
                Assert.Contains(expectedError, log.ShowErrors());
                Assert.Equal(1, exitCode);
            }
        }
Ejemplo n.º 18
0
        public void BasicLogging_VerifyExceptionLoggedWhenVerbose()
        {
            // Arrange
            var log = new TestCommandOutputLogger(observeLogLevel: true);

            var args = new string[]
            {
                "--verbosity", "verbose",
                "--unknown",
            };

            // Act
            var exitCode = Program.MainInternal(args, log);

            // Assert
            Assert.Equal(1, exitCode);
            Assert.Equal(3, log.Messages.Count);
            Assert.Equal(1, log.Errors);
            Assert.Equal(0, log.Warnings);
            Assert.Contains("--unknown", log.ShowErrors());                          // error
            Assert.Contains("NuGet.CommandLine.XPlat.Program.", log.ShowMessages()); // verbose stack trace
        }
Ejemplo n.º 19
0
        public void BasicLogging_RestoreUnknownOption_ExitCode()
        {
            // Arrange
            var log = new TestCommandOutputLogger();

            var args = new string[]
            {
                "restore",
                "--unknown",
            };

            // Act
            var exitCode = Program.MainInternal(args, log);

            // Assert
            Assert.Equal(1, exitCode);
            Assert.Equal(3, log.Messages.Count);
            Assert.Equal(1, log.Errors);
            Assert.Equal(0, log.Warnings);
            Assert.Contains("--unknown", log.ShowErrors());                          // error
            Assert.Contains("NuGet.CommandLine.XPlat.Program.", log.ShowMessages()); // verbose stack trace
        }
Ejemplo n.º 20
0
        public void ClientCertAddCommand_Success_FileCertificateRelative()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupCertificateFile();

                var packageSource = testInfo.PackageSourceName;
                var path          = testInfo.CertificateRelativeFilePath;
                var password      = testInfo.CertificatePassword;

                var args = new[]
                {
                    "add",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile,
                    "--package-source",
                    packageSource,
                    "--path",
                    path,
                    "--password",
                    password
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("was successfully added", log.ShowMessages());

                testInfo.ValidateSettings(new FileClientCertItem(packageSource, path, password, false, testInfo.ConfigFile));
            }
        }
Ejemplo n.º 21
0
        public void ClientCertListCommand_Success_NotEmptyList()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName,
                                                                  testInfo.CertificateRelativeFilePath,
                                                                  testInfo.CertificatePassword,
                                                                  false,
                                                                  testInfo.ConfigFile),
                                           new StoreClientCertItem(testInfo.InvalidPackageSourceName,
                                                                   testInfo.CertificateFindValue.ToString(),
                                                                   testInfo.CertificateStoreLocation,
                                                                   testInfo.CertificateStoreName,
                                                                   testInfo.CertificateFindBy));

                var args = new[]
                {
                    "list",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                var showMessages = log.ShowMessages();
                Assert.Contains($"{testInfo.PackageSourceName} [{ConfigurationConstants.FileCertificate}]", showMessages);
                Assert.Contains($"{testInfo.InvalidPackageSourceName} [{ConfigurationConstants.StoreCertificate}]", showMessages);
            }
        }
Ejemplo n.º 22
0
        public async Task PushMultiplePathsToFileSystemSource()
        {
            using (var packageDirectory = TestDirectory.Create())
                using (var source = TestDirectory.Create())
                {
                    // Arrange
                    var log = new TestCommandOutputLogger();
                    var packageInfoCollection = new[]
                    {
                        await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageA", "1.1.0"),
                        await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageB", "1.1.0"),
                    };

                    var pushArgs = new List <string>
                    {
                        "push",
                        packageInfoCollection[0].FullName,
                        packageInfoCollection[1].FullName,
                        "--source",
                        source,
                    };

                    // Act
                    var exitCode = CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log);

                    // Assert
                    Assert.Equal(string.Empty, log.ShowErrors());
                    Assert.Equal(0, exitCode);

                    foreach (var packageInfo in packageInfoCollection)
                    {
                        Assert.Contains($"Pushing {packageInfo.Name}", log.ShowMessages());
                        Assert.True(File.Exists(Path.Combine(source, packageInfo.Name)));
                    }
                }
        }
Ejemplo n.º 23
0
        public void ClientCertListCommand_Success_EmptyList()
        {
            // Arrange
            using (var testInfo = new TestInfo())
            {
                var args = new[]
                {
                    "list",
                    "client-cert",
                    "--configfile",
                    testInfo.ConfigFile
                };

                var log = new TestCommandOutputLogger();

                // Act
                var exitCode = Program.MainInternal(args.ToArray(), log);

                // Assert
                Assert.Equal(string.Empty, log.ShowErrors());
                Assert.Equal(0, exitCode);
                Assert.Contains("There are no client certificates", log.ShowMessages());
            }
        }
Ejemplo n.º 24
0
        public async Task Restore_FallbackFolderDoesNotExist()
        {
            using (var sourceDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var fallbackDir1 = TestFileSystemUtility.CreateRandomTestFolder())
                    using (var fallbackDir2 = TestFileSystemUtility.CreateRandomTestFolder())
                        using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                            using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                            {
                                var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json");
                                var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                                XPlatTestUtils.AddDependency(spec, "a", "1.0.0");
                                XPlatTestUtils.AddDependency(spec, "b", "1.0.0");
                                XPlatTestUtils.WriteJson(spec, specPath);

                                var packageA = new SimpleTestPackageContext("a", "1.0.0");
                                var packageB = new SimpleTestPackageContext("b", "1.0.0");

                                var saveMode = PackageSaveMode.Nuspec | PackageSaveMode.Files;

                                await SimpleTestPackageUtility.CreateFolderFeedV3(
                                    fallbackDir2,
                                    saveMode,
                                    packageA,
                                    packageB);

                                Directory.Delete(fallbackDir1);

                                var log = new TestCommandOutputLogger();

                                var config = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <config>
        <add key=""globalPackagesFolder"" value=""{packagesDir}"" />
    </config>
    <fallbackPackageFolders>
        <add key=""a"" value=""{fallbackDir1}"" />
        <add key=""b"" value=""{fallbackDir2}"" />
    </fallbackPackageFolders>
    <packageSources>
        <add key=""a"" value=""{sourceDir}"" />
    </packageSources>
</configuration>";

                                File.WriteAllText(Path.Combine(projectDir, "NuGet.Config"), config);

                                var args = new string[]
                                {
                                    "restore",
                                    projectDir,
                                };

                                // Act
                                var exitCode = Program.MainInternal(args, log);

                                // Assert
                                Assert.Equal(1, exitCode);
                                Assert.Equal(1, log.Errors);
                                Assert.Contains(fallbackDir1, log.ShowErrors());
                            }
        }