コード例 #1
0
        public void TestEnumerator()
        {
            IDataReader reader     = new DataProvider().GetAllCustomersDataReader();
            var         enumerator = new DataReaderEnumerator(reader);

            Assert.IsTrue(reader.IsClosed);

            Assert.AreEqual(3, enumerator.RowCount);

            Assert.IsTrue(enumerator.MoveNext());
            DataRow dataRow = enumerator.Current;

            Assert.AreEqual(1, dataRow.ItemArray[dataRow.Table.Columns["Id"].Ordinal]);
            Assert.AreEqual("Customer 1", dataRow.ItemArray[dataRow.Table.Columns["Name"].Ordinal]);
            Assert.AreEqual(false, dataRow.ItemArray[dataRow.Table.Columns["IsVip"].Ordinal]);
            Assert.AreEqual(DBNull.Value, dataRow.ItemArray[dataRow.Table.Columns["Type"].Ordinal]);

            Assert.IsTrue(enumerator.MoveNext());
            dataRow = enumerator.Current;
            Assert.AreEqual(2, dataRow.ItemArray[dataRow.Table.Columns["Id"].Ordinal]);
            Assert.AreEqual("Customer 2", dataRow.ItemArray[dataRow.Table.Columns["Name"].Ordinal]);
            Assert.AreEqual(true, dataRow.ItemArray[dataRow.Table.Columns["IsVip"].Ordinal]);
            Assert.AreEqual(1, dataRow.ItemArray[dataRow.Table.Columns["Type"].Ordinal]);

            dataRow = enumerator.Current;
            Assert.AreEqual(2, dataRow.ItemArray[dataRow.Table.Columns["Id"].Ordinal]);
            Assert.AreEqual("Customer 2", dataRow.ItemArray[dataRow.Table.Columns["Name"].Ordinal]);
            Assert.AreEqual(true, dataRow.ItemArray[dataRow.Table.Columns["IsVip"].Ordinal]);
            Assert.AreEqual(1, dataRow.ItemArray[dataRow.Table.Columns["Type"].Ordinal]);

            Assert.IsTrue(enumerator.MoveNext());
            dataRow = enumerator.Current;
            Assert.AreEqual(3, dataRow.ItemArray[dataRow.Table.Columns["Id"].Ordinal]);
            Assert.AreEqual("Customer 3", dataRow.ItemArray[dataRow.Table.Columns["Name"].Ordinal]);
            Assert.AreEqual(DBNull.Value, dataRow.ItemArray[dataRow.Table.Columns["IsVip"].Ordinal]);
            Assert.AreEqual(DBNull.Value, dataRow.ItemArray[dataRow.Table.Columns["Type"].Ordinal]);

            Assert.IsFalse(enumerator.MoveNext());

            Assert.AreEqual(3, enumerator.RowCount);

            enumerator.Reset();

            Assert.AreEqual(3, enumerator.RowCount);

            IList <DataRow> result = new List <DataRow>();

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(3, enumerator.RowCount);
        }
コード例 #2
0
        public bool MoveNext()
        {
            switch (_index)
            {
            case 1:
                return(_reader.MoveNext());

            case 2:
                return(_nv.MoveNext());

            case 3:
                return(_row.MoveNext());

            case 4:
                return(_dataSet.MoveNext());

            case 5:
                return(_enumerator.MoveNext());

            case 6:
                return(_pair.MoveNext());

            case 7:
                return(_property.MoveNext());

            default:
                throw new NotSupportedException();
            }
        }
コード例 #3
0
        public void TestEmptyEnumeratorWithRealSqlReader()
        {
            IDataReader reader     = new DataProvider().GetEmptyDataReader();
            var         enumerator = new DataReaderEnumerator(reader);

            Assert.IsTrue(reader.IsClosed);
            Assert.AreEqual(0, enumerator.RowCount);
            Assert.IsFalse(enumerator.MoveNext());
            Assert.AreEqual(0, enumerator.RowCount);
        }