Ejemplo n.º 1
0
        public void MapFromDataReaderByMapFunc(int firstResult, int maxResults)
        {
            Func <IDataReader, CustomerOrderHistory> @mapper =
                dr => {
                var reader = dr;
                return(new CustomerOrderHistory
                {
                    ProductName = reader.AsString("ProductName"),
                    Total = reader.AsInt32Nullable("Total")
                });
            };

            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var histories = reader.Map(@mapper, firstResult, maxResults).ToList();

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }

                histories.All(history => history.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(history => history.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
        }
Ejemplo n.º 2
0
        public void MapFromDataReaderByPersister(int firstResult, int maxResults)
        {
            IReaderPersister <CustomerOrderHistory> readerPersister = new CapitalizeReaderPersister <CustomerOrderHistory>();

            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist2", CustomerTestParameter)) {
                var orderHistories = reader.Map(readerPersister, firstResult, maxResults);
                Assert.IsTrue(orderHistories.Count > 0);
            }
        }
Ejemplo n.º 3
0
        public void DatabaseToPersistentObject()
        {
            // CustOrderHist2 는 컬럼명만 PROJECT_NAME, TOTAL 로 변경한 것이다.
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist2", CustomerTestParameter)) {
                var orderHistories = reader.Map <CustomerOrderHistory>(reader.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')));

                Assert.IsTrue(orderHistories.Count > 0);
                Console.WriteLine("Order History: " + orderHistories.CollectionToString());
            }
        }
Ejemplo n.º 4
0
        public void ExecuteReaderByProcedure()
        {
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure(GetCustomerOrderHistorySql, CustomerTestParameter)) {
                Assert.IsTrue(reader.Read());

                if (IsDebugEnabled)
                {
                    log.Debug(reader.ToString(true));
                }
            }
        }
Ejemplo n.º 5
0
        public void MapFromDataReaderByPropertyNameMapping(int firstResult, int maxResults)
        {
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var orderHistories = reader.Map <CustomerOrderHistory>(NameMappings, firstResult, maxResults);

                if (log.IsInfoEnabled)
                {
                    Console.WriteLine(orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);
            }
        }
Ejemplo n.º 6
0
        public void Load_Nullable()
        {
            var spName = NorthwindAdoRepository.QueryProvider.GetQuery("TenMostExpensiveProduct");

            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure(spName)) {
                Assert.IsNotNull(reader);

                while (reader.Read())
                {
                    var unitPrice = reader.AsDecimalNullable("UnitPrice");
                    Assert.IsTrue(unitPrice.HasValue);
                    Assert.Greater(unitPrice.GetValueOrDefault(0m), 0m);
                }
            }
        }
Ejemplo n.º 7
0
        public void MapFromDataReaderByNameMappingFuncs(int firstResult, int maxResults)
        {
            // CustOrderHist2 Procedure를 만들어야 한다.  (Column 명을 대문자, '_'로 바꾼다. 즉 PRODUCT_NAME, TOTAL 로 column명만 바꾼다
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist2", CustomerTestParameter)) {
                var orderHistories =
                    reader.Map <CustomerOrderHistory>(reader.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')),
                                                      firstResult,
                                                      maxResults);
                if (log.IsInfoEnabled)
                {
                    Console.WriteLine(orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);
            }
        }
Ejemplo n.º 8
0
        public void MapFromDataReaderExcludeProperty(int firstResult, int maxResults)
        {
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var orderHistories = reader.Map <CustomerOrderHistory>(firstResult, maxResults, x => x.Total).OrderBy(x => x.Total).ToList();

                if (log.IsInfoEnabled)
                {
                    Console.WriteLine(orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);

                // Total 속성 값은 설정되지 않기 때문에, 모두 초기 값이어야 한다.
                orderHistories.All(x => x.Total == 0).Should().Be.True();
            }
        }
Ejemplo n.º 9
0
        public void Load_Nullable()
        {
            var spName = NorthwindAdoRepository.QueryProvider.GetQuery("TenMostExpensiveProduct");

            using (var adapter = new AdoDataAdapter(NorthwindAdoRepository.GetDataAdapter()))
                using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure(spName)) {
                    Assert.IsNotNull(reader);

                    var dataTable = new DataTable();

                    adapter.Fill(new[] { dataTable }, reader, 2, 2);

                    Assert.IsFalse(dataTable.HasErrors);
                    Assert.AreEqual(2, dataTable.Rows.Count);
                }
        }
Ejemplo n.º 10
0
        public void MapFromDataReaderByPersister(int firstResult, int maxResults)
        {
            IReaderPersister <CustomerOrderHistory> readerPersister = new CapitalizeReaderPersister <CustomerOrderHistory>();

            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist2", CustomerTestParameter)) {
                var histories = reader.Map(readerPersister, firstResult, maxResults).ToList();

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }

                histories.All(history => history.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(history => history.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
        }
Ejemplo n.º 11
0
        public void MapFromDataReaderByConverter(int firstResult, int maxResults)
        {
            Func <IDataReader, CustomerOrderHistory> @mapFunc
                = delegate(IDataReader dr) {
                var reader = dr;
                return
                    (new CustomerOrderHistory {
                    ProductName = reader.AsString("PRODUCTNAME"),
                    Total = reader.AsInt32Nullable("TOTAL")
                });
                };

            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var orderHistories = reader.Map(@mapFunc, firstResult, maxResults);

                if (log.IsInfoEnabled)
                {
                    Console.WriteLine(orderHistories.CollectionToString());
                }
            }
        }
Ejemplo n.º 12
0
        public void MapFromDataReaderExcludeProperty(int firstResult, int maxResults)
        {
            // Total 속성의 값은 매핑하지 않는다.
            //
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var histories = reader.Map <CustomerOrderHistory>(firstResult, maxResults, h => h.Total);

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }

                Console.WriteLine(histories.CollectionToString());

                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
            }
        }
Ejemplo n.º 13
0
        public void Load_TenMostExpensiveProduct()
        {
            var spName = NorthwindAdoRepository.QueryProvider.GetQuery("TenMostExpensiveProduct");

            Assert.IsNotEmpty(spName);

            if (IsDebugEnabled)
            {
                log.Debug("Execute Procedure... spName=[{0}]", spName);
            }

            using (var adapter = new AdoDataAdapter(NorthwindAdoRepository.GetDataAdapter()))
                using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure(spName)) {
                    Assert.IsNotNull(reader);
                    Assert.Greater(reader.FieldCount, 0);

                    var dataTable = new DataTable();
                    adapter.Fill(new[] { dataTable }, reader, 2, 2);

                    Assert.IsFalse(dataTable.HasErrors);
                    Assert.AreEqual(2, dataTable.Rows.Count);
                }
        }
Ejemplo n.º 14
0
        public void MapFromDataReaderByFactoryFunc(int firstResult, int maxResults)
        {
            // 단순히 TrimMapper 를 이용하여 Persistence를 생성합니다.
            //
            using (var reader = NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist", CustomerTestParameter)) {
                var histories = reader.Map <CustomerOrderHistory>(() => new CustomerOrderHistory("임시", -1), firstResult, maxResults);

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }

                histories.All(history => history.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(history => history.Total.GetValueOrDefault() > 0).Should().Be.True();
            }


            using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_CUSTOMER_SELECT)) {
                var customers = reader.Map <Customer>(() => new Customer(), firstResult, maxResults);

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, customers.Count);
                }
                else
                {
                    Assert.Greater(customers.Count, 0);
                }

                customers.All(c => c.CustomerID.IsNotWhiteSpace()).Should().Be.True();
                customers.All(c => c.Address.IsNotWhiteSpace()).Should().Be.True();
            }
        }
Ejemplo n.º 15
0
 private static IDataReader GetCustomerOrderHistoryDataReader(string customerId)
 {
     return(NorthwindAdoRepository.ExecuteReaderByProcedure("CustOrderHist2", new AdoParameter("CustomerId", customerId)));
 }
Ejemplo n.º 16
0
        private IDataReader CustomerOrderDetailDataReader()
        {
            var spName = NorthwindAdoRepository.QueryProvider.GetQuery("CustomerOrdersDetail");

            return(NorthwindAdoRepository.ExecuteReaderByProcedure(spName, OrderTestParameter));
        }