-
Notifications
You must be signed in to change notification settings - Fork 689
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
Create tracking file when user-profile nuget.config does not exist #4338
Changes from all commits
b487a39
16176e5
e2db0d2
a3db7a4
b582ea7
abcb5b0
ff4c17b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2021,63 +2021,95 @@ public void LoadDefaultSettings_WithUserSpecifiedConfigFile_IgnoresOtherSettings | |
} | ||
|
||
[Fact] | ||
public void LoadSettings_EmptyUserWideConfigFile_DoNotAddNuGetOrg() | ||
public void LoadSettings_UserSettingsFolderDoesNotExist_DefaultNuGetConfigAndTrackingFilesCreated() | ||
{ | ||
using (var mockBaseDirectory = TestDirectory.Create()) | ||
{ | ||
// Arrange | ||
var config = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
// Arrange | ||
using TestDirectory mockSolutionDirectory = TestDirectory.Create(); | ||
// Settings.LoadSettings' useTestingGlobalPath will use a subdirectory, instead of machine configuration, to allow for testing. | ||
string mockUserProfileDirectory = Path.Combine(mockSolutionDirectory, "TestingGlobalPath"); | ||
|
||
// Act | ||
ISettings settings = Settings.LoadSettings( | ||
root: mockSolutionDirectory, | ||
configFileName: null, | ||
machineWideSettings: null, | ||
loadUserWideSettings: true, | ||
useTestingGlobalPath: true); | ||
|
||
// Assert | ||
|
||
// Check that the config file has the expected contents | ||
string actual = SettingsTestUtils.RemoveWhitespace(File.ReadAllText(Path.Combine(mockUserProfileDirectory, "NuGet.Config"))); | ||
string expected = SettingsTestUtils.RemoveWhitespace(NuGetConstants.DefaultConfigContent); | ||
actual.Should().Be(expected); | ||
|
||
// Check that the tracking file exists, so that nuget.org won't be re-added if the customer removes it. | ||
Assert.True(File.Exists(Path.Combine(mockUserProfileDirectory, NuGetConstants.V3TrackFile))); | ||
} | ||
|
||
[Fact] | ||
public void LoadSettings_UserNuGetConfigIsEmptyWithoutTrackingFile_NuGetOrgSourceAddedAndTrackingFileCreated() | ||
{ | ||
// Arrange | ||
using TestDirectory mockSolutionDirectory = TestDirectory.Create(); | ||
// Settings.LoadSettings' useTestingGlobalPath will use a subdirectory, instead of machine configuration, to allow for testing. | ||
string mockUserProfileDirectory = Path.Combine(mockSolutionDirectory, "TestingGlobalPath"); | ||
|
||
string emptyConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<configuration> | ||
</configuration>"; | ||
|
||
var nugetConfigPath = "NuGet.Config"; | ||
SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, Path.Combine(mockBaseDirectory, "TestingGlobalPath"), config); | ||
string nugetConfigPath = "NuGet.Config"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literals should be implicit types |
||
SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockUserProfileDirectory, emptyConfig); | ||
|
||
// Act | ||
var settings = Settings.LoadSettings( | ||
root: mockBaseDirectory, | ||
configFileName: null, | ||
machineWideSettings: null, | ||
loadUserWideSettings: true, | ||
useTestingGlobalPath: true); | ||
// Act | ||
ISettings settings = Settings.LoadSettings( | ||
root: mockSolutionDirectory, | ||
configFileName: null, | ||
machineWideSettings: null, | ||
loadUserWideSettings: true, | ||
useTestingGlobalPath: true); | ||
|
||
// Assert | ||
var actual = SettingsTestUtils.RemoveWhitespace(File.ReadAllText(Path.Combine(mockBaseDirectory, "TestingGlobalPath", "NuGet.Config"))); | ||
var expected = SettingsTestUtils.RemoveWhitespace(config); | ||
// Assert | ||
// Check that the config file has the expected contents | ||
string actual = SettingsTestUtils.RemoveWhitespace(File.ReadAllText(Path.Combine(mockUserProfileDirectory, "NuGet.Config"))); | ||
string expected = SettingsTestUtils.RemoveWhitespace(NuGetConstants.DefaultConfigContent); | ||
actual.Should().Be(expected); | ||
|
||
actual.Should().Be(expected); | ||
} | ||
// Check that the tracking file exists, so that nuget.org won't be re-added if the customer removes it. | ||
Assert.True(File.Exists(Path.Combine(mockUserProfileDirectory, NuGetConstants.V3TrackFile))); | ||
} | ||
|
||
[Fact] | ||
public void LoadSettings_NonExistingUserWideConfigFile_CreateUserWideConfigFileWithNuGetOrg() | ||
public void LoadSettings_UserNuGetConfigIsEmptyAndTrackingFileExists_ConfigFileNotModified() | ||
{ | ||
using (var mockBaseDirectory = TestDirectory.Create()) | ||
{ | ||
// Arrange | ||
var nugetConfigPath = Path.Combine(mockBaseDirectory, "TestingGlobalPath", "NuGet.Config"); | ||
File.Exists(nugetConfigPath).Should().BeFalse(); | ||
|
||
// Act | ||
var settings = Settings.LoadSettings( | ||
root: mockBaseDirectory, | ||
configFileName: null, | ||
machineWideSettings: null, | ||
loadUserWideSettings: true, | ||
useTestingGlobalPath: true); | ||
// Arrange | ||
using TestDirectory mockSolutionDirectory = TestDirectory.Create(); | ||
// Settings.LoadSettings' useTestingGlobalPath will use a subdirectory, instead of machine configuration, to allow for testing. | ||
string mockUserProfileDirectory = Path.Combine(mockSolutionDirectory, "TestingGlobalPath"); | ||
|
||
// Assert | ||
File.Exists(nugetConfigPath).Should().BeTrue(); | ||
var actual = SettingsTestUtils.RemoveWhitespace(File.ReadAllText(nugetConfigPath)); | ||
var expected = SettingsTestUtils.RemoveWhitespace(@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
string emptyConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literals should be implicit types |
||
<configuration> | ||
<packageSources> | ||
<add key=""nuget.org"" value=""https://api.nuget.org/v3/index.json"" protocolVersion=""3"" /> | ||
</packageSources> | ||
</configuration>"); | ||
</configuration>"; | ||
|
||
actual.Should().Be(expected); | ||
} | ||
string nugetConfigPath = "NuGet.Config"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Literals should be implicit types |
||
SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockUserProfileDirectory, emptyConfig); | ||
|
||
File.WriteAllText(Path.Combine(mockUserProfileDirectory, NuGetConstants.V3TrackFile), string.Empty); | ||
|
||
// Act | ||
ISettings settings = Settings.LoadSettings( | ||
root: mockSolutionDirectory, | ||
configFileName: null, | ||
machineWideSettings: null, | ||
loadUserWideSettings: true, | ||
useTestingGlobalPath: true); | ||
|
||
// Assert | ||
// Check that the config file has the expected contents | ||
string actual = SettingsTestUtils.RemoveWhitespace(File.ReadAllText(Path.Combine(mockUserProfileDirectory, "NuGet.Config"))); | ||
string expected = SettingsTestUtils.RemoveWhitespace(emptyConfig); | ||
actual.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literals should be implicit types