Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing a key using CLI now actually saves changes to nuget.config #4080

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,33 @@ public void DeleteConfigValue_WithNullSettings_Throws()
ex.Should().BeOfType<ArgumentNullException>();
}

[Fact]
public void DeleteConfigValue_WithValidSettings_DeletesKey()
{
// Arrange
var keyName = "dependencyVersion";
var nugetConfigPath = "NuGet.Config";
var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<config>
<add key=""" + keyName + @""" value=""Highest"" />
</config>
</configuration>";
Copy link
Contributor

@erdembayar erdembayar May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            var config = $@"
<configuration>
    <config>
        <add key=""{keyName}"" value=""Highest"" />
    </config>
</configuration>";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually agree that this is easier to read, but in recent PR reviews, I've learned it's worse performance. Since this is a test, perf isn't really critical here, and it's probably negligible anyway, but I don't see enough value to rerun CI since it's already green.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the compiler has improvements I don't know about, interpolated strings (strings starting with $) are syntactic sugar for string.Format, which has much slower runtime performance than string.Concat (which operator +(string a, string b) is syntactic sugar for).

This is a test, so it's not a perf-critical hot-path. But, unless you find concatenated strings much less readable than interpolated strings, I think it's fine as-is.


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()
{
Expand Down