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)); } }
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())); }
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); } }
public static PackageReferenceArgs GetPackageReferenceArgs(string packageId, SimpleTestProjectContext project) { var logger = new TestCommandOutputLogger(); var packageDependency = new PackageDependency(packageId); return(new PackageReferenceArgs(project.ProjectPath, packageDependency, logger)); }
/// <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()); } }
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); } }
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); } }
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(); } }
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(); } }
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); } }
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); } }
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); } } }
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); } }
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 } }
internal static PackageReferenceArgs GetPackageReferenceArgs(string packageId, SimpleTestProjectContext project) { var logger = new TestCommandOutputLogger(); return(new PackageReferenceArgs(project.ProjectPath, logger) { PackageId = packageId }); }
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)); } }
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); }
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); }
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); }
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); }
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); } }
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); } }
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)); } }
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); } }
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); } }
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)); } }
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()); }
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)); } }
// [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()); } }