System.Data.Tests.DataColumnTest2.AllowDBNull C# (CSharp) Method

AllowDBNull() private method

private AllowDBNull ( ) : void
return void
        public void AllowDBNull()
        {
            DataTable dt = new DataTable();
            DataColumn dc;
            dc = new DataColumn("ColName", typeof(int));
            dc.DefaultValue = DBNull.Value;
            dt.Columns.Add(dc);
            dc.AutoIncrement = false;

            // Checking default value (True)
            Assert.Equal(true, dc.AllowDBNull);

            // AllowDBNull=true - adding new row with null value
            dt.Rows.Add(dt.NewRow());
            Assert.Equal(DBNull.Value, dt.Rows[0][0]);

            // set AllowDBNull=false 
            Assert.Throws<DataException>(() =>
            {
                dc.AllowDBNull = false; //the exisiting row contains null value
            });

            dt.Rows.Clear();
            dc.AllowDBNull = false;
            // AllowDBNull=false - adding new row with null value
            Assert.Throws<NoNullAllowedException>(() =>
            {
                dt.Rows.Add(dt.NewRow());
            });

            dc.AutoIncrement = true;
            int iRowCount = dt.Rows.Count;
            // AllowDBNull=false,AutoIncrement=true - adding new row with null value
            dt.Rows.Add(dt.NewRow());
            Assert.Equal(dt.Rows.Count, iRowCount + 1);
        }