System.Data.Tests.DataSetTest2.Tables C# (CSharp) Метод

Tables() приватный Метод

private Tables ( ) : void
Результат void
        public void Tables()
        {
            //References by name to tables and relations in a DataSet are case-sensitive. Two or more tables or relations can exist in a DataSet that have the same name, but that differ in case. For example you can have Table1 and table1. In this situation, a reference to one of the tables by name must match the case of the table name exactly, otherwise an exception is thrown. For example, if the DataSet myDS contains tables Table1 and table1, you would reference Table1 by name as myDS.Tables["Table1"], and table1 as myDS.Tables ["table1"]. Attempting to reference either of the tables as myDS.Tables ["TABLE1"] would generate an exception.
            //The case-sensitivity rule does not apply if only one table or relation exists with a particular name. That is, if no other table or relation object in the DataSet matches the name of that particular table or relation object, even by a difference in case, you can reference the object by name using any case and no exception is thrown. For example, if the DataSet has only Table1, you can reference it using myDS.Tables["TABLE1"].
            //The CaseSensitive property of the DataSet does not affect this behavior. The CaseSensitive property

            var ds = new DataSet();

            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();
            DataTable dt3 = new DataTable();
            dt3.TableName = "Table3";
            DataTable dt4 = new DataTable(dt3.TableName.ToUpper());

            // Checking Tables - default value
            //Check default
            Assert.Equal(0, ds.Tables.Count);

            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);
            ds.Tables.Add(dt3);

            // Checking Tables Count
            Assert.Equal(3, ds.Tables.Count);

            // Checking Tables Value 1
            Assert.Equal(dt1, ds.Tables[0]);

            // Checking Tables Value 2
            Assert.Equal(dt2, ds.Tables[1]);

            // Checking Tables Value 3
            Assert.Equal(dt3, ds.Tables[2]);

            // Checking get table by name.ToUpper
            Assert.Equal(dt3, ds.Tables[dt3.TableName.ToUpper()]);

            // Checking get table by name.ToLower
            Assert.Equal(dt3, ds.Tables[dt3.TableName.ToLower()]);

            // Checking Tables add with name case insensetive
            ds.Tables.Add(dt4); //same name as Table3, but different case
            Assert.Equal(4, ds.Tables.Count);

            // Checking get table by name
            Assert.Equal(dt4, ds.Tables[dt4.TableName]);

            // Checking get table by name with diferent case, ArgumentException
            Assert.Throws<ArgumentException>(() => ds.Tables[dt4.TableName.ToLower()]);
        }
DataSetTest2