示例#1
0
        public void CopyToTest()
        {
            var set   = new IndexedSet <string>();
            var array = new string[2];

            Assert.IsEmpty(set);
            Assert.That(array, Is.All.Null);

            set.CopyTo(array, 0);

            Assert.IsEmpty(set);
            Assert.That(array, Is.All.Null);

            set.Add("A");
            set.Add("B");
            set.CopyTo(array, 0);

            Assert.That(set.Count, Is.EqualTo(2));
            Assert.That(set, Contains.Item("A").And.Contains("B"));
            Assert.That(array.Length, Is.EqualTo(2));
            Assert.That(array, Is.All.Not.Null);
            Assert.That(array, Contains.Item("A").And.Contains("B"));
            Assert.That(array[0], Is.EqualTo("A"));
            Assert.That(array[1], Is.EqualTo("B"));
        }
示例#2
0
        public void CopyToExceptions()
        {
            int[] array = null;
            Assert.That(() => set.CopyTo(array, 0),
                        Throws.Exception.TypeOf <ArgumentNullException>());

            array = new int[3];
            Assert.That(() => set.CopyTo(array, -1),
                        Throws.Exception.TypeOf <ArgumentOutOfRangeException>());


            Assert.That(() => set.CopyTo(array, 1),
                        Throws.Exception.TypeOf <ArgumentException>());

            Assert.That(() => set.CopyTo(array, 2),
                        Throws.Exception.TypeOf <ArgumentException>());

            Assert.That(() => set.CopyTo(array, set.Count),
                        Throws.Exception.TypeOf <ArgumentException>());

            array = new int[2];

            Assert.That(() => set.CopyTo(array, 0),
                        Throws.Exception.TypeOf <ArgumentException>());

            Assert.That(() => set.CopyTo(array, 1),
                        Throws.Exception.TypeOf <ArgumentException>());
        }