public void Insert() { X509CertificateCollection c = new X509CertificateCollection(); c.Add(x509a); Assert.AreEqual(0, c.IndexOf(x509a), "a=0"); c.Add(x509c); Assert.AreEqual(1, c.IndexOf(x509c), "c=1"); c.Insert(1, x509b); Assert.AreEqual(1, c.IndexOf(x509b), "1"); Assert.AreEqual(2, c.IndexOf(x509c), "2"); }
public int Init() { IntPtr storeHandle; storeHandle = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, "MY"); IntPtr currentCertContext; currentCertContext = CertEnumCertificatesInStore(storeHandle, (IntPtr)0); int i = 0; while (currentCertContext != (IntPtr)0) { m_certs.Insert(i++, new X509Certificate(currentCertContext)); currentCertContext = CertEnumCertificatesInStore(storeHandle, currentCertContext); } CertCloseStore(storeHandle, 0); return(m_certs.Count); }
public static void X509CertificateCollectionAsIList() { using (X509Certificate2 c1 = new X509Certificate2()) using (X509Certificate2 c2 = new X509Certificate2()) { IList il = new X509CertificateCollection(); il.Add(c1); il.Add(c2); Assert.Throws<ArgumentNullException>(() => il[0] = null); string bogus = "Bogus"; Assert.Throws<ArgumentException>(() => il[0] = bogus); Assert.Throws<ArgumentException>(() => il.Add(bogus)); Assert.Throws<ArgumentException>(() => il.Insert(0, bogus)); } }
public static void X509CertificateCollectionThrowsArgumentOutOfRangeException() { using (X509Certificate certificate = new X509Certificate()) { X509CertificateCollection collection = new X509CertificateCollection { certificate }; Assert.Throws<ArgumentOutOfRangeException>(() => collection[-1]); Assert.Throws<ArgumentOutOfRangeException>(() => collection[collection.Count]); Assert.Throws<ArgumentOutOfRangeException>(() => collection[-1] = certificate); Assert.Throws<ArgumentOutOfRangeException>(() => collection[collection.Count] = certificate); Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(-1, certificate)); Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(collection.Count + 1, certificate)); Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(collection.Count)); IList ilist = (IList)collection; Assert.Throws<ArgumentOutOfRangeException>(() => ilist[-1]); Assert.Throws<ArgumentOutOfRangeException>(() => ilist[collection.Count]); Assert.Throws<ArgumentOutOfRangeException>(() => ilist[-1] = certificate); Assert.Throws<ArgumentOutOfRangeException>(() => ilist[collection.Count] = certificate); Assert.Throws<ArgumentOutOfRangeException>(() => ilist.Insert(-1, certificate)); Assert.Throws<ArgumentOutOfRangeException>(() => ilist.Insert(collection.Count + 1, certificate)); Assert.Throws<ArgumentOutOfRangeException>(() => ilist.RemoveAt(-1)); Assert.Throws<ArgumentOutOfRangeException>(() => ilist.RemoveAt(collection.Count)); } }
public static void X509CertificateCollectionThrowsArgumentNullException() { using (X509Certificate certificate = new X509Certificate()) { Assert.Throws<ArgumentNullException>(() => new X509CertificateCollection((X509Certificate[])null)); Assert.Throws<ArgumentNullException>(() => new X509CertificateCollection((X509CertificateCollection)null)); X509CertificateCollection collection = new X509CertificateCollection { certificate }; Assert.Throws<ArgumentNullException>(() => collection[0] = null); Assert.Throws<ArgumentNullException>(() => collection.Add(null)); Assert.Throws<ArgumentNullException>(() => collection.AddRange((X509Certificate[])null)); Assert.Throws<ArgumentNullException>(() => collection.AddRange((X509CertificateCollection)null)); Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 0)); Assert.Throws<ArgumentNullException>(() => collection.Insert(0, null)); Assert.Throws<ArgumentNullException>(() => collection.Remove(null)); IList ilist = (IList)collection; Assert.Throws<ArgumentNullException>(() => ilist[0] = null); Assert.Throws<ArgumentNullException>(() => ilist.Add(null)); Assert.Throws<ArgumentNullException>(() => ilist.CopyTo(null, 0)); Assert.Throws<ArgumentNullException>(() => ilist.Insert(0, null)); Assert.Throws<ArgumentNullException>(() => ilist.Remove(null)); } Assert.Throws<ArgumentNullException>(() => new X509CertificateCollection.X509CertificateEnumerator(null)); }
public static void X509CertificateCollectionInsertAndClear() { using (X509Certificate c1 = new X509Certificate()) using (X509Certificate c2 = new X509Certificate()) using (X509Certificate c3 = new X509Certificate()) { X509CertificateCollection cc = new X509CertificateCollection(); cc.Insert(0, c1); cc.Insert(1, c2); cc.Insert(2, c3); Assert.Equal(3, cc.Count); Assert.Same(c1, cc[0]); Assert.Same(c2, cc[1]); Assert.Same(c3, cc[2]); cc.Clear(); Assert.Equal(0, cc.Count); cc.Add(c1); cc.Add(c3); Assert.Equal(2, cc.Count); Assert.Same(c1, cc[0]); Assert.Same(c3, cc[1]); cc.Insert(1, c2); Assert.Equal(3, cc.Count); Assert.Same(c1, cc[0]); Assert.Same(c2, cc[1]); Assert.Same(c3, cc[2]); cc.Clear(); Assert.Equal(0, cc.Count); IList il = cc; il.Insert(0, c1); il.Insert(1, c2); il.Insert(2, c3); Assert.Equal(3, il.Count); Assert.Same(c1, il[0]); Assert.Same(c2, il[1]); Assert.Same(c3, il[2]); il.Clear(); Assert.Equal(0, il.Count); il.Add(c1); il.Add(c3); Assert.Equal(2, il.Count); Assert.Same(c1, il[0]); Assert.Same(c3, il[1]); il.Insert(1, c2); Assert.Equal(3, il.Count); Assert.Same(c1, il[0]); Assert.Same(c2, il[1]); Assert.Same(c3, il[2]); il.Clear(); Assert.Equal(0, il.Count); } }
public static void X509CertificateCollectionAsIListBogusEntry() { using (X509Certificate2 c = new X509Certificate2()) { IList il = new X509CertificateCollection(); il.Add(c); string bogus = "Bogus"; Assert.Throws<ArgumentException>(() => il[0] = bogus); Assert.Throws<ArgumentException>(() => il.Add(bogus)); Assert.Throws<ArgumentException>(() => il.Remove(bogus)); Assert.Throws<ArgumentException>(() => il.Insert(0, bogus)); } }