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

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

private Find ( ) : void
Результат void
        public void Find()
        {
            DataColumn Col = new DataColumn("test_1");
            Col.AllowDBNull = false;
            Col.Unique = true;
            Col.DataType = typeof(long);
            _tbl.Columns.Add(Col);

            Col = new DataColumn("test_2");
            Col.DataType = typeof(string);
            _tbl.Columns.Add(Col);

            DataRowCollection Rows = _tbl.Rows;

            Rows.Add(new object[] { 1, "first" });
            Rows.Add(new object[] { 2, "second" });
            Rows.Add(new object[] { 3, "third" });
            Rows.Add(new object[] { 4, "fourth" });
            Rows.Add(new object[] { 5, "fifth" });

            try
            {
                Rows.Find(1);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(MissingPrimaryKeyException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Table doesn't have a primary key.", e.Message);
            }

            _tbl.PrimaryKey = new DataColumn[] { _tbl.Columns[0] };
            DataRow row = Rows.Find(1);
            Assert.Equal(1L, row[0]);
            row = Rows.Find(2);
            Assert.Equal(2L, row[0]);
            row = Rows.Find("2");
            Assert.Equal(2L, row[0]);

            try
            {
                row = Rows.Find("test");
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(FormatException), e.GetType());
                //Assert.Equal ("Input string was not in a correct format.", e.Message);
            }

            string tes = null;
            row = Rows.Find(tes);
            Assert.Null(row);
            _tbl.PrimaryKey = null;

            try
            {
                Rows.Find(new object[] { 1, "fir" });
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(MissingPrimaryKeyException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Table doesn't have a primary key.", e.Message);
            }

            _tbl.PrimaryKey = new DataColumn[] { _tbl.Columns[0], _tbl.Columns[1] };

            try
            {
                Rows.Find(1);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Expecting 2 value(s) for the key being indexed, but received 1 value(s).", e.Message);
            }

            row = Rows.Find(new object[] { 1, "fir" });
            Assert.Null(row);
            row = Rows.Find(new object[] { 1, "first" });
            Assert.Equal(1L, row[0]);
        }