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_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 OwnersItem_ParsedCorrectly() { // Arrange var config = @" <configuration> <SectionName> <owners>test;text;owner</owners> </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 OwnersItem; var expectedItem = new OwnersItem("test;text;owner"); SettingsTestUtils.DeepEquals(item, expectedItem).Should().BeTrue(); } }
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(); }
public void RepositoryItem_WithCertificatesAndOwners_ParsedCorrectly() { // Arrange var config = @" <configuration> <SectionName> <repository name=""repositoryName"" serviceIndex=""https://api.test/index/""> <certificate fingerprint=""abcdefg"" hashAlgorithm=""Sha256"" allowUntrustedRoot=""true"" /> <owners>test;text</owners> </repository> </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 RepositoryItem; var expectedItem = new RepositoryItem("repositoryName", "https://api.test/index/", "test;text", new CertificateItem("abcdefg", Common.HashAlgorithmName.SHA256, allowUntrustedRoot: true)); SettingsTestUtils.DeepEquals(item, expectedItem).Should().BeTrue(); } }
public void OwnersItem_Clone_CopiesTheSameItem() { // Arrange var config = @" <configuration> <SectionName> <owners>test;text;owner</owners> </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 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 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 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_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 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 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 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 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 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 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()) { SettingsTestUtils.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); SettingsTestUtils.DeepEquals(children[0], expectedValue).Should().BeTrue(); } }
public void Clone_CreatesEquivalentObjects(string patternName) { var original = new PackagePatternItem(patternName); var clone = original.Clone() as PackagePatternItem; original.Equals(clone).Should().BeTrue(); original.GetHashCode().Equals(clone.GetHashCode()).Should().BeTrue(); SettingsTestUtils.DeepEquals(original, clone).Should().BeTrue(); ReferenceEquals(original, clone).Should().BeFalse(); original.Pattern.Equals(clone.Pattern); }
public void Clone_CreatesEquivalentObjects(string namespaceName) { var original = new NamespaceItem(namespaceName); var clone = original.Clone() as NamespaceItem; original.Equals(clone).Should().BeTrue(); original.GetHashCode().Equals(clone.GetHashCode()).Should().BeTrue(); SettingsTestUtils.DeepEquals(original, clone).Should().BeTrue(); ReferenceEquals(original, clone).Should().BeFalse(); original.Id.Equals(clone.Id); }
public void AsSourceItem_WorksCorrectly() { var source = new PackageSource("Source", "SourceName", isEnabled: false) { ProtocolVersion = 43 }; var expectedItem = new SourceItem("SourceName", "Source", "43"); SettingsTestUtils.DeepEquals(source.AsSourceItem(), expectedItem).Should().BeTrue(); }
public void SettingSection_Merge_JoinsTwoSectionsCorrectly() { var firstSection = new VirtualSettingSection("Section", new AddItem("key1", "value1"), new AddItem("key2", "value2")); var secondSection = new VirtualSettingSection("Section", new AddItem("key2", "valueX"), new AddItem("key3", "value3")); var expectedSection = new VirtualSettingSection("Section", new AddItem("key1", "value1"), new AddItem("key2", "valueX"), new AddItem("key3", "value3")); firstSection.Merge(secondSection); SettingsTestUtils.DeepEquals(firstSection, expectedSection).Should().BeTrue(); }
public void AsCredentialsItem_WithSpaceOnSourceName_WorksCorrectly() { var credentials = new PackageSourceCredential( "source name", "user", "password", isPasswordClearText: true, validAuthenticationTypesText: null); var expectedItem = new CredentialsItem("source name", "user", "password", isPasswordClearText: true, validAuthenticationTypes: null); SettingsTestUtils.DeepEquals(credentials.AsCredentialsItem(), expectedItem).Should().BeTrue(); }
public void AsCredentialsItem_WithAuthenticationTypes_WorksCorrectly() { var credentials = new PackageSourceCredential( "source", "user", "password", isPasswordClearText: false, validAuthenticationTypesText: "basic, negotiate"); var expectedItem = new CredentialsItem("source", "user", "password", isPasswordClearText: false, validAuthenticationTypes: "basic, negotiate"); SettingsTestUtils.DeepEquals(credentials.AsCredentialsItem(), expectedItem).Should().BeTrue(); }
public void Clone_CreatesEquivalentPackagePatterns() { var original = new PackageSourceMappingSourceItem("name", new List <PackagePatternItem>() { new PackagePatternItem("stuff"), new PackagePatternItem("stuff2") }); var clone = original.Clone() as PackageSourceMappingSourceItem; original.Equals(clone).Should().BeTrue(); original.GetHashCode().Equals(clone.GetHashCode()).Should().BeTrue(); SettingsTestUtils.DeepEquals(original, clone).Should().BeTrue(); ReferenceEquals(original, clone).Should().BeFalse(); original.Key.Equals(clone.Key); }
public void SettingsFile_MergeSectionsInto_WithSectionsInCommon_ReturnsConfigWithAllSectionsMerged() { // Arrange var nugetConfigPath = "NuGet.Config"; var config = @" <configuration> <Section1> <add key='key1' value='value1' /> </Section1> <Section2> <add key='key2' value='value2' /> </Section2> <Section3> <add key='key3' value='value3' /> </Section3> </configuration>"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var settingsFile = new SettingsFile(mockBaseDirectory); // Act var settingsDict = new Dictionary <string, VirtualSettingSection>() { { "Section2", new VirtualSettingSection("Section2", new AddItem("keyX", "valueX")) }, { "Section3", new VirtualSettingSection("Section3", new AddItem("key3", "valueY")) }, { "Section4", new VirtualSettingSection("Section4", new AddItem("key4", "value4")) } }; settingsFile.MergeSectionsInto(settingsDict); var expectedSettingsDict = new Dictionary <string, VirtualSettingSection>() { { "Section2", new VirtualSettingSection("Section2", new AddItem("keyX", "valueX"), new AddItem("key2", "value2")) }, { "Section3", new VirtualSettingSection("Section3", new AddItem("key3", "value3")) }, { "Section4", new VirtualSettingSection("Section4", new AddItem("key4", "value4")) }, { "Section1", new VirtualSettingSection("Section1", new AddItem("key1", "value1")) }, }; foreach (var pair in settingsDict) { expectedSettingsDict.TryGetValue(pair.Key, out var expectedSection).Should().BeTrue(); SettingsTestUtils.DeepEquals(pair.Value, expectedSection).Should().BeTrue(); expectedSettingsDict.Remove(pair.Key); } expectedSettingsDict.Should().BeEmpty(); } }
public void RepositoryItem_Update_RemovesOwnersCorrectly() { // Arrange var config = @" <configuration> <SectionName> <repository name=""repositoryName"" serviceIndex=""https://api.test/index/""> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true"" /> <owners>owner1;owner2</owners> </repository> </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() as RepositoryItem; item.Owners.Count.Should().Be(2); var updatedItem = item.Clone() as RepositoryItem; updatedItem.Owners.RemoveAt(1); item.Update(updatedItem); SettingsTestUtils.DeepEquals(item, updatedItem).Should().BeTrue(); settingsFile.SaveToDisk(); // Assert var result = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <SectionName> <repository name=""repositoryName"" serviceIndex=""https://api.test/index/""> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true"" /> <owners>owner1</owners> </repository> </SectionName> </configuration>"; Assert.Equal(result.Replace("\r\n", "\n"), File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath)).Replace("\r\n", "\n")); } }
public void SettingSection_Clone_ReturnsSectionClone() { // 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.Should().BeOfType <ParsedSettingSection>(); section.IsCopy().Should().BeFalse(); section.Origin.Should().NotBeNull(); var clone = section.Clone() as SettingSection; clone.IsAbstract().Should().BeTrue(); clone.Origin.Should().BeNull(); clone.Should().BeOfType <VirtualSettingSection>(); SettingsTestUtils.DeepEquals(clone, section).Should().BeTrue(); var virtualSection = new VirtualSettingSection("SectionName", new AddItem("key1", "val", new Dictionary <string, string>() { { "meta", "data" } })); virtualSection.Origin.Should().BeNull(); virtualSection.IsAbstract().Should().BeTrue(); var virtualClone = virtualSection.Clone() as SettingSection; virtualClone.IsAbstract().Should().BeTrue(); virtualClone.Origin.Should().BeNull(); virtualClone.Should().BeOfType <VirtualSettingSection>(); SettingsTestUtils.DeepEquals(virtualClone, virtualSection).Should().BeTrue(); } }
public void AuthorItem_Update_UpdatesAddsCertificatesCorrectly() { // Arrange var config = @" <configuration> <SectionName> <author name=""authorName""> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true"" /> </author> </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() as AuthorItem; var updatedItem = item.Clone() as AuthorItem; updatedItem.Certificates.Add(new CertificateItem("xyz", Common.HashAlgorithmName.SHA256)); item.Update(updatedItem); SettingsTestUtils.DeepEquals(item, updatedItem).Should().BeTrue(); settingsFile.SaveToDisk(); // Assert var result = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <SectionName> <author name=""authorName""> <certificate fingerprint=""abcdefg"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""true"" /> <certificate fingerprint=""xyz"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""false"" /> </author> </SectionName> </configuration>"; Assert.Equal(result.Replace("\r\n", "\n"), File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath)).Replace("\r\n", "\n")); } }
public void Update_UpdatesKeyCorrectly() { // Arrange var config = @" <configuration> <packageSourceMapping> <packageSource key=""nuget.org""> <package pattern=""original"" /> </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); settingsFile.TryGetSection("packageSourceMapping", out var section).Should().BeTrue(); section.Should().NotBeNull(); section.Items.Count.Should().Be(1); var packageSourcePatternsItem = section.Items.First() as PackageSourceMappingSourceItem; var updatedItem = new PackagePatternItem("updated"); packageSourcePatternsItem.Patterns.First().Update(updatedItem); SettingsTestUtils.DeepEquals(packageSourcePatternsItem.Patterns.First(), updatedItem).Should().BeTrue(); settingsFile.SaveToDisk(); // Assert var result = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSourceMapping> <packageSource key=""nuget.org""> <package pattern=""updated"" /> </packageSource> </packageSourceMapping> </configuration>"; result.Replace("\r\n", "\n") .Should().BeEquivalentTo( File.ReadAllText(Path.Combine(mockBaseDirectory, nugetConfigPath)).Replace("\r\n", "\n")); }
public void StoreClientCert_FromDocumentation_ParsedCorrectly() { // Arrange var config = @" <configuration> <SectionName> <storeCert packageSource=""Contoso"" storeLocation = ""currentUser"" storeName = ""my"" findBy = ""thumbprint"" findValue = ""4894671ae5aa84840cc1079e89e82d426bc24ec6"" /> </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(); var items = section.Items.ToList(); items.Count.Should().Be(1); var storeClientCertItem = (StoreClientCertItem)items[0]; storeClientCertItem.ElementName.Should().Be("storeCert"); storeClientCertItem.PackageSource.Should().Be("Contoso"); storeClientCertItem.StoreLocation.Should().Be(StoreLocation.CurrentUser); storeClientCertItem.StoreName.Should().Be(StoreName.My); storeClientCertItem.FindType.Should().Be(X509FindType.FindByThumbprint); storeClientCertItem.FindValue.Should().Be("4894671ae5aa84840cc1079e89e82d426bc24ec6"); var expectedStoreClientCertItem = new StoreClientCertItem("Contoso", "4894671ae5aa84840cc1079e89e82d426bc24ec6", StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint); SettingsTestUtils.DeepEquals(storeClientCertItem, expectedStoreClientCertItem).Should().BeTrue(); } }