This class fakes up a data reader.
Inheritance: IDataReader
Beispiel #1
0
        public void SingleResultStubDataReaderReturnsCorrectValues()
        {
            DateTime testDate = DateTime.Now;
            StubResultSet resultSet = new StubResultSet("col0", "col1", "col2");
            resultSet.AddRow(1, "Test", testDate);
            resultSet.AddRow(2, "Test2", testDate.AddDays(1));

            StubDataReader reader = new StubDataReader(resultSet);

            //Advance to first row.
            Assert.IsTrue(reader.Read(), "Expected data.");

            Assert.AreEqual(1, reader["col0"], "Misread row 0, col 0.");
            Assert.AreEqual("Test", reader["col1"], "Misread row 0, col 1.");
            Assert.AreEqual(testDate, reader["col2"], "Misread row 0, col 3.");
            Assert.AreEqual(1, reader.GetInt32(0), "Misread row 0, col 0.");
            Assert.AreEqual("Test", reader.GetString(1), "Misread row 0, col 1.");
            Assert.AreEqual(testDate, reader.GetDateTime(2), "Misread row 0, col 3.");
            Assert.AreEqual(1, reader[0], "Misread row 0, col 0.");
            Assert.AreEqual("Test", reader[1], "Misread row 0, col 1.");
            Assert.AreEqual(testDate, reader[2], "Misread row 0, col 3.");

            //Advance to second row.
            Assert.IsTrue(reader.Read(), "Expected data.");

            Assert.AreEqual(2, reader.GetInt32(0), "Misread row 1, col 0.");
            Assert.AreEqual("Test2", reader.GetString(1), "Misread row 1, col 1.");
            Assert.AreEqual(testDate.AddDays(1), reader.GetDateTime(2), "Misread row 1, col 3.");
            Assert.AreEqual(2, reader[0], "Misread row 1, col 0.");
            Assert.AreEqual("Test2", reader[1], "Misread row 1, col 1.");
            Assert.AreEqual(testDate.AddDays(1), reader[2], "Misread row 1, col 3.");
            Assert.AreEqual(2, reader["col0"], "Misread row 1, col 0.");
            Assert.AreEqual("Test2", reader["col1"], "Misread row 1, col 1.");
            Assert.AreEqual(testDate.AddDays(1), reader["col2"], "Misread row 1, col 3.");
        }
Beispiel #2
0
        public void MultipleResultStubDataReaderReturnsCorrectValues()
        {
            DateTime testDate = DateTime.Now;
            StubResultSet resultSet = new StubResultSet("col0", "col1", "col2");
            resultSet.AddRow(1, "Test", testDate);

            StubResultSet anotherResultSet = new StubResultSet("first", "second");
            anotherResultSet.AddRow((decimal)1.618, "Foo");
            anotherResultSet.AddRow((decimal)2.718, "Bar");
            anotherResultSet.AddRow((decimal)3.142, "Baz");

            StubDataReader reader = new StubDataReader(resultSet, anotherResultSet);

            //Advance to first row.
            Assert.IsTrue(reader.Read(), "Expected data.");

            Assert.AreEqual(1, reader["col0"]);

            //Advance to second ResultSet.
            Assert.IsTrue(reader.NextResult(), "Expected next result set");

            //Advance to first row.
            Assert.IsTrue(reader.Read(), "Expected data.");
            Assert.AreEqual((decimal)1.618, reader["first"]);
            Assert.AreEqual("Foo", reader["second"]);
            Assert.IsTrue(reader.Read(), "Expected data.");
            Assert.AreEqual((decimal)2.718, reader["first"]);
            Assert.AreEqual("Bar", reader["second"]);
            Assert.IsTrue(reader.Read(), "Expected data.");
            Assert.AreEqual((decimal)3.142, reader["first"]);
            Assert.AreEqual("Baz", reader["second"]);
        }
Beispiel #3
0
 public IDataReader GetData(int i)
 {
     StubDataReader reader = new StubDataReader(this.stubResultSets);
     reader.currentResultsetIndex = i;
     return reader;
 }