Пример #1
0
        public void ParallelMapFromDataTableByPaging(string customerId, int firstResult, int maxResults)
        {
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist2",
                                                                                  firstResult,
                                                                                  maxResults,
                                                                                  CustomerTestParameter)) {
                Assert.IsFalse(table.HasErrors);
                Assert.Greater(table.Rows.Count, 1);

                var histories =
                    table
                    .MapAsParallel <CustomerOrderHistory>(ActivatorTool.CreateInstance <CustomerOrderHistory>, CapitalizeMapper)
                    .ToList();

                if (IsDebugEnabled)
                {
                    log.Debug(histories.CollectionToString());
                }

                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();
            }
        }
Пример #2
0
        public void ParallelMapFromDataRowWithFilter()
        {
            // const string customerId = @"ANATR";

            var capitalizeRowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (모두 통과)
                var histories = table.MapAsParallel <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => true).ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(h => h.Total.HasValue && h.Total.Value > 0).Should().Be.True();
            }
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (모두 거부)
                var histories = table.MapAsParallel <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => false).ToList();

                histories.Count.Should().Be(0);
                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(h => h.Total.HasValue && h.Total.Value > 0).Should().Be.True();
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (Total 이 0보다 큰 레코드만)
                var histories =
                    table.MapAsParallel <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => row["Total"].AsValue <int>(0) > 0).
                    ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(h => h.Total.HasValue && h.Total.Value > 0).Should().Be.True();
            }
        }
Пример #3
0
        public void ParallelMapFromDataTableByMapFunc(int firstResult, int maxResults)
        {
            Func <DataRow, CustomerOrderHistory> @mapper =
                row => new CustomerOrderHistory
            {
                ProductName = row["ProductName"].AsText(),
                Total       = row["Total"].AsIntNullable()
            };

            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.MapAsParallel(@mapper).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();
            }
        }
Пример #4
0
        public void MapFromDataRowWithFilter()
        {
            var capitalizeRowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (모두 통과)
                var histories = table.MapIf <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => true).ToList();

                Assert.Greater(histories.Count, 0);
                histories.TrueForAll(h => h.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (모두 거부)
                var histories = table.MapIf <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => false).ToList();

                Assert.AreEqual(0, histories.Count);
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 필터링된 데이타 (Total 이 0보다 큰 레코드만)
                var histories =
                    table.MapIf <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => row["Total"].AsInt(0) > 0).ToList();

                Assert.Greater(histories.Count, 0);
                histories.TrueForAll(h => h.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
        }
Пример #5
0
        public void MapWhile_From_DataRow()
        {
            var capitalizeRowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 계속 조건이 항상 참
                var histories = table.MapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => true).ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 계속 조건이 항상 거짓 (모두 거부)
                var histories = table.MapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => false).ToList();

                histories.Count.Should().Be(0);
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                //  Total 이 0보다 클 때까지만 변환
                var histories =
                    table.MapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => row["Total"].AsInt(0) > 0).ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.Total.GetValueOrDefault() > 0).Should().Be.True();
            }
        }
Пример #6
0
        public void MapFromDataTableByMapFunc(int firstResult, int maxResults)
        {
            Func <DataRow, CustomerOrderHistory> @mapper =
                row => {
                var history = new CustomerOrderHistory
                {
                    ProductName = row["ProductName"].ToString(),
                    Total       = row["Total"].AsIntNullable()
                };

                return(history);
            };

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

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }
            }
        }
Пример #7
0
        public void MapFromDataTableByPaging(string customerId, int firstResult, int maxResults)
        {
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist2",
                                                                                  firstResult,
                                                                                  maxResults,
                                                                                  CustomerTestParameter)) {
                Assert.IsFalse(table.HasErrors);
                Assert.Greater(table.Rows.Count, 1);

                var histories = table.Map <CustomerOrderHistory>(CapitalizeMapper).ToList();

                if (IsDebugEnabled)
                {
                    log.Debug(histories.CollectionToString());
                }

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }
            }
        }
Пример #8
0
        public void ConvertAllFromDataTableByConverter(int firstResult, int maxResults)
        {
            Func <DataRow, CustomerOrderHistory> @mapFunc =
                row =>
                new CustomerOrderHistory {
                ProductName = row["PRODUCTNAME"].AsText(),
                Total       = row["TOTAL"].AsIntNullable()
            };

            using (var dt = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist",
                                                                               firstResult,
                                                                               maxResults,
                                                                               CustomerTestParameter)) {
                Assert.IsFalse(dt.HasErrors);
                Assert.Greater(dt.Rows.Count, 1);

                var orderHistories = AdoTool.Map(dt, @mapFunc);

                if (IsDebugEnabled)
                {
                    log.Debug(orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);
            }
        }
Пример #9
0
        public void ParallelMapWhile_FromDataRow()
        {
            var capitalizeRowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 계속 조건이 항상 참
                var histories = table.ParallelMapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => true).ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(h => h.Total.HasValue && h.Total.Value > 0).Should().Be.True();
            }
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // 계속 조건이 항상 거짓 (모두 거부)
                var histories = table.ParallelMapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => false).ToList();

                histories.Count.Should().Be(0);
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", CustomerTestParameter)) {
                // Total 이 0보다 클 때까지만 변환
                var histories =
                    table.ParallelMapWhile <CustomerOrderHistory>(capitalizeRowPersister.Persist, row => row["Total"].AsValue(0) > 0).
                    ToList();

                histories.Count.Should().Be.GreaterThan(0);
                histories.All(h => h.ProductName.IsNotWhiteSpace()).Should().Be.True();
                histories.All(h => h.Total.HasValue && h.Total.Value > 0).Should().Be.True();
            }
        }
Пример #10
0
 public void ExecuteDataTableByProcedure(int firstResult, int maxResults)
 {
     using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure(GetCustomerOrderHistorySql,
                                                                           firstResult,
                                                                           maxResults,
                                                                           CustomerTestParameter)) {
         Assert.IsFalse(table.HasErrors);
         Assert.Greater(table.Rows.Count, 0);
         Console.WriteLine("RowCount=[{0}]", table.Rows.Count);
     }
 }
Пример #11
0
        public void ExecuteDataTableToInstance(int firstResult, int maxResults)
        {
            using (var table = NorthwindAdoRepository.ExecuteDataTableByProcedure(GetCustomerOrderHistorySql,
                                                                                  firstResult,
                                                                                  maxResults,
                                                                                  CustomerTestParameter)) {
                Assert.IsFalse(table.HasErrors);
                Assert.Greater(table.Rows.Count, 1);

                var orderHistories = AdoTool.Map <CustomerOrderHistory>(table);
                Assert.Greater(orderHistories.Count, 1);
            }
        }
Пример #12
0
        public void MapFromDataTableByPersister(int firstResult, int maxResults)
        {
            IRowPersister <CustomerOrderHistory> rowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist2", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.Map(rowPersister).ToList();

                if (maxResults > 0)
                {
                    Assert.GreaterOrEqual(maxResults, histories.Count);
                }
                else
                {
                    Assert.Greater(histories.Count, 0);
                }
            }
        }
Пример #13
0
        public void ConvertAllFromDataTable(int firstResult, int maxResults)
        {
            using (var dt = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist",
                                                                               firstResult,
                                                                               maxResults,
                                                                               CustomerTestParameter)) {
                Assert.IsFalse(dt.HasErrors);
                Assert.Greater(dt.Rows.Count, 1);

                var orderHistories = AdoTool.Map <CustomerOrderHistory>(dt);

                if (IsDebugEnabled)
                {
                    log.Debug("OrderHistories:" + orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);
            }
        }
Пример #14
0
        public void ParallelMapFromDataTableByPersister(int firstResult, int maxResults)
        {
            IRowPersister <CustomerOrderHistory> rowPersister = new CapitalizeRowPersister <CustomerOrderHistory>();

            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist2", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.MapAsParallel(rowPersister).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();
            }
        }
Пример #15
0
        public void ParallelMapFromDataTableExcludeProperty(int firstResult, int maxResults)
        {
            // Total 속성의 값은 매핑하지 않는다.
            //
            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.MapAsParallel <CustomerOrderHistory>("Total").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) == 0).Should().Be.True();
            }
        }
Пример #16
0
        public void ParallelMapPersistenceFromDataTable(int firstResult, int maxResults)
        {
            // 단순히 TrimMapper 를 이용하여 Persistence를 생성합니다.
            //
            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.MapAsParallel <CustomerOrderHistory>().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();
            }
        }
Пример #17
0
        public void ConvertAllFromDataTableByNameMappingFuncs(int firstResult, int maxResults)
        {
            // CustOrderHist2 Procedure를 만들어야 한다.  (Column 명을 대문자, '_'로 바꾼다. 즉 PRODUCT_NAME, TOTAL 로 column명만 바꾼다
            using (var dt = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist2",
                                                                               firstResult,
                                                                               maxResults,
                                                                               CustomerTestParameter)) {
                Assert.IsFalse(dt.HasErrors);
                Assert.Greater(dt.Rows.Count, 1);

                var orderHistories =
                    AdoTool.Map <CustomerOrderHistory>(dt,
                                                       dt.Mapping(NameMappingUtil
                                                                  .CapitalizeMappingFunc('_', ' ')));

                if (IsDebugEnabled)
                {
                    log.Debug(orderHistories.CollectionToString());
                }

                Assert.Greater(orderHistories.Count, 0);
            }
        }
Пример #18
0
        //[TestCase(0, 50)]
        //[TestCase(5, 200)]
        public void MapPersistenceFromDataTable(int firstResult, int maxResults)
        {
            // 단순히 TrimMapper 를 이용하여 Persistence를 생성합니다.
            //
            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.Map <CustomerOrderHistory>().ToList();

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

                histories.TrueForAll(h => h.Total.GetValueOrDefault(0) > 0);
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_CUSTOMER_SELECT, firstResult, maxResults)) {
                var customers = table.Map <Customer>().ToList();

                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();
            }
        }
Пример #19
0
        public void MapFromDataTableExcludeProperty(int firstResult, int maxResults)
        {
            // Total 속성의 값은 매핑하지 않는다.
            //
            using (
                var table = NorthwindAdoRepository.ExecuteDataTableByProcedure("CustOrderHist", firstResult, maxResults,
                                                                               CustomerTestParameter)) {
                var histories = table.Map <CustomerOrderHistory>(new[] { "Total" }).ToList();

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

                histories.All(x => x.Total == 0).Should().Be.True();
            }

            using (var table = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_CUSTOMER_SELECT, firstResult, maxResults)) {
                var customers = table.Map <Customer>(new string[0]);

                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();
            }
        }