public void TestVerbosityQuiet_DoesNotShowInfoMessages() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var nugetexe = Util.GetNuGetExePath(); var args = new string[] { "sources", "Add", "-Name", "test_source", "-Source", "http://test_source", "-Verbosity", "Quiet" }; var root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory // And, will fail since global nuget.config is updated var result = CommandRunner.Run(nugetexe, root, string.Join(" ", args), true); // Assert Util.VerifyResultSuccess(result); // Ensure that no messages are shown with Verbosity as Quiet Assert.Equal(string.Empty, result.Item2); var settings = Configuration.Settings.LoadDefaultSettings(null, null, null); var packageSourcesSection = settings.GetSection("packageSources"); var sourceItem = packageSourcesSection?.GetFirstItemWithAttribute <SourceItem>("key", "test_source"); Assert.Equal("http://test_source", sourceItem.GetValueAsPath()); } }
public void SourcesCommandTest_AddSource() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var nugetexe = Util.GetNuGetExePath(); var args = new string[] { "sources", "Add", "-Name", "test_source", "-Source", "http://test_source" }; var root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory // And, will fail since global nuget.config is updated var result = CommandRunner.Run(nugetexe, root, string.Join(" ", args), true); // Assert Assert.Equal(0, result.Item1); var settings = Configuration.Settings.LoadDefaultSettings(null, null, null); var packageSourcesSection = settings.GetSection("packageSources"); var sourceItem = packageSourcesSection?.GetFirstItemWithAttribute <SourceItem>("key", "test_source"); Assert.Equal("http://test_source", sourceItem.GetValueAsPath()); } }
public void SourcesCommandTest_AddWithUserNamePassword() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var nugetexe = Util.GetNuGetExePath(); var args = new string[] { "sources", "Add", "-Name", "test_source", "-Source", "http://test_source", "-UserName", "test_user_name", "-Password", "test_password" }; var root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory // And, will fail since global nuget.config is updated var result = CommandRunner.Run(nugetexe, root, string.Join(" ", args), true); // Assert Assert.True(0 == result.Item1, result.Item2 + " " + result.Item3); var settings = Configuration.Settings.LoadDefaultSettings(null, null, null); var packageSourcesSection = settings.GetSection("packageSources"); var sourceItem = packageSourcesSection?.GetFirstItemWithAttribute <SourceItem>("key", "test_source"); Assert.Equal("http://test_source", sourceItem.GetValueAsPath()); var sourceCredentialsSection = settings.GetSection("packageSourceCredentials"); var credentialItem = sourceCredentialsSection?.Items.First(c => string.Equals(c.ElementName, "test_source", StringComparison.OrdinalIgnoreCase)) as CredentialsItem; Assert.NotNull(credentialItem); Assert.Equal("test_user_name", credentialItem.Username); var password = Configuration.EncryptionUtility.DecryptString(credentialItem.Password); Assert.Equal("test_password", password); } }
public void SourcesCommandTest_AddWithUserNamePasswordInClearText() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var nugetexe = Util.GetNuGetExePath(); var args = new string[] { "sources", "Add", "-Name", "test_source", "-Source", "http://test_source", "-UserName", "test_user_name", "-Password", "test_password", "-StorePasswordInClearText" }; string root = Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory // And, will fail since global nuget.config is updated var result = CommandRunner.Run(nugetexe, root, string.Join(" ", args), true); // Assert Assert.True(0 == result.Item1, result.Item2 + " " + result.Item3); var settings = Configuration.Settings.LoadDefaultSettings(null, null, null); var source = settings.GetValue("packageSources", "test_source"); Assert.Equal("http://test_source", source); var credentials = settings.GetNestedValues( "packageSourceCredentials", "test_source"); Assert.Equal(2, credentials.Count); Assert.Equal("Username", credentials[0].Key); Assert.Equal("test_user_name", credentials[0].Value); Assert.Equal("ClearTextPassword", credentials[1].Key); Assert.Equal("test_password", credentials[1].Value); } }
public void SourcesCommandTest_AddWithUserNamePassword() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var nugetexe = Util.GetNuGetExePath(); string[] args = new string[] { "sources", "Add", "-Name", "test_source", "-Source", "http://test_source", "-UserName", "test_user_name", "-Password", "test_password" }; // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory // And, will fail since global nuget.config is updated var result = CommandRunner.Run(nugetexe, @"c:\", string.Join(" ", args), true); // Assert Assert.Equal(0, result.Item1); var settings = Configuration.Settings.LoadDefaultSettings(null, null, null); var source = settings.GetValue("packageSources", "test_source"); Assert.Equal("http://test_source", source); var credentials = settings.GetNestedValues( "packageSourceCredentials", "test_source"); Assert.Equal(2, credentials.Count); Assert.Equal("Username", credentials[0].Key); Assert.Equal("test_user_name", credentials[0].Value); Assert.Equal("Password", credentials[1].Key); var password = Configuration.EncryptionUtility.DecryptString(credentials[1].Value); Assert.Equal("test_password", password); } }
public void ConfigCommand_ChangeDefaultConfigFile() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange var args = new string[] { "config", "-Set", "Name1=Value1", "-Set", "HTTP_PROXY=http://127.0.0.1", "-Set", @"HTTP_PROXY.USER=domain\user" }; var root = RuntimeEnvironmentHelper.IsMono && !RuntimeEnvironmentHelper.IsWindows ? Environment.GetEnvironmentVariable("HOME") : @"c:\"; // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory var result = Program.MainCore(root, args); // Assert Assert.Equal(0, result); var settings = Configuration.Settings.LoadDefaultSettings( root, null, null); var configSection = settings.GetSection("config"); var values = configSection?.Items.Select(c => c as AddItem).Where(c => c != null).ToList(); AssertEqualCollections(values, new[] { "Name1", "Value1", "HTTP_PROXY", "http://127.0.0.1", "HTTP_PROXY.USER", @"domain\user" }); } }
public void ConfigCommand_ChangeDefaultConfigFile() { using (var preserver = new DefaultConfigurationFilePreserver()) { // Arrange string[] args = new string[] { "config", "-Set", "Name1=Value1", "-Set", "HTTP_PROXY=http://127.0.0.1", "-Set", @"HTTP_PROXY.USER=domain\user" }; // Act // Set the working directory to C:\, otherwise, // the test will change the nuget.config at the code repo's root directory int result = Program.MainCore(@"c:\", args); // Assert Assert.Equal(0, result); var settings = Configuration.Settings.LoadDefaultSettings( @"c:\", null, null); var values = settings.GetSettingValues("config", isPath: false); AssertEqualCollections(values, new[] { "Name1", "Value1", "HTTP_PROXY", "http://127.0.0.1", "HTTP_PROXY.USER", @"domain\user" }); } }