Exemple #1
0
        public static void CopyExceptions()
        {
            CryptographicAttributeObject a0 = s_ca0;
            CryptographicAttributeObject a1 = s_ca1;
            CryptographicAttributeObject a2 = s_ca2;

            CryptographicAttributeObjectCollection c = new CryptographicAttributeObjectCollection();

            c.Add(a0);
            c.Add(a1);
            c.Add(a2);

            CryptographicAttributeObject[] a = new CryptographicAttributeObject[3];
            Assert.Throws <ArgumentNullException>(() => c.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(a, 3));
            AssertExtensions.Throws <ArgumentException>(null, () => c.CopyTo(a, 1));

            ICollection ic = c;

            Assert.Throws <ArgumentNullException>(() => ic.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => ic.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => ic.CopyTo(a, 3));
            AssertExtensions.Throws <ArgumentException>(null, () => ic.CopyTo(a, 1));
            AssertExtensions.Throws <ArgumentException>(null, () => ic.CopyTo(new CryptographicAttributeObject[2, 2], 0));
            Assert.Throws <InvalidCastException>(() => ic.CopyTo(new int[10], 0));

            if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
            {
                // Array has non-zero lower bound
                Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
                Assert.Throws <IndexOutOfRangeException>(() => ic.CopyTo(array, 0));
            }
        }
        public static void CopyExceptions()
        {
            CryptographicAttributeObject a0 = s_ca0;
            CryptographicAttributeObject a1 = s_ca1;
            CryptographicAttributeObject a2 = s_ca2;

            CryptographicAttributeObjectCollection c = new CryptographicAttributeObjectCollection();

            c.Add(a0);
            c.Add(a1);
            c.Add(a2);

            CryptographicAttributeObject[] a = new CryptographicAttributeObject[3];
            Assert.Throws <ArgumentNullException>(() => c.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => c.CopyTo(a, 3));
            Assert.Throws <ArgumentException>(() => c.CopyTo(a, 1));

            ICollection ic = c;

            Assert.Throws <ArgumentNullException>(() => ic.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => ic.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => ic.CopyTo(a, 3));
            Assert.Throws <ArgumentException>(() => ic.CopyTo(a, 1));
            Assert.Throws <ArgumentException>(() => ic.CopyTo(new CryptographicAttributeObject[2, 2], 0));
            Assert.Throws <InvalidCastException>(() => ic.CopyTo(new int[10], 0));
        }
        private void CommonStuff(CryptographicAttributeObjectCollection coll)
        {
            Assert.IsFalse(coll.IsSynchronized, "IsSynchronized");
            Assert.AreSame(coll, coll.SyncRoot, "SyncRoot");
            Assert.IsNotNull(coll.GetEnumerator(), "GetEnumerator");

            int            i   = coll.Count;
            Oid            o1  = new Oid("1.2.840.113549.1.7.3");
            AsnEncodedData aed = new AsnEncodedData(o1, new byte[] { 0x05, 0x00 });

            Assert.AreEqual(i, coll.Add(aed), "Add(AsnEncodedData)");
            Assert.IsTrue((coll[i++] is CryptographicAttributeObject), "converted");

            Oid o2 = new Oid("1.2.840.113549.1.7.2");
            CryptographicAttributeObject cao = new CryptographicAttributeObject(o2);

            Assert.AreEqual(i, coll.Add(cao), "Add(CryptographicAttributeObject)");

            CryptographicAttributeObject[] array = new CryptographicAttributeObject [coll.Count];
            coll.CopyTo(array, 0);

            Array       a = (Array) new object [coll.Count];
            ICollection c = (ICollection)coll;

            c.CopyTo(a, 0);

            IEnumerable e = (IEnumerable)coll;

            Assert.IsNotNull(e.GetEnumerator(), "GetEnumerator");

            coll.Remove(cao);
            Assert.AreEqual(i, coll.Count, "Remove(CryptographicAttributeObject)");
        }
Exemple #4
0
        private static void AssertEquals(CryptographicAttributeObjectCollection c, IList <CryptographicAttributeObject> expected)
        {
            Assert.Equal(expected.Count, c.Count);

            for (int i = 0; i < c.Count; i++)
            {
                Assert.Equal(expected[i], c[i], s_CryptographicAttributeObjectComparer);
            }

            int index = 0;

            foreach (CryptographicAttributeObject a in c)
            {
                Assert.Equal(expected[index++], a, s_CryptographicAttributeObjectComparer);
            }
            Assert.Equal(c.Count, index);

            ValidateEnumerator(c.GetEnumerator(), expected);
            ValidateEnumerator(((ICollection)c).GetEnumerator(), expected);

            {
                CryptographicAttributeObject[] dumped = new CryptographicAttributeObject[c.Count + 3];
                c.CopyTo(dumped, 2);
                Assert.Null(dumped[0]);
                Assert.Null(dumped[1]);
                Assert.Null(dumped[dumped.Length - 1]);
                for (int i = 0; i < expected.Count; i++)
                {
                    Assert.Equal(expected[i], dumped[i + 2], s_CryptographicAttributeObjectComparer);
                }
            }
            {
                CryptographicAttributeObject[] dumped = new CryptographicAttributeObject[c.Count + 3];
                ((ICollection)c).CopyTo(dumped, 2);
                Assert.Null(dumped[0]);
                Assert.Null(dumped[1]);
                Assert.Null(dumped[dumped.Length - 1]);
                for (int i = 0; i < expected.Count; i++)
                {
                    Assert.Equal(expected[i], dumped[i + 2], s_CryptographicAttributeObjectComparer);
                }
            }
        }