public void TestAddRemoveRange() { var certificates = new List <X509Certificate> (); var chain = new X509CertificateChain(); foreach (var authority in CertificateAuthorities) { var certificate = LoadCertificate(GetTestDataPath(authority)); certificates.Add(certificate); } Assert.Throws <ArgumentNullException> (() => chain.AddRange(null)); chain.AddRange(certificates); Assert.AreEqual(CertificateAuthorities.Length, chain.Count, "Unexpected number of certificates after AddRange."); int index = 0; foreach (var certificate in chain) { Assert.AreEqual(certificates[index++], certificate, "GetEnumerator"); } index = 0; foreach (X509Certificate certificate in ((IEnumerable)chain)) { Assert.AreEqual(certificates[index++], certificate, "GetEnumerator"); } Assert.Throws <ArgumentNullException> (() => chain.RemoveRange(null)); chain.RemoveRange(certificates); Assert.AreEqual(0, chain.Count, "Unexpected number of certificates after RemoveRange."); }
public void TestArgumentExceptions() { var path = Path.Combine("..", "..", "TestData", "smime", "smime.p12"); var chain = new X509CertificateChain(); CmsSigner signer; using (var stream = File.OpenRead(path)) signer = new CmsSigner(stream, "no.secret"); Assert.Throws <ArgumentNullException> (() => new X509CertificateChain(null)); Assert.Throws <ArgumentNullException> (() => chain.Add(null)); Assert.Throws <ArgumentNullException> (() => chain.AddRange(null)); Assert.Throws <ArgumentNullException> (() => chain.Contains(null)); Assert.Throws <ArgumentNullException> (() => chain.CopyTo(null, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => chain.CopyTo(new X509Certificate[0], -1)); Assert.Throws <ArgumentNullException> (() => chain.IndexOf(null)); Assert.Throws <ArgumentOutOfRangeException> (() => chain.Insert(-1, signer.Certificate)); Assert.Throws <ArgumentNullException> (() => chain.Insert(0, null)); Assert.Throws <ArgumentNullException> (() => chain[0] = null); Assert.Throws <ArgumentNullException> (() => chain.Remove(null)); Assert.Throws <ArgumentOutOfRangeException> (() => chain.RemoveAt(-1)); }