From eac18b8284d180cba1f9166bf01ed6e28f735767 Mon Sep 17 00:00:00 2001 From: Donnie Goodson Date: Fri, 28 May 2021 13:00:42 -0700 Subject: [PATCH 1/2] Removing key saves to disk --- .../NuGet.CommandLine.csproj | 2 +- .../Utility/SettingsUtility.cs | 1 + .../SettingsUtilityTests.cs | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj b/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj index 008a954d55e..32d1638a661 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj +++ b/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj @@ -1,4 +1,4 @@ - + true diff --git a/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs b/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs index a94bc096b3e..8540dfdc4a8 100644 --- a/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs +++ b/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs @@ -55,6 +55,7 @@ public static bool DeleteValue(ISettings settings, string section, string attrib if (element != null) { settings.Remove(section, element); + settings.SaveToDisk(); return true; } diff --git a/test/NuGet.Core.Tests/NuGet.Configuration.Test/SettingsUtilityTests.cs b/test/NuGet.Core.Tests/NuGet.Configuration.Test/SettingsUtilityTests.cs index 0a053cdee45..860b08b3f04 100644 --- a/test/NuGet.Core.Tests/NuGet.Configuration.Test/SettingsUtilityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Configuration.Test/SettingsUtilityTests.cs @@ -254,6 +254,33 @@ public void DeleteConfigValue_WithNullSettings_Throws() ex.Should().BeOfType(); } + [Fact] + public void DeleteConfigValue_WithValidSettings_DeletesKey() + { + // Arrange + var keyName = "dependencyVersion"; + var nugetConfigPath = "NuGet.Config"; + var config = @" + + + + +"; + + using (var mockBaseDirectory = TestDirectory.Create()) + { + SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); + var settings = new Settings(mockBaseDirectory); + + // Act + SettingsUtility.DeleteConfigValue(settings, keyName); + + // Assert + var content = File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath)); + content.Should().NotContain(keyName); + } + } + [Fact] public void GetGlobalPackagesFolder_WithNullSettings_Throws() { From 7500c005e5a8c7278cb0926b82d2973bc6fe20e5 Mon Sep 17 00:00:00 2001 From: Donnie Goodson Date: Fri, 28 May 2021 13:18:54 -0700 Subject: [PATCH 2/2] remove proj file change --- src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj b/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj index 32d1638a661..008a954d55e 100644 --- a/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj +++ b/src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj @@ -1,4 +1,4 @@ - + true