System.Data.Tests.ForeignKeyConstraintTest.CtorExceptions C# (CSharp) Метод

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

private CtorExceptions ( ) : void
Результат void
        public void CtorExceptions()
        {
            ForeignKeyConstraint fkc;

            DataTable localTable = new DataTable();
            localTable.Columns.Add("Col1", typeof(int));
            localTable.Columns.Add("Col2", typeof(bool));

            //Null
            Assert.Throws<NullReferenceException>(() =>
            {
                fkc = new ForeignKeyConstraint(null, (DataColumn)null);
            });

            //zero length collection
            Assert.Throws<ArgumentException>(() =>
            {
                fkc = new ForeignKeyConstraint(new DataColumn[] { }, new DataColumn[] { });
            });

            //different datasets
            Assert.Throws<InvalidOperationException>(() =>
            {
                fkc = new ForeignKeyConstraint(_ds.Tables[0].Columns[0], localTable.Columns[0]);
            });

            Assert.Throws<InvalidOperationException>(() =>
            {
                fkc = new ForeignKeyConstraint(_ds.Tables[0].Columns[0], localTable.Columns[1]);
            });

            // Cannot create a Key from Columns that belong to
            // different tables.
            Assert.Throws<InvalidConstraintException>(() =>
            {
                fkc = new ForeignKeyConstraint(new DataColumn[] { _ds.Tables[0].Columns[0], _ds.Tables[0].Columns[1] }, new DataColumn[] { localTable.Columns[1], _ds.Tables[1].Columns[0] });
            });
        }