コード例 #1
0
        public void StubDataReader_IndexAccessors_Read_Success()
        {
            using (var reader = new StubDataReader(new StubResultSet("abc", "def").AddRow(3, "nice")))
            {
                Assert.IsTrue(reader.Read(), "First call to Read() should have had data");
                Assert.AreEqual(3, reader[0], "The first column (by index) was not correct");
                Assert.AreEqual("nice", reader["def"], "The second column (by name) was not correct");

                Assert.IsFalse(reader.Read(), "Second call to Read() should not have had data");
            }
        }
コード例 #2
0
        public void NullUtils_GetBoolean_NotNull_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(true));

            reader.Read();
            Assert.IsTrue(NullUtils.GetBoolean(reader, "unit_test"), "GetBoolean(true) should have returned true");
        }
コード例 #3
0
        public void NullUtils_GetDateTimeOrNull_Null_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(DBNull.Value));

            reader.Read();
            Assert.IsNull(NullUtils.GetDateTimeOrNull(reader, "unit_test"),
                          "GetDateTime(null) should have returned null");
        }
コード例 #4
0
        public void NullUtils_GetDateTime_Value_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(new DateTime(2004, 12, 13)));

            reader.Read();
            Assert.AreEqual(new DateTime(2004, 12, 13), NullUtils.GetDateTime(reader, "unit_test"),
                            "GetDateTime(value) should have returned a value");
        }
コード例 #5
0
        public void NullUtils_GetDateTime_Null_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(DBNull.Value));

            reader.Read();
            Assert.AreEqual(default(DateTime), NullUtils.GetDateTime(reader, "unit_test"),
                            "GetDateTime(null) should not have returned a default DateTime");
        }
コード例 #6
0
        public void NullUtils_GetStringOrNull_Value_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow("123"));

            reader.Read();
            Assert.AreEqual("123", NullUtils.GetStringOrNull(reader, "unit_test"),
                            "GetStringOrNull(value) did not return the expected value");
        }
コード例 #7
0
        public void NullUtils_GetString_Null_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(DBNull.Value));

            reader.Read();
            Assert.AreEqual(String.Empty, NullUtils.GetString(reader, "unit_test"),
                            "GetString(null) should have returned an empty string");
        }
コード例 #8
0
        public void NullUtils_GetInt64_Value_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(5L));

            reader.Read();
            Assert.AreEqual(5L, NullUtils.GetInt64(reader, "unit_test"),
                            "GetInt64(value) did not return the expected value");
        }
コード例 #9
0
        public void NullUtils_GetInt64_Null_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(DBNull.Value));

            reader.Read();
            Assert.AreEqual(default(long), NullUtils.GetInt64(reader, "unit_test"),
                            "GetInt64(null) should have returned the default long value");
        }
コード例 #10
0
        public void NullUtils_GetInt16OrNull_Value_Success()
        {
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow((short)17));

            reader.Read();
            Assert.AreEqual((short)17, NullUtils.GetInt16OrNull(reader, "unit_test").Value,
                            "GetInt16OrNull(value) did not return the expected value");
        }
コード例 #11
0
 public void StubDataReader_GetFieldType_Success()
 {
     using (var reader = new StubDataReader(new StubResultSet("more", "fun").AddRow(8, "yowza")))
     {
         reader.Read();
         Assert.AreEqual(typeof(int), reader.GetFieldType(0));
         Assert.AreEqual(typeof(string), reader.GetFieldType(1));
     }
 }
コード例 #12
0
        public void NullUtils_GetGuidOrNull_Value_Success()
        {
            var guid   = Guid.NewGuid();
            var reader = new StubDataReader(new StubResultSet("unit_test").AddRow(guid));

            reader.Read();
            Assert.AreEqual(guid, NullUtils.GetGuidOrNull(reader, "unit_test").Value,
                            "GetGuidOrNull(value) did not return the expected value");
        }
コード例 #13
0
        public void StubDataReader_IndexAccessors_EOF_Failure()
        {
            using (var reader = new StubDataReader(new StubResultSet()))
            {
                Assert.IsFalse(reader.Read(), "Read() should not have had data");

                try
                {
                    var column = reader[0];
                    Assert.Fail("Index accessor should have thrown an exception (EOF)");
                }
                catch (InvalidOperationException) { }
            }
        }
コード例 #14
0
        public void IsDBNull_NotNull_Test()
        {
            StubResultSetCollection stubResultSets = new StubResultSetCollection();

            stubResultSets.Add(CreateIsDBNullResultSet());

            StubDataReader target = new StubDataReader(stubResultSets);

            target.Read();
            int  i        = 2;
            bool expected = false;
            bool actual;

            actual = target.IsDBNull(i);
            Assert.AreEqual(expected, actual);
        }