コード例 #1
0
        public void GetOrdinalWhenTheOrdinalCannotBeFound()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Columns.Add("Direction", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Columns.Add("Sum", typeof(int));

            IDataReader reader = new TableDataReader(table);

            Assert.AreEqual(0, reader.GetOrdinal("NotAColumn"));
        }
コード例 #2
0
        public void FieldCount()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Columns.Add("Direction", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Columns.Add("Sum", typeof(int));

            IDataReader reader = new TableDataReader(table);

            Assert.AreEqual(4, reader.FieldCount);
        }
コード例 #3
0
        public void GetOrdinal()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Columns.Add("Direction", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Columns.Add("Sum", typeof(int));

            IDataReader reader = new TableDataReader(table);

            Assert.AreEqual(0, reader.GetOrdinal("State"));
            Assert.AreEqual(1, reader.GetOrdinal("Direction"));
            Assert.AreEqual(2, reader.GetOrdinal("Count"));
            Assert.AreEqual(3, reader.GetOrdinal("Sum"));
        }
コード例 #4
0
        public void ClosingFunctionality()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Rows.Add(new object[]{"TX"});
            table.Rows.Add(new object[]{"MO"});
            table.Rows.Add(new object[]{"AR"});

            TableDataReader reader = new TableDataReader(table);

            Assert.IsFalse(reader.IsClosed);
            reader.Close();
            Assert.IsTrue(reader.IsClosed);

            reader = new TableDataReader(table);
            reader.Dispose();
            Assert.IsTrue(reader.IsClosed);
        }
コード例 #5
0
        public void GetValue()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Columns.Add("Direction", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Columns.Add("Sum", typeof(int));

            table.Rows.Add(new object[]{"TX", "North", 1, 2});

            IDataReader reader = new TableDataReader(table);
            reader.Read();

            Assert.AreEqual("TX", (string)reader.GetValue(0));
            Assert.AreEqual("North", (string)reader.GetValue(1));
            Assert.AreEqual(1, (int)reader.GetValue(2));
            Assert.AreEqual(2, (int)reader.GetValue(3));
        }
コード例 #6
0
        public void ReadWithTwoRows()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Rows.Add(new object[]{"TX"});
            table.Rows.Add(new object[]{"MO"});

            TableDataReader reader = new TableDataReader(table);

            // One row, so it should return true the first time, and false the second
            Assert.IsTrue(reader.Read());
            Assert.IsTrue(reader.Read());
            Assert.IsFalse(reader.Read());
        }
コード例 #7
0
        public void ReadWithNoRows()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));

            TableDataReader reader = new TableDataReader(table);

            // No rows, so it should return false
            Assert.IsFalse(reader.Read());
        }
コード例 #8
0
        public void ReadingAClosedReaderThrowsAnException()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Rows.Add(new object[]{"TX"});
            table.Rows.Add(new object[]{"MO"});
            table.Rows.Add(new object[]{"AR"});

            TableDataReader reader = new TableDataReader(table);

            Assert.IsFalse(reader.IsClosed);
            reader.Close();
            Assert.IsTrue(reader.IsClosed);

            reader.Read();
        }
コード例 #9
0
        public void IsDBNull()
        {
            DataTable table = new DataTable();
            table.Columns.Add("State", typeof(string));
            table.Columns.Add("Direction", typeof(string));
            table.Columns.Add("Count", typeof(int));
            table.Columns.Add("Sum", typeof(int));

            table.Rows.Add(new object[]{DBNull.Value, "North", DBNull.Value, 2});

            IDataReader reader = new TableDataReader(table);
            reader.Read();

            Assert.IsTrue(reader.IsDBNull(0));
            Assert.IsFalse(reader.IsDBNull(1));
            Assert.IsTrue(reader.IsDBNull(2));
            Assert.IsFalse(reader.IsDBNull(3));
        }