public void CredentialsItem_Parsing_WithMultipleValidAuthenticationTypes_TakesFirstAndIgnoresRest() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <packageSourceCredentials> <NuGet.Org meta1='data1'> <add key='Username' value='username' /> <add key='Password' value='password' /> <add key='ValidAuthenticationTypes' value='one,two,three' /> <add key='ValidAuthenticationTypes' value='four,five,six' /> </NuGet.Org> </packageSourceCredentials> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("packageSourceCredentials"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First() as CredentialsItem; item.Should().NotBeNull(); item.ValidAuthenticationTypes.Should().Be("one,two,three"); } }
public void SettingsFile_ConnectSettingsFilesLinkedList_ConnectsConfigsCorrectly() { // Arrange var configFile = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) using (var mockSubDirectory = TestDirectory.Create(mockBaseDirectory)) using (var mockSubSubDirectory = TestDirectory.Create(mockSubDirectory)) { ConfigurationFileTestUtility.CreateConfigurationFile(configFile, mockBaseDirectory, @"<configuration></configuration>"); ConfigurationFileTestUtility.CreateConfigurationFile(configFile, mockSubDirectory, @"<configuration></configuration>"); ConfigurationFileTestUtility.CreateConfigurationFile(configFile, mockSubSubDirectory, @"<configuration></configuration>"); var baseSettingsFile = new SettingsFile(mockBaseDirectory); var subSettingsFile = new SettingsFile(mockSubDirectory); var subSubSettingsFile = new SettingsFile(mockSubSubDirectory); // Act & Assert baseSettingsFile.Should().NotBeNull(); subSettingsFile.Should().NotBeNull(); subSubSettingsFile.Should().NotBeNull(); SettingsFile.ConnectSettingsFilesLinkedList(new List <SettingsFile>() { baseSettingsFile, subSettingsFile, subSubSettingsFile }); subSubSettingsFile.Next.Should().BeSameAs(subSettingsFile); subSettingsFile.Next.Should().BeSameAs(baseSettingsFile); baseSettingsFile.Next.Should().BeNull(); } }
public void SettingsFile_Constructor_ConfigurationPath_Succeds() { // Arrange var configFile = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { var config = @" <configuration> <SectionName> <add key='key1' value='value1' /> <add key='key2' value='value2' /> </SectionName> </configuration>"; ConfigurationFileTestUtility.CreateConfigurationFile(configFile, mockBaseDirectory, config); // Act var settingsFile = new SettingsFile(mockBaseDirectory); // Assert var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); var key1Element = section.GetFirstItemWithAttribute <AddItem>("key", "key1"); var key2Element = section.GetFirstItemWithAttribute <AddItem>("key", "key2"); key1Element.Should().NotBeNull(); key2Element.Should().NotBeNull(); key1Element.Value.Should().Be("value1"); key2Element.Value.Should().Be("value2"); } }
public void SettingsFile_AddOrUpdate_SectionThatExist_WillAddToSection() { // Arrange var configFile = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { var config = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <SectionName> <add key=""key"" value=""value"" /> </SectionName> </configuration>"; ConfigurationFileTestUtility.CreateConfigurationFile(configFile, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act settingsFile.AddOrUpdate("SectionName", new AddItem("keyTwo", "valueTwo")); settingsFile.SaveToDisk(); // Assert var result = ConfigurationFileTestUtility.RemoveWhitespace(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <SectionName> <add key=""key"" value=""value"" /> <add key=""keyTwo"" value=""valueTwo"" /> </SectionName> </configuration>"); ConfigurationFileTestUtility.RemoveWhitespace(File.ReadAllText(Path.Combine(mockBaseDirectory, configFile))).Should().Be(result); } }
public void SettingsFile_Remove_LastValueInSection_RemovesSection() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <SectionName> <add key=""DeleteMe"" value=""value2"" /> </SectionName> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(Path.Combine(mockBaseDirectory)); // Act & Assert var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); var item = section.GetFirstItemWithAttribute <AddItem>("key", "DeleteMe"); item.Should().NotBeNull(); item.Value.Should().Be("value2"); settingsFile.Remove("SectionName", item); settingsFile.SaveToDisk(); ConfigurationFileTestUtility.RemoveWhitespace(File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath))).Should().Be(ConfigurationFileTestUtility.RemoveWhitespace(@"<?xml version=""1.0"" encoding=""utf-8""?><configuration></configuration>")); section = settingsFile.GetSection("SectionName"); section.Should().BeNull(); } }
public void GetFallbackPackageFolders_MultipleFoldersFromNuGetConfig() { // Arrange var config = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""d"" value=""C:\Temp\d"" /> <add key=""b"" value=""C:\Temp\b"" /> <add key=""c"" value=""C:\Temp\c"" /> </fallbackPackageFolders> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); Settings settings = new Settings(mockBaseDirectory); // Act var paths = SettingsUtility.GetFallbackPackageFolders(settings).ToArray(); // Assert Assert.Equal(3, paths.Length); Assert.Equal("d", GetFileName(paths[0])); Assert.Equal("b", GetFileName(paths[1])); Assert.Equal("c", GetFileName(paths[2])); } }
public void SettingsFile_AddOrUpdate_WithMachineWideSettings_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key0' value='value0' /> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var configFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); var settingsFile = new SettingsFile(mockBaseDirectory, nugetConfigPath, isMachineWide: true); // Act var ex = Record.Exception(() => settingsFile.AddOrUpdate("section", new AddItem("SomeKey", "SomeValue"))); ex.Should().NotBeNull(); ex.Should().BeOfType <InvalidOperationException>(); ex.Message.Should().Be("Unable to update setting since it is in a machine-wide NuGet.Config."); settingsFile.SaveToDisk(); var section = settingsFile.GetSection("Section"); section.Items.Count.Should().Be(1); var updatedFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); updatedFileHash.Should().BeEquivalentTo(configFileHash); } }
public void ClearItem_CaseInsensitive_ParsedSuccessfully() { // Arrange var config = @" <configuration> <section> <clEaR /> </section> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("section"); section.Should().NotBeNull(); var children = section.Items.ToList(); children.Should().NotBeEmpty(); children.Count.Should().Be(1); children[0].Should().BeOfType <ClearItem>(); } }
public void ClearItem_MultiTag_ParsedSuccessfully() { // Arrange var config = @" <configuration> <SectionName> <clear></clear> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); section.Items.FirstOrDefault().Should().BeOfType <ClearItem>(); } }
public void SourceItem_CaseInsensitive_ParsedSuccessfully() { // Arrange var config = @" <configuration> <section> <AdD key='key' value='val' /> </section> </configuration>"; var expectedValue = new AddItem("key", "val"); var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("section"); section.Should().NotBeNull(); var children = section.Items.ToList(); children.Should().NotBeEmpty(); children.Count.Should().Be(1); children[0].DeepEquals(expectedValue).Should().BeTrue(); } }
public void AddItem_SingleTag_WithOnlyKeyAndValue_ParsedSuccessfully() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key1' value='value1' /> </Section> </configuration>"; var expectedSetting = new AddItem("key1", "value1"); using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault(); element.Should().NotBeNull(); // Assert element.DeepEquals(expectedSetting).Should().BeTrue(); } }
public void AddItem_WithAdditionalMetada_ParsedSuccessfully() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key1' value='value1' meta1='data1' meta2='data2'/> </Section> </configuration>"; var expectedSetting = new AddItem("key1", "value1", new ReadOnlyDictionary <string, string>(new Dictionary <string, string> { { "meta1", "data1" }, { "meta2", "data2" } })); using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var value = section.Items.FirstOrDefault(); value.Should().NotBeNull(); // Assert value.DeepEquals(expectedSetting).Should().BeTrue(); } }
public void CredentialsItem_Parsing_WithUsernamePasswordAndClearTextPassword_TakesFirstAndIgnoresRest() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <packageSourceCredentials> <NuGet.Org meta1='data1'> <add key='Username' value='username' /> <add key='Password' value='password' /> <add key='ClearTextPassword' value='clearTextPassword' /> </NuGet.Org> </packageSourceCredentials> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("packageSourceCredentials"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First() as CredentialsItem; item.Should().NotBeNull(); item.Password.Should().Be("password"); item.IsPasswordClearText.Should().BeFalse(); } }
public void CredentialsItem_Parsing_WithoutPasswordOrClearTextPassword_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <packageSourceCredentials> <NuGet.Org meta1='data1'> <add key='Username' value='username' /> </NuGet.Org> </packageSourceCredentials> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var ex = Record.Exception(() => new SettingsFile(mockBaseDirectory)); ex.Should().NotBeNull(); ex.Should().BeOfType <NuGetConfigurationException>(); ex.Message.Should().Be(string.Format("Unable to parse config file because: Credentials item must have username and password. Path: '{0}'.", Path.Combine(mockBaseDirectory, nugetConfigPath))); } }
public void SourceItem_CaseInsensitive_ParsedSuccessfully() { // Arrange var config = @" <configuration> <PACkagEsourCEs> <AdD key='nugetorg' value='http://serviceIndexorg.test/api/index.json' /> </PACkagEsourCEs> </configuration>"; var expectedValue = new SourceItem("nugetorg", "http://serviceIndexorg.test/api/index.json"); var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("PACkagEsourCEs"); section.Should().NotBeNull(); var children = section.Items.ToList(); children.Should().NotBeEmpty(); children.Count.Should().Be(1); children[0].DeepEquals(expectedValue).Should().BeTrue(); } }
public void SettingsFile_GetSections_DuplicatedSections_TakesFirstAndIgnoresRest() { // Arrange var config = @" <configuration> <SectionName> <add key='key1' value='value1' /> </SectionName> <SectionName> <add key='key2' value='value2' /> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); var addItem = section.Items.FirstOrDefault() as AddItem; addItem.Should().NotBeNull(); addItem.Key.Should().Be("key1"); addItem.Value.Should().Be("value1"); } }
public void SourceItem_Parsing_ElementWithChildren_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <packageSources> <add key='nugetorg' value='http://serviceIndexorg.test/api/index.json'> <add key='key2' value='value2' /> </add> </packageSources> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var ex = Record.Exception(() => new SettingsFile(mockBaseDirectory)); ex.Should().NotBeNull(); ex.Should().BeOfType <NuGetConfigurationException>(); ex.Message.Should().Be(string.Format("Error parsing NuGet.Config. Element '{0}' cannot have descendant elements. Path: '{1}'.", "add", Path.Combine(mockBaseDirectory, nugetConfigPath))); } }
public void UnknownItem_WithChildren_OnlyText_ParsedCorrectly() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <Unknown>Text for test</Unknown> </Section> </configuration>"; var expectedSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>() { new SettingText("Text for test") }); using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault(); element.Should().NotBeNull(); // Assert element.DeepEquals(expectedSetting).Should().BeTrue(); } }
public void GetGlobalPackagesFolder_FromNuGetConfig_RelativePath() { // Arrange var config = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <config> <add key=""globalPackagesFolder"" value=""..\..\NuGetPackages"" /> </config> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settings = new Settings(mockBaseDirectory); var expected = Path.GetFullPath(Path.Combine(mockBaseDirectory, @"..\..\NuGetPackages")); // Act var globalPackagesFolderPath = SettingsUtility.GetGlobalPackagesFolder(settings); // Assert globalPackagesFolderPath.Should().Be(expected); } }
public void UnknownItem_Update_RemovesMissingAttributes() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <Unknown old=""attr"" /> </Section> </configuration>"; var updateSetting = new UnknownItem("Unknown", attributes: new Dictionary <string, string>() { }, children: null); using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault() as UnknownItem; element.Should().NotBeNull(); element.Update(updateSetting); // Assert element.Attributes.TryGetValue("old", out var _).Should().BeFalse(); } }
public void UnknownItem_Add_Item_WorksSuccessfully() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <Unknown /> </Section> </configuration>"; var expectedSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>() { new AddItem("key", "val") }); using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault() as UnknownItem; element.Should().NotBeNull(); element.Add(new AddItem("key", "val")).Should().BeTrue(); // Assert element.DeepEquals(expectedSetting).Should().BeTrue(); } }
public void UnknownItem_Remove_ToMachineWide_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <Unknown> <Unknown2 /> </Unknown> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory, nugetConfigPath, isMachineWide: true); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault() as UnknownItem; element.Should().NotBeNull(); // Assert var ex = Record.Exception(() => element.Remove(element.Children.First())); ex.Should().NotBeNull(); ex.Should().BeOfType <InvalidOperationException>(); } }
public void SettingSection_Remove_UnexistantChild_DoesNotRemoveAnything() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key0' value='value0' /> <add key='key1' value='value1' meta1='data1' meta2='data2'/> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var configFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); section.Remove(new AddItem("key7", "value7")); var updatedFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); updatedFileHash.Should().BeEquivalentTo(configFileHash); section.Items.Count.Should().Be(2); } }
public void SettingSection_GetValues_ReturnsAllChildElements() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <SectionName> <add key='key1' value='value1' /> <add key='key2' value='value2' /> </SectionName> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); var children = section.Items; // Assert children.Should().NotBeEmpty(); children.Count.Should().Be(2); children.Should().AllBeOfType <AddItem>(); } }
public void SettingSection_Remove_OnlyOneChild_SucceedsAndRemovesSection() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key0' value='value0' /> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var configFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var child = section.GetFirstItemWithAttribute <AddItem>("key", "key0"); child.Should().NotBeNull(); settingsFile.Remove("Section", child); settingsFile.SaveToDisk(); var updatedFileHash = ConfigurationFileTestUtility.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); updatedFileHash.Should().NotBeEquivalentTo(configFileHash); section = settingsFile.GetSection("Section"); section.Should().BeNull(); } }
public void SettingSection_GetValues_UnexistantChild_ReturnsNull() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <SectionName> <add key='key1' value='value1' /> <add key='key2' value='value2' /> </SectionName> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); var key3Element = section.GetFirstItemWithAttribute <AddItem>("key", "key3"); // Assert key3Element.Should().BeNull(); } }
public void SettingText_ParsedSuccessfully() { // Arrange var config = @" <configuration> <SectionName> <Item>This is a test</Item> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.Should().NotBeNull(); var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First() as UnknownItem; item.Should().NotBeNull(); item.Children.Count.Should().Be(1); var text = item.Children.First() as SettingText; text.Should().NotBeNull(); text.Value.Should().Be("This is a test"); } }
public void GetFallbackPackageFolders_RelativePathChild() { // Arrange var config = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""shared"" value=""test"" /> </fallbackPackageFolders> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { var testFolder = Path.Combine(mockBaseDirectory, "test"); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); Settings settings = new Settings(mockBaseDirectory); // Act var paths = SettingsUtility.GetFallbackPackageFolders(settings); // Assert Assert.Equal(testFolder, paths.Single()); } }
public void GetFallbackPackageFolders_MultipleFoldersFromMultipleNuGetConfigs() { // Arrange var configA = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""a"" value=""C:\Temp\a"" /> <add key=""b"" value=""C:\Temp\b"" /> </fallbackPackageFolders> </configuration>"; var configB = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""c"" value=""C:\Temp\c"" /> <add key=""d"" value=""C:\Temp\d"" /> </fallbackPackageFolders> </configuration>"; var configC = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""x"" value=""C:\Temp\x"" /> <add key=""y"" value=""C:\Temp\y"" /> </fallbackPackageFolders> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var machineWide = TestDirectory.Create()) using (var mockBaseDirectory = TestDirectory.Create()) { var subFolder = Path.Combine(mockBaseDirectory, "sub"); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, subFolder, configA); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, configB); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, machineWide, configC); var machineWiderFolderSettings = new Settings(machineWide); var machineWideSettings = new TestMachineWideSettings(machineWiderFolderSettings); var settings = Settings.LoadDefaultSettings( subFolder, configFileName: null, machineWideSettings: machineWideSettings); // Act var paths = SettingsUtility.GetFallbackPackageFolders(settings).ToArray(); // Assert Assert.Equal(6, paths.Length); Assert.Equal("a", GetFileName(paths[0])); Assert.Equal("b", GetFileName(paths[1])); Assert.Equal("c", GetFileName(paths[2])); Assert.Equal("d", GetFileName(paths[3])); Assert.Equal("x", GetFileName(paths[4])); Assert.Equal("y", GetFileName(paths[5])); } }
public void GetFallbackPackageFolders_MultipleFoldersFromMultipleNuGetConfigs() { // Arrange var configA = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""a"" value=""C:\Temp\a"" /> <add key=""b"" value=""C:\Temp\b"" /> </fallbackPackageFolders> </configuration>"; var configB = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""c"" value=""C:\Temp\c"" /> <add key=""d"" value=""C:\Temp\d"" /> </fallbackPackageFolders> </configuration>"; var configC = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <fallbackPackageFolders> <add key=""x"" value=""C:\Temp\x"" /> <add key=""y"" value=""C:\Temp\y"" /> </fallbackPackageFolders> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var machineWide = TestDirectory.Create()) using (var mockBaseDirectory = TestDirectory.Create()) { var subFolder = Path.Combine(mockBaseDirectory, "sub"); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, subFolder, configA); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, configB); ConfigurationFileTestUtility.CreateConfigurationFile(nugetConfigPath, machineWide, configC); var machineWiderFolderSettings = new Settings(machineWide); var machineWideSettings = new TestMachineWideSettings(machineWiderFolderSettings); var settings = Settings.LoadDefaultSettings( subFolder, configFileName: null, machineWideSettings: machineWideSettings); // Act var actual = SettingsUtility .GetFallbackPackageFolders(settings) .Select(GetFileName); var expected = new[] { "a", "b", "c", "d", "x", "y" }; // Ignore any extra folders on the machine var actualFiltered = Enumerable.Intersect(actual, expected); Assert.Equal(expected, actualFiltered); } }