Esempio n. 1
0
        public void Add_InvalidItems_ThrowsArgumentException()
        {
            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();

            Assert.Throws <ArgumentException>(() => collection.Add(new SqlBulkCopyColumnOrderHint(null, SortOrder.Ascending)));
            Assert.Throws <ArgumentException>(() => collection.Add(new SqlBulkCopyColumnOrderHint(null, SortOrder.Unspecified)));
            Assert.Throws <ArgumentException>(() => collection.Add(new SqlBulkCopyColumnOrderHint("", SortOrder.Descending)));
            Assert.Throws <ArgumentException>(() => collection.Add(new SqlBulkCopyColumnOrderHint("", SortOrder.Unspecified)));
            Assert.Throws <ArgumentException>(() => collection.Add(new SqlBulkCopyColumnOrderHint("column", SortOrder.Unspecified)));

            IList list = CreateCollection();

            Assert.Throws <ArgumentException>(() => list.Add(new SqlBulkCopyColumnOrderHint(null, SortOrder.Ascending)));
            Assert.Throws <ArgumentException>(() => list.Add(new SqlBulkCopyColumnOrderHint(null, SortOrder.Unspecified)));
            Assert.Throws <ArgumentException>(() => list.Add(new SqlBulkCopyColumnOrderHint("", SortOrder.Descending)));
            Assert.Throws <ArgumentException>(() => list.Add(new SqlBulkCopyColumnOrderHint("", SortOrder.Unspecified)));
            Assert.Throws <ArgumentException>(() => list.Add(new SqlBulkCopyColumnOrderHint("column", SortOrder.Unspecified)));
        }
Esempio n. 2
0
        public void Add_HelperOverloads_ItemsAddedAsExpected()
        {
            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();
            SqlBulkCopyColumnOrderHint           item;

            item = collection.Add("column1", SortOrder.Ascending);
            Assert.NotNull(item);
            Assert.Equal("column1", item.Column);
            Assert.Equal(SortOrder.Ascending, item.SortOrder);
        }
Esempio n. 3
0
        public void Methods_NullParameterPassed_ThrowsArgumentNullException()
        {
            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();

            collection.Add(new SqlBulkCopyColumnOrderHint("column", SortOrder.Ascending));

            Assert.Throws <ArgumentNullException>(() => collection.CopyTo(null, 0));
            Assert.Throws <ArgumentNullException>(() => collection.Add(null));

            Assert.Throws <ArgumentNullException>(() => collection.Insert(0, null));
            Assert.Throws <ArgumentNullException>(() => collection.Remove(null));

            IList list = collection;

            Assert.Throws <ArgumentNullException>(() => list[0] = null);
            Assert.Throws <ArgumentNullException>(() => list.Add(null));
            Assert.Throws <ArgumentNullException>(() => list.CopyTo(null, 0));
            Assert.Throws <ArgumentNullException>(() => list.Insert(0, null));
            Assert.Throws <ArgumentNullException>(() => list.Remove(null));
        }
Esempio n. 4
0
        public void Add_AddItems_ItemsAddedAsEpected()
        {
            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();
            var item1 = new SqlBulkCopyColumnOrderHint("column1", SortOrder.Ascending);

            Assert.Same(item1, collection.Add(item1));
            Assert.Same(item1, collection[0]);
            var item2 = new SqlBulkCopyColumnOrderHint("column2", SortOrder.Descending);

            Assert.Same(item2, collection.Add(item2));
            Assert.Same(item2, collection[1]);

            IList list  = CreateCollection();
            int   index = list.Add(item1);

            Assert.Equal(0, index);
            Assert.Same(item1, list[0]);
            index = list.Add(item2);
            Assert.Equal(1, index);
            Assert.Same(item2, list[1]);
        }
Esempio n. 5
0
        public void GetEnumerator_ModifiedCollectionDuringEnumeration_ThrowsInvalidOperationException()
        {
            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();

            IEnumerator e = collection.GetEnumerator();

            collection.Add("column", SortOrder.Ascending);

            // Collection changed.
            Assert.Throws <InvalidOperationException>(() => e.MoveNext());
            Assert.Throws <InvalidOperationException>(() => e.Reset());
        }
Esempio n. 6
0
        private static SqlBulkCopyColumnOrderHintCollection CreateCollection(params SqlBulkCopyColumnOrderHint[] orderHints)
        {
            Assert.NotNull(orderHints);

            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();

            foreach (SqlBulkCopyColumnOrderHint orderHint in orderHints)
            {
                collection.Add(orderHint);
            }

            return(collection);
        }
Esempio n. 7
0
        public void Add_DuplicateColumnNames_NotAllowed()
        {
            SqlBulkCopyColumnOrderHintCollection collection1 = CreateCollection();
            SqlBulkCopyColumnOrderHintCollection collection2 = CreateCollection();
            var item1 = new SqlBulkCopyColumnOrderHint("column1", SortOrder.Ascending);

            collection1.Add(item1);
            item1.Column          += "2";
            collection1[0].Column += "3";
            Assert.Equal("column123", item1.Column);
            Assert.Throws <InvalidOperationException>(() => collection1.Add(item1));

            collection2.Add(item1);
            item1.Column += "4";
            Assert.Same(collection1[0], collection2[0]);
            Assert.Equal("column1234", collection1[0].Column);

            item1.Column = "column1";
            collection1.Add("column2", SortOrder.Ascending);
            item1.Column          = "column1";
            collection1[0].Column = "column1";
            collection1[1].Column = "column2";
            Assert.Throws <InvalidOperationException>(() => item1.Column          = "column2");
            Assert.Throws <InvalidOperationException>(() => collection1[0].Column = "column2");
            Assert.Throws <InvalidOperationException>(() => collection1[1].Column = "column1");
            Assert.Throws <InvalidOperationException>(() => collection2[0].Column = "column2");
            Assert.Equal("column1", collection1[0].Column);
            Assert.Equal("column2", collection1[1].Column);
            ValidateCollection(collection1, expectedCount: 2);

            Assert.Throws <InvalidOperationException>(() => collection2.Add(collection1[0]));
            collection2.Add(collection1[1]);
            var item3 = new SqlBulkCopyColumnOrderHint("column1", SortOrder.Ascending);

            Assert.Throws <InvalidOperationException>(() => collection1.Add(item3));
            item3.Column = "column3";
            collection1.Add(item3);
            ValidateCollection(collection1, expectedCount: 3);
            ValidateCollection(collection2, expectedCount: 2);

            Assert.Throws <InvalidOperationException>(() => collection1.Insert(0, new SqlBulkCopyColumnOrderHint("column3", SortOrder.Ascending)));
            collection1.Insert(0, new SqlBulkCopyColumnOrderHint("column4", SortOrder.Ascending));
            collection1.Insert(collection1.Count, new SqlBulkCopyColumnOrderHint("column5", SortOrder.Ascending));
            Assert.Throws <InvalidOperationException>(() => collection1[collection1.IndexOf(item1)].Column = "column4");
            ValidateCollection(collection1, expectedCount: 5);

            collection2.Remove(item1);
            Assert.Throws <InvalidOperationException>(() => collection2[0].Column = item1.Column);
            collection2[0].Column = "column6";
            ValidateCollection(collection2, expectedCount: 1);

            collection1.Clear();
            Assert.Empty(collection1);
            collection1.Add("column1", SortOrder.Descending);
            collection1.Add("column2", SortOrder.Descending);
            collection1.Add("column3", SortOrder.Descending);
            collection2[0].Column = collection1[0].Column;
            Assert.Throws <InvalidOperationException>(() => collection1.Add(collection2[0]));
            ValidateCollection(collection1, expectedCount: 3);
            collection1.RemoveAt(0);
            collection1.Add(collection2[0]);
            collection1.Remove(collection1[collection1.Count - 1]);
            collection1.RemoveAt(1);
            collection1.Remove(collection1[collection1.Count - 1]);
            collection1.Add("column1", SortOrder.Descending);
            collection1.Add("column2", SortOrder.Descending);
            collection1.Add("column3", SortOrder.Descending);
            collection1.Add("column4", SortOrder.Descending);
            collection1.Add("column5", SortOrder.Descending);
            ValidateCollection(collection1, expectedCount: 5);
        }
Esempio n. 8
0
        public void InsertAndClear_BehavesAsExpected()
        {
            var item1 = new SqlBulkCopyColumnOrderHint("column1", SortOrder.Ascending);
            var item2 = new SqlBulkCopyColumnOrderHint("column2", SortOrder.Descending);
            var item3 = new SqlBulkCopyColumnOrderHint("column3", SortOrder.Ascending);

            SqlBulkCopyColumnOrderHintCollection collection = CreateCollection();

            collection.Insert(0, item1);
            collection.Insert(1, item2);
            collection.Insert(2, item3);
            Assert.Equal(3, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item2, collection[1]);
            Assert.Same(item3, collection[2]);

            collection.Clear();
            Assert.Empty(collection);

            collection.Add(item1);
            collection.Add(item3);
            Assert.Equal(2, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item3, collection[1]);

            collection.Insert(1, item2);
            Assert.Equal(3, collection.Count);
            Assert.Same(item1, collection[0]);
            Assert.Same(item2, collection[1]);
            Assert.Same(item3, collection[2]);

            collection.Clear();
            Assert.Empty(collection);

            IList list = collection;

            list.Insert(0, item1);
            list.Insert(1, item2);
            list.Insert(2, item3);
            Assert.Equal(3, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item2, list[1]);
            Assert.Same(item3, list[2]);

            list.Clear();
            Assert.Equal(0, list.Count);

            list.Add(item1);
            list.Add(item3);
            Assert.Equal(2, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item3, list[1]);

            list.Insert(1, item2);
            Assert.Equal(3, list.Count);
            Assert.Same(item1, list[0]);
            Assert.Same(item2, list[1]);
            Assert.Same(item3, list[2]);

            list.Clear();
            Assert.Equal(0, list.Count);
        }