예제 #1
0
        public void Ctor_sets_properties()
        {
            var columnMetadata = new ColumnMetadata("Name", "Type", typeof(int));

            Assert.Equal("Name", columnMetadata.Name);
            Assert.Equal("Type", columnMetadata.DataTypeName);
            Assert.Same(typeof(int), columnMetadata.DataType);
        }
예제 #2
0
        public void CachedResults_properties_set_correctly()
        {
            var tableMetadata = new ColumnMetadata[0];
            var results = new List<object[]>();

            var cachedResults = new CachedResults(tableMetadata, results, 42);

            Assert.Same(tableMetadata, cachedResults.TableMetadata);
            Assert.Same(results, cachedResults.Results);
            Assert.Equal(42, cachedResults.RecordsAffected);
        }
예제 #3
0
 public CachedResults(ColumnMetadata[] tableMetadata, List<object[]> results, int recordsAffected)
 {
     _tableMetadata = tableMetadata;
     _results = results;
     _recordsAffected = recordsAffected;
 }
예제 #4
0
        private static ColumnMetadata[] GetTableMetadata(DbDataReader reader)
        {
            var columnMetadata = new ColumnMetadata[reader.FieldCount];

            for (var i = 0; i < reader.FieldCount; i++)
            {
                columnMetadata[i] =
                    new ColumnMetadata(
                        reader.GetName(i), reader.GetDataTypeName(i), reader.GetFieldType(i));
            }

            return columnMetadata;
        }
예제 #5
0
        public void GetName_throws_if_index_out_of_range()
        {
            var tableMetadata = new ColumnMetadata[]
            {
                new ColumnMetadata("Z", null, null),
            };

            using (var reader = new CachingReader(new CachedResults(tableMetadata, new List<object[]>(), 0)))
            {
                Assert.Throws<IndexOutOfRangeException>(() => reader.GetName(-1));
                Assert.Throws<IndexOutOfRangeException>(() => reader.GetName(1));
            }
        }
예제 #6
0
        public void GetName_returns_name_for_the_given_ordinal()
        {
            var tableMetadata = new ColumnMetadata[]
            {
                new ColumnMetadata("Z", null, null),
                new ColumnMetadata("X", null, null),
                new ColumnMetadata("Y", null, null),
            };

            using (var reader = new CachingReader(new CachedResults(tableMetadata, new List<object[]>(), 0)))
            {
                Assert.Same("Z", reader.GetName(0));
                Assert.Same("X", reader.GetName(1));
                Assert.Same("Y", reader.GetName(2));
            }
        }
예제 #7
0
        public void GetFieldType_returns_type_for_the_given_ordinal()
        {
            var tableMetadata = new ColumnMetadata[]
            {
                new ColumnMetadata(null, null, typeof(int)),
                new ColumnMetadata(null, null, typeof(string)),
                new ColumnMetadata(null, null, typeof(object)),
            };

            using (var reader = new CachingReader(new CachedResults(tableMetadata, new List<object[]>(), 0)))
            {
                Assert.Same(typeof(int), reader.GetFieldType(0));
                Assert.Same(typeof(string), reader.GetFieldType(1));
                Assert.Same(typeof(object), reader.GetFieldType(2));
            }
        }
예제 #8
0
        public void GetDataTypeName_returns_type_name_for_the_given_ordinal()
        {
            var tableMetadata = new ColumnMetadata[]
            {
                new ColumnMetadata(null, "abc", null),
                new ColumnMetadata(null, "123", null),
                new ColumnMetadata(null, "!@#", null),
            };

            using (var reader = new CachingReader(new CachedResults(tableMetadata, new List<object[]>(), 0)))
            {
                Assert.Equal("abc", reader.GetDataTypeName(0));
                Assert.Equal("123", reader.GetDataTypeName(1));
                Assert.Equal("!@#", reader.GetDataTypeName(2));
            }
        }