public void RestoreCommand_VerifyMinClientVersionV3Source()
        {
            // Arrange
            using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var specPath = Path.Combine(projectDir, "TestProject", "project.json");
                    var spec     = XPlatTestUtils.BasicConfigNetCoreApp;

                    // This package has a minclientversion of 9999
                    XPlatTestUtils.AddDependency(spec, "TestPackage.MinClientVersion", "1.0.0");
                    XPlatTestUtils.WriteJson(spec, specPath);

                    var lockFilePath = Path.Combine(projectDir, "project.lock.json");
                    var log          = new TestCommandOutputLogger();

                    var args = new string[]
                    {
                        "restore",
                        projectDir,
                        "-s",
                        "https://api.nuget.org/v3/index.json",
                        "--packages",
                        packagesDir
                    };

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

                    // Assert
                    Assert.Equal(1, log.Errors);
                    Assert.Contains("'TestPackage.MinClientVersion 1.0.0' package requires NuGet client version '9.9999.0' or above", log.ShowMessages());
                    Assert.False(File.Exists(lockFilePath));
                }
        }
示例#2
0
        public void BasicListPackageParsing_InteractiveTakesNoArguments()
        {
            // Arrange
            var projectPath = Path.Combine(Path.GetTempPath(), "project.csproj");

            File.Create(projectPath).Dispose();


            var argList = new List <string>()
            {
                "list",
                "--interactive",
                "no",
                projectPath
            };

            var logger            = new TestCommandOutputLogger();
            var testApp           = new CommandLineApplication();
            var mockCommandRunner = new Mock <IListPackageCommandRunner>();

            mockCommandRunner
            .Setup(m => m.ExecuteCommandAsync(It.IsAny <ListPackageArgs>()))
            .Returns(Task.CompletedTask);

            testApp.Name = "dotnet nuget_test";
            ListPackageCommand.Register(testApp,
                                        () => logger,
                                        () => mockCommandRunner.Object);

            // Act
            Assert.Throws <CommandParsingException>(() => testApp.Execute(argList.ToArray()));
        }
示例#3
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);
            }
        }
示例#4
0
        public static PackageReferenceArgs GetPackageReferenceArgs(string packageId, SimpleTestProjectContext project)
        {
            var logger            = new TestCommandOutputLogger();
            var packageDependency = new PackageDependency(packageId);

            return(new PackageReferenceArgs(project.ProjectPath, packageDependency, logger));
        }
示例#5
0
        /// <summary>
        /// This is called when the package must be deleted before being pushed. It's ok if this
        /// fails, maybe the package was never pushed.
        /// </summary>
        private static void DeletePackageBeforePush(string packageId, string packageVersion, string sourceUri, string apiKey)
        {
            var packageUri = $"{sourceUri}/{packageId}/{packageVersion}";
            var log        = new TestCommandOutputLogger();
            var args       = new List <string>()
            {
                "delete",
                packageId,
                packageVersion,
                "--source",
                sourceUri,
                "--api-key",
                apiKey,
                "--non-interactive"
            };

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

            Assert.InRange(exitCode, 0, 1);

            Assert.Contains($"DELETE {packageUri}", log.ShowMessages());

            if (exitCode == 0)
            {
                Assert.Contains($"OK {packageUri}", log.ShowMessages());
            }
            else
            {
                Assert.Contains($"NotFound {packageUri}", log.ShowMessages());
            }
        }
示例#6
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);
            }
        }
示例#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);
            }
        }
示例#8
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();
            }
        }
示例#9
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();
            }
        }
示例#10
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);
            }
        }
示例#11
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);
            }
        }
示例#12
0
        private void VerifyCommand(Action <string, Mock <IListPackageCommandRunner>, CommandLineApplication, Func <LogLevel> > verify)
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var projectPath = Path.Combine(testDirectory, "project.csproj");
                File.WriteAllText(projectPath, string.Empty);

                var logLevel          = LogLevel.Information;
                var logger            = new TestCommandOutputLogger();
                var testApp           = new CommandLineApplication();
                var mockCommandRunner = new Mock <IListPackageCommandRunner>();
                mockCommandRunner
                .Setup(m => m.ExecuteCommandAsync(It.IsAny <ListPackageArgs>()))
                .Returns(Task.CompletedTask);

                testApp.Name = "dotnet nuget_test";
                ListPackageCommand.Register(testApp,
                                            () => logger,
                                            ll => logLevel = ll,
                                            () => mockCommandRunner.Object);

                // Act & Assert
                try
                {
                    verify(projectPath, mockCommandRunner, testApp, () => logLevel);
                }
                finally
                {
                    XPlatTestUtils.DisposeTemporaryFile(projectPath);
                }
            }
        }
示例#13
0
        public async Task Restore_FallbackFolderContainsAllPackages()
        {
            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);

                                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(0, exitCode);
                                Assert.Equal(0, log.Errors);
                                Assert.Equal(0, log.Warnings);
                                Assert.Equal(0, Directory.GetDirectories(packagesDir).Length);
                            }
        }
示例#14
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
                }
        }
示例#15
0
        internal static PackageReferenceArgs GetPackageReferenceArgs(string packageId, SimpleTestProjectContext project)
        {
            var logger = new TestCommandOutputLogger();

            return(new PackageReferenceArgs(project.ProjectPath, logger)
            {
                PackageId = packageId
            });
        }
示例#16
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));
            }
        }
示例#17
0
        private void TrustCommandArgs(Action <CommandLineApplication, Func <LogLevel> > verify)
        {
            // Arrange
            var logLevel = LogLevel.Information;
            var logger   = new TestCommandOutputLogger();
            var testApp  = new CommandLineApplication();

            testApp.Name = "dotnet nuget_test";
            TrustedSignersCommand.Register(testApp,
                                           () => logger,
                                           ll => logLevel = ll);

            // Act & Assert
            verify(testApp, () => logLevel);
        }
示例#18
0
        public void BasicLogging_NoParams_ExitCode()
        {
            // Arrange
            var log = new TestCommandOutputLogger();

            var args = new string[]
            {
                //empty
            };

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

            // Assert
            Assert.Equal(0, exitCode);
        }
示例#19
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);
        }
示例#20
0
        public void BasicLogging_RestoreHelp_ExitCode()
        {
            // Arrange
            var log = new TestCommandOutputLogger();

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

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

            // Assert
            Assert.Equal(0, exitCode);
        }
示例#21
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);
                }
        }
示例#22
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);
            }
        }
示例#23
0
        public void RestoreCommand_VerifyMinClientVersionLocalFolder()
        {
            // Arrange
            using (var sourceDir = TestFileSystemUtility.CreateRandomTestFolder())
                using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder())
                    using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder())
                    {
                        var packageContext = new SimpleTestPackageContext()
                        {
                            Id               = "packageA",
                            Version          = "1.0.0",
                            MinClientVersion = "9.9.9"
                        };

                        SimpleTestPackageUtility.CreatePackages(sourceDir, packageContext);

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

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

                        var lockFilePath = Path.Combine(projectDir, "project.lock.json");
                        var log          = new TestCommandOutputLogger();

                        var args = new string[]
                        {
                            "restore",
                            projectDir,
                            "-s",
                            sourceDir,
                            "--packages",
                            packagesDir
                        };

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

                        // Assert
                        Assert.Equal(1, log.Errors);
                        Assert.Contains("'packageA 1.0.0' package requires NuGet client version '9.9.9' or above", log.ShowMessages());
                        Assert.False(File.Exists(lockFilePath));
                    }
        }
示例#24
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);
                }
        }
示例#25
0
        public void BasicLogging_RestoreVerbosityDefaultsToGlobalVerbosity()
        {
            // Arrange
            var log = new TestCommandOutputLogger(observeLogLevel: true);

            var args = new string[]
            {
                "--verbosity", "verbose",         // Set the verbosity at a global level.
                "restore",
                "--configfile", "MyNuGet.config", // Cause a failure since we don't want a real restore to happen.
                "--disable-parallel",             // Generate a verbose level log.
            };

            // Act
            Program.MainInternal(args, log);

            // Assert
            Assert.Contains("Running non-parallel restore.", log.ShowMessages());
        }
        public void AddPkg_RemoveParsing(string packageOption, string package,
                                         string projectOption, string project)
        {
            // Arrange
            using (var testDirectory = TestDirectory.Create())
            {
                var projectPath = Path.Combine(testDirectory, project);
                File.Create(projectPath).Dispose();
                var argList = new List <string>()
                {
                    "remove",
                    packageOption,
                    package,
                    projectOption,
                    projectPath
                };

                var logger            = new TestCommandOutputLogger();
                var testApp           = new CommandLineApplication();
                var mockCommandRunner = new Mock <IPackageReferenceCommandRunner>();
                mockCommandRunner
                .Setup(m => m.ExecuteCommand(It.IsAny <PackageReferenceArgs>(), It.IsAny <MSBuildAPIUtility>()))
                .ReturnsAsync(0);

                testApp.Name = "dotnet nuget_test";
                RemovePackageReferenceCommand.Register(testApp,
                                                       () => logger,
                                                       () => mockCommandRunner.Object);

                // Act
                var result = testApp.Execute(argList.ToArray());

                XPlatTestUtils.DisposeTemporaryFile(projectPath);

                // Assert
                mockCommandRunner.Verify(m => m.ExecuteCommand(It.Is <PackageReferenceArgs>(p =>
                                                                                            p.PackageId == package &&
                                                                                            p.ProjectPath == projectPath),
                                                               It.IsAny <MSBuildAPIUtility>()));

                Assert.Equal(0, result);
            }
        }
示例#27
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));
            }
        }
示例#28
0
        public void BasicLogging_VersionHeading()
        {
            // Arrange
            var log = new TestCommandOutputLogger(observeLogLevel: true);

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

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

            // Assert
            Assert.Equal(0, exitCode);
            Assert.Equal(1, log.VerboseMessages.Count);
            Assert.Equal(1, log.Messages.Count);
            Assert.Contains("NuGet Command Line Version:", log.ShowMessages());
        }
示例#29
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));
                    }
        }
示例#30
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());
                }
        }