public void Remove_WithEmptyListOFSignersToRemove_Throws() { var trustedSignersProvider = new TrustedSignersProvider(settings: NullSettings.Instance); // Act and Assert var ex = Record.Exception(() => trustedSignersProvider.Remove(trustedSigners: new List <TrustedSignerItem>())); ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentException>(); }
public void Remove_IgnoresAnyUnexistantTrustedSigner() { // 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("author2", new CertificateItem("def", HashAlgorithmName.SHA256)), new RepositoryItem("repo1", "https://serviceIndex.test/v3/api.json", new CertificateItem("ghi", HashAlgorithmName.SHA256)) }; // Act and Assert var settings = new Settings(mockBaseDirectory); settings.Should().NotBeNull(); var trustedSignerProvider = new TrustedSignersProvider(settings); var trustedSigners = trustedSignerProvider.GetTrustedSigners(); trustedSignerProvider.Remove(new[] { trustedSigners.First(), new AuthorItem("DontExist", new CertificateItem("abc", HashAlgorithmName.SHA256)) }); trustedSigners = trustedSignerProvider.GetTrustedSigners(); trustedSigners.Should().NotBeNull(); trustedSigners.Count.Should().Be(2); trustedSigners.Should().BeEquivalentTo( expectedTrustedSigners, options => options .Excluding(o => o.Path == "[0].Origin") .Excluding(o => o.Path == "[1].Origin")); } }