System.Data.Tests.DataRowCollectionTest.Add C# (CSharp) Метод

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

private Add ( ) : void
Результат void
        public void Add()
        {
            _tbl.Columns.Add();
            _tbl.Columns.Add();
            DataRow Row = _tbl.NewRow();
            DataRowCollection Rows = _tbl.Rows;

            Rows.Add(Row);
            Assert.Equal(1, Rows.Count);
            Assert.False(Rows.IsReadOnly);
            Assert.False(Rows.IsSynchronized);
            Assert.Equal("System.Data.DataRowCollection", Rows.ToString());

            string[] cols = new string[2];
            cols[0] = "first";
            cols[1] = "second";

            Rows.Add(cols);
            cols[0] = "something";
            cols[1] = "else";
            Rows.Add(cols);

            Assert.Equal(3, Rows.Count);
            Assert.Equal("System.Data.DataRow", Rows[0].ToString());
            Assert.Equal(DBNull.Value, Rows[0][0]);
            Assert.Equal(DBNull.Value, Rows[0][1]);
            Assert.Equal("first", Rows[1][0]);
            Assert.Equal("something", Rows[2][0]);
            Assert.Equal("second", Rows[1][1]);
            Assert.Equal("else", Rows[2][1]);

            try
            {
                Rows.Add(Row);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                // Never premise English.
                //Assert.Equal ("This row already belongs to this table.", e.Message);
            }

            try
            {
                Row = null;
                Rows.Add(Row);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentNullException), e.GetType());
                //Assert.Equal ("'row' argument cannot be null.\r\nParameter name: row", e.Message);
            }

            DataColumn Column = new DataColumn("not_null");
            Column.AllowDBNull = false;
            _tbl.Columns.Add(Column);

            cols = new string[3];
            cols[0] = "first";
            cols[1] = "second";
            cols[2] = null;

            try
            {
                Rows.Add(cols);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(NoNullAllowedException), e.GetType());
                //Assert.Equal ("Column 'not_null' does not allow nulls.", e.Message);
            }

            Column = _tbl.Columns[0];
            Column.Unique = true;

            cols = new string[3];
            cols[0] = "first";
            cols[1] = "second";
            cols[2] = "blabal";

            try
            {
                Rows.Add(cols);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ConstraintException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Column 'Column1' is constrained to be unique.  Value 'first' is already present.", e.Message);
            }

            Column = new DataColumn("integer");
            Column.DataType = typeof(short);
            _tbl.Columns.Add(Column);

            object[] obs = new object[4];
            obs[0] = "_first";
            obs[1] = "second";
            obs[2] = "blabal";
            obs[3] = "ads";

            try
            {
                Rows.Add(obs);
                Assert.False(true);
            }
            catch (ArgumentException e)
            {
                // LAMESPEC: MSDN says this exception is InvalidCastException
                //				Assert.Equal (typeof (ArgumentException), e.GetType ());
            }

            object[] obs1 = new object[5];
            obs1[0] = "A";
            obs1[1] = "B";
            obs1[2] = "C";
            obs1[3] = 38;
            obs1[4] = "Extra";
            try
            {
                Rows.Add(obs1);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentException), e.GetType());
            }
        }