public static void RemoveNonExistent() { CmsRecipientCollection c = new CmsRecipientCollection(); CmsRecipient a0 = s_cr0; c.Remove(a0); // You can "remove" items that aren't in the collection - this is defined as a NOP. }
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(); }
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)); }
public static void Remove() { CmsRecipient a0 = s_cr0; CmsRecipient a1 = s_cr1; CmsRecipient a2 = s_cr2; CmsRecipientCollection c = new CmsRecipientCollection(); int index; index = c.Add(a0); Assert.Equal(0, index); index = c.Add(a1); Assert.Equal(1, index); index = c.Add(a2); Assert.Equal(2, index); c.Remove(a1); AssertEquals(c, new CmsRecipient[] { a0, a2 }); }
public static void RemoveNegative() { CmsRecipientCollection c = new CmsRecipientCollection(); Assert.Throws <ArgumentNullException>(() => c.Remove(null)); }