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()) { SettingsTestUtils.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 SettingsTestUtils.DeepEquals(element, expectedSetting).Should().BeTrue(); } }
public void AddItem_Parsing_ElementWithChildren_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <add key='key1' value='value1'> <add key='key2' value='value2' /> </add> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.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 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()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var element = section.Items.FirstOrDefault() as AddItem; element.Should().NotBeNull(); // Assert SettingsTestUtils.DeepEquals(element, expectedSetting).Should().BeTrue(); } }
public void CertificateItem_WithChildren_Throws() { // Arrange var config = @" <configuration> <SectionName> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true""> <add key=""key"" value=""val"" /> </certificate> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.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 'certificate' cannot have descendant elements. Path: '{0}'.", Path.Combine(mockBaseDirectory, nugetConfigPath))); } }
public void CertificateItem_Clone_CopiesTheSameItem() { // Arrange var config = @" <configuration> <SectionName> <certificate fingerprint=""abcdefg"" hashAlgorithm=""Sha256"" allowUntrustedRoot=""true"" /> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.TryGetSection("SectionName", out var section).Should().BeTrue(); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First(); item.IsCopy().Should().BeFalse(); item.Origin.Should().NotBeNull(); var clone = item.Clone(); clone.IsCopy().Should().BeTrue(); clone.Origin.Should().NotBeNull(); SettingsTestUtils.DeepEquals(clone, item).Should().BeTrue(); } }
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()) { SettingsTestUtils.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 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()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var configFileHash = SettingsTestUtils.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 = SettingsTestUtils.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); updatedFileHash.Should().BeEquivalentTo(configFileHash); section.Items.Count.Should().Be(2); } }
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()) { SettingsTestUtils.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 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()) { SettingsTestUtils.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 UnknownItem_Merge_AddsNewAttributes() { var originalSetting = new UnknownItem("Unknown", attributes: new Dictionary <string, string>() { { "old", "attr" } }, children: null); var newSetting = new UnknownItem("Unknown", attributes: new Dictionary <string, string>() { { "new", "newAttr" } }, children: null); originalSetting.Merge(newSetting); var expectedSetting = new UnknownItem("Unknown", attributes: new Dictionary <string, string>() { { "old", "attr" }, { "new", "newAttr" } }, children: null); SettingsTestUtils.DeepEquals(originalSetting, expectedSetting).Should().BeTrue(); }
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>"; 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); } }
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()) { SettingsTestUtils.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 SettingsTestUtils.DeepEquals(element, expectedSetting).Should().BeTrue(); } }
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()) { SettingsTestUtils.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_Remove_ToReadOnly_Throws() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section> <Unknown> <Unknown2 /> </Unknown> </Section> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory, nugetConfigPath, isMachineWide: false, isReadOnly: 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 PackageSourceNamespacesItemParse_WithValidData_ParsesCorrectly() { // Arrange var config = @" <configuration> <packageNamespaces> <packageSource key=""nuget.org""> <namespace id=""sadas"" /> </packageSource> </packageNamespaces> </configuration>"; var nugetConfigPath = "NuGet.Config"; using var mockBaseDirectory = TestDirectory.Create(); SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); var section = settingsFile.GetSection("packageNamespaces"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var packageSourceNamespaceItem = section.Items.First() as PackageNamespacesSourceItem; var item = packageSourceNamespaceItem.Namespaces.First(); var expectedItem = new NamespaceItem("sadas"); SettingsTestUtils.DeepEquals(item, expectedItem).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()) { SettingsTestUtils.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 PackageSourceMappingSourceItemParse_WithUnrecognizedItems_UnknownItemsAreIgnored() { // Arrange // Arrange var config = @" <configuration> <packageSourceMapping> <packageSource key=""nuget.org""> <package pattern=""sadas"" /> <notANamespace id=""sadas"" /> </packageSource> </packageSourceMapping> </configuration>"; var nugetConfigPath = "NuGet.Config"; using var mockBaseDirectory = TestDirectory.Create(); SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); var section = settingsFile.GetSection("packageSourceMapping"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var packageSourceMappingSourceItem = section.Items.First() as PackageSourceMappingSourceItem; var item = packageSourceMappingSourceItem.Patterns.First(); var expectedItem = new PackagePatternItem("sadas"); SettingsTestUtils.DeepEquals(item, expectedItem).Should().BeTrue(); }
public void GetPackageNamespacesConfiguration_WithOneSource() { // Arrange using var mockBaseDirectory = TestDirectory.Create(); var configPath1 = Path.Combine(mockBaseDirectory, "NuGet.Config"); SettingsTestUtils.CreateConfigurationFile(configPath1, @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageNamespaces> <clear /> <packageSource key=""nuget.org""> <namespace id=""stuff"" /> </packageSource> </packageNamespaces> </configuration>"); var settings = Settings.LoadSettingsGivenConfigPaths(new string[] { configPath1 }); // Act & Assert var configuration = PackageNamespacesConfiguration.GetPackageNamespacesConfiguration(settings); configuration.AreNamespacesEnabled.Should().BeTrue(); configuration.Namespaces.Should().HaveCount(1); KeyValuePair <string, IReadOnlyList <string> > namespaceForSource = configuration.Namespaces.First(); namespaceForSource.Key.Should().Be("nuget.org"); namespaceForSource.Value.Should().BeEquivalentTo(new string[] { "stuff" }); }
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()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var configFileHash = SettingsTestUtils.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 = SettingsTestUtils.GetFileHash(Path.Combine(mockBaseDirectory, nugetConfigPath)); updatedFileHash.Should().NotBeEquivalentTo(configFileHash); section = settingsFile.GetSection("Section"); section.Should().BeNull(); } }
public void GetPackageNamespacesConfiguration_WithMultipleSources() { // Arrange using var mockBaseDirectory = TestDirectory.Create(); var configPath1 = Path.Combine(mockBaseDirectory, "NuGet.Config"); SettingsTestUtils.CreateConfigurationFile(configPath1, @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageNamespaces> <packageSource key=""nuget.org""> <namespace id=""stuff"" /> </packageSource> <packageSource key=""contoso""> <namespace id=""moreStuff"" /> </packageSource> </packageNamespaces> </configuration>"); var settings = Settings.LoadSettingsGivenConfigPaths(new string[] { configPath1 }); // Act & Assert var configuration = PackageNamespacesConfiguration.GetPackageNamespacesConfiguration(settings); configuration.AreNamespacesEnabled.Should().BeTrue(); configuration.Namespaces.Should().HaveCount(2); IReadOnlyList <string> nugetNamespaces = configuration.Namespaces["nuget.org"]; nugetNamespaces.Should().BeEquivalentTo(new string[] { "stuff" }); IReadOnlyList <string> contosoNamespace = configuration.Namespaces["contoso"]; contosoNamespace.Should().BeEquivalentTo(new string[] { "moreStuff" }); }
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()) { SettingsTestUtils.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 AddItem_Clone_ReturnsItemClone() { // Arrange var config = @" <configuration> <SectionName> <add key=""key1"" value=""val"" meta=""data"" /> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.TryGetSection("SectionName", out var section).Should().BeTrue(); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First(); item.IsCopy().Should().BeFalse(); item.Origin.Should().NotBeNull(); var clone = item.Clone() as AddItem; clone.IsCopy().Should().BeTrue(); clone.Origin.Should().NotBeNull(); SettingsTestUtils.DeepEquals(clone, item).Should().BeTrue(); } }
public void CertificateItem_ParsedCorrectly() { // Arrange var config = @" <configuration> <SectionName> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true"" /> </SectionName> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); var section = settingsFile.GetSection("SectionName"); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First() as CertificateItem; var expectedItem = new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA256, allowUntrustedRoot: true); SettingsTestUtils.DeepEquals(item, expectedItem).Should().BeTrue(); } }
public void CredentialsItem_Clone_WithSpaceOnName_ReturnsItemClone() { // Arrange var config = @" <configuration> <packageSourceCredentials> <nuget_x0020_org> <add key='Username' value='username' /> <add key='Password' value='password' /> </nuget_x0020_org> </packageSourceCredentials> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); // Act and Assert var settingsFile = new SettingsFile(mockBaseDirectory); settingsFile.TryGetSection("packageSourceCredentials", out var section).Should().BeTrue(); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var item = section.Items.First(); item.IsCopy().Should().BeFalse(); item.Origin.Should().NotBeNull(); var clone = item.Clone() as CredentialsItem; clone.IsCopy().Should().BeTrue(); clone.Origin.Should().NotBeNull(); SettingsTestUtils.DeepEquals(clone, item).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()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var section = settingsFile.GetSection("Section"); section.Should().NotBeNull(); var value = section.Items.FirstOrDefault() as AddItem; value.Should().NotBeNull(); // Assert SettingsTestUtils.DeepEquals(value, expectedSetting).Should().BeTrue(); } }
public void CredentialsItem_Parsing_WithUsernamePasswordAndClearTextPassword_Throws() { // 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()) { SettingsTestUtils.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: {0} Path: '{1}'.", _moreThanOnePassword, Path.Combine(mockBaseDirectory, nugetConfigPath))); } }
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()) { SettingsTestUtils.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); SettingsTestUtils.DeepEquals(children[0], expectedValue).Should().BeTrue(); } }
public void PackagePatternItemParse_WithChildren_Throws() { // Arrange var config = @" <configuration> <packageSourceMapping> <packageSource key=""nuget.org""> <package pattern=""sadas""> <add key=""key"" value=""val"" /> </package> </packageSource> </packageSourceMapping> </configuration>"; var nugetConfigPath = "NuGet.Config"; using var mockBaseDirectory = TestDirectory.Create(); SettingsTestUtils.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 'package' cannot have descendant elements. Path: '{0}'.", Path.Combine(mockBaseDirectory, nugetConfigPath))); }
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()) { SettingsTestUtils.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 UnknownItem_Merge_AddshNewChildren() { var originalSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>() { new AddItem("key", "val") }); var newSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>() { new SettingText("New test") }); originalSetting.Merge(newSetting); var expectedSetting = new UnknownItem("Unknown", attributes: null, children: new List <SettingBase>() { new AddItem("key", "val"), new SettingText("New test") }); SettingsTestUtils.DeepEquals(originalSetting, expectedSetting).Should().BeTrue(); }