Esempio n. 1
0
        public void TestCollectionAddRemove()
        {
            var path       = Path.Combine("..", "..", "TestData", "smime", "certificate-authority.crt");
            var recipients = new CmsRecipientCollection();
            var recipient  = new CmsRecipient(path);
            var array      = new CmsRecipient[1];

            Assert.IsFalse(recipients.Contains(recipient), "Contains: False");
            Assert.IsFalse(recipients.Remove(recipient), "Remove: False");

            recipients.Add(recipient);

            Assert.AreEqual(1, recipients.Count, "Count");
            Assert.IsTrue(recipients.Contains(recipient), "Contains: True");

            recipients.CopyTo(array, 0);
            Assert.AreEqual(recipient, array[0], "CopyTo");

            Assert.IsTrue(recipients.Remove(recipient), "Remove: True");

            Assert.AreEqual(0, recipients.Count, "Count");

            recipients.Clear();
        }
Esempio n. 2
0
        public void TestArgumentExceptions()
        {
            Assert.Throws <ArgumentNullException> (() => new CmsRecipient((X509Certificate2)null));
            Assert.Throws <ArgumentNullException> (() => new CmsRecipient((X509Certificate)null));
            Assert.Throws <ArgumentNullException> (() => new CmsRecipient((Stream)null));
            Assert.Throws <ArgumentNullException> (() => new CmsRecipient((string)null));

            var recipients = new CmsRecipientCollection();

            Assert.AreEqual(0, recipients.Count);
            Assert.IsFalse(recipients.IsReadOnly);
            Assert.Throws <ArgumentNullException> (() => recipients.Add(null));
            Assert.Throws <ArgumentNullException> (() => recipients.Contains(null));
            Assert.Throws <ArgumentNullException> (() => recipients.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => recipients.CopyTo(new CmsRecipient[1], -1));
            Assert.Throws <ArgumentOutOfRangeException> (() => recipients.CopyTo(new CmsRecipient[1], 2));
            Assert.Throws <ArgumentNullException> (() => recipients.Remove(null));
        }