public void AddOrUpdateTrustedSigner_WithNullItem_Throws() { var trustedSignersProvider = new TrustedSignersProvider(settings: NullSettings.Instance); // Act and Assert var ex = Record.Exception(() => trustedSignersProvider.AddOrUpdateTrustedSigner(trustedSigner: null)); ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public void AddOrUpdateTrustedSigner_WithNewTrustedSigner_AddsItSuccesfully() { // Arrange var config = @" <configuration> <trustedSigners> <author name=""author1""> <certificate fingerprint=""abc"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""false"" /> </author> <author name=""author2""> <certificate fingerprint=""def"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""false"" /> </author> <repository name=""repo1"" serviceIndex=""https://serviceIndex.test/v3/api.json""> <certificate fingerprint=""ghi"" hashAlgorithm=""SHA256"" allowUntrustedRoot=""false"" /> </repository> </trustedSigners> </configuration>"; var nugetConfigPath = "NuGet.Config"; using (var mockBaseDirectory = TestDirectory.Create()) { SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config); var expectedTrustedSigners = new List <TrustedSignerItem>() { new AuthorItem("author1", new CertificateItem("abc", HashAlgorithmName.SHA256)), new AuthorItem("author2", new CertificateItem("def", HashAlgorithmName.SHA256)), new RepositoryItem("repo1", "https://serviceIndex.test/v3/api.json", new CertificateItem("ghi", HashAlgorithmName.SHA256)), new AuthorItem("author3", new CertificateItem("jkl", HashAlgorithmName.SHA256)), }; // Act and Assert var settings = new Settings(mockBaseDirectory); settings.Should().NotBeNull(); var trustedSignerProvider = new TrustedSignersProvider(settings); trustedSignerProvider.AddOrUpdateTrustedSigner(new AuthorItem("author3", new CertificateItem("jkl", HashAlgorithmName.SHA256))); var trustedSigners = trustedSignerProvider.GetTrustedSigners(); trustedSigners.Should().NotBeNull(); trustedSigners.Count.Should().Be(4); trustedSigners.Should().BeEquivalentTo( expectedTrustedSigners, options => options .Excluding(o => o.Path == "[0].Origin") .Excluding(o => o.Path == "[1].Origin") .Excluding(o => o.Path == "[2].Origin") .Excluding(o => o.Path == "[3].Origin")); } }