Exemplo n.º 1
0
        public void IndexOf_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(item1, item2);

            Assert.Equal(0, collection.IndexOf(item1));
            Assert.Equal(1, collection.IndexOf(item2));
            Assert.Equal(-1, collection.IndexOf(item3));

            IList list = collection;

            Assert.Equal(0, list.IndexOf(item1));
            Assert.Equal(1, list.IndexOf(item2));
            Assert.Equal(-1, list.IndexOf(item3));
            Assert.Equal(-1, list.IndexOf("bogus"));
        }
Exemplo n.º 2
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);
        }