Beispiel #1
0
        public static List <Test1> Test1GetListOrbitfogCoreDatabaseMapper(int count)
        {
            using (var connection = new SqlConnection())
            {
                connection.ConnectionString = ConnectionString;
                connection.Open();

                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = GetCommandText(count);

                    return(DbDataReaderMapper <Test1> .ToList(command.ExecuteReader()));
                }
            }
        }
Beispiel #2
0
        public void ToList_ClassA_1()
        {
            int i = 10;
            var fakeDatabaseDataList = new List <FakeDbDataReaderRow>()
            {
                new FakeDbDataReaderRow()
                .AddColumn(typeof(string), "StringValue", "ble" + i)
                .AddColumn(typeof(bool), "BoolValue", false)
                .AddColumn(typeof(int), "IntValue", i)
                .AddColumn(typeof(Guid), "GuidValue", Guid.NewGuid())
                .AddColumn(typeof(DateTime), "DateTimeValue", DateTime.Today)
                .AddColumn(typeof(byte[]), "ByteArrayValue", new byte[] { 5, 8 })
                .AddColumn(typeof(int), "EnumValue", i++),
                new FakeDbDataReaderRow()
                .AddColumn(typeof(string), "StringValue", "ble" + i)
                .AddColumn(typeof(bool), "BoolValue", null)
                .AddColumn(typeof(int), "IntValue", i)
                .AddColumn(typeof(Guid), "GuidValue", null)
                .AddColumn(typeof(DateTime), "DateTimeValue", null)
                .AddColumn(typeof(byte[]), "ByteArrayValue", null)
                .AddColumn(typeof(int), "EnumValue", i++),
                new FakeDbDataReaderRow()
                .AddColumn(typeof(string), "StringValue", "ble" + i)
                .AddColumn(typeof(bool), "BoolValue", true)
                .AddColumn(typeof(int), "IntValue", i)
                .AddColumn(typeof(Guid), "GuidValue", null)
                .AddColumn(typeof(DateTime), "DateTimeValue", null)
                .AddColumn(typeof(byte[]), "ByteArrayValue", null)
                .AddColumn(typeof(int), "EnumValue", i++)
            };

            var list = DbDataReaderMapper <ClassA> .ToList(new FakeDbDataReader(fakeDatabaseDataList));

            Assert.Equal(3, list.Count);

            Assert.Equal("ble12", list[2].StringValue);

            Assert.False(list[0].BoolValue);
            Assert.False(list[1].BoolValue);
            Assert.True(list[2].BoolValue);

            Assert.NotEqual(Guid.Empty, list[0].GuidValue);
            Assert.Equal(Guid.Empty, list[1].GuidValue);

            Assert.Equal(DateTime.Today, list[0].DateTimeValue);
            Assert.Equal(default, list[1].DateTimeValue);