Пример #1
0
        public void LoadDataSetByParallelForEach()
        {
            var options = new ParallelOptions {
                MaxDegreeOfParallelism = DegreeOfParallelism
            };

            Parallel.ForEach(Sections2,
                             options,
                             (section, loopState) => {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryName);

                using (var cmd = NorthwindAdoRepository.GetCommand(query)) {
                    var ds = NorthwindAdoRepository.ExecuteDataSet(cmd);
                    Assert.AreEqual(1, ds.Tables.Count);
                    Assert.IsFalse(ds.Tables[0].HasErrors);

                    if (IsDebugEnabled)
                    {
                        log.Debug("[{0}] Table을 로드하는데 성공했습니다.", ds.Tables[0].TableName);
                    }

                    ds.Dispose();
                }
            });
        }
Пример #2
0
        public void ExecutePagingDataTableTest(int pageIndex, int pageSize, double discount)
        {
            var parameters = new[] { new AdoParameter("Discount", discount) };

            using (
                new OperationTimer(string.Format("ExecutePagingDataTable(pageIndex=[{0}], pageSize=[{1}])", pageIndex, pageSize), false)
                ) {
                using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql + " WHERE Discount > @Discount"))
                    using (var pagingTable = NorthwindAdoRepository.ExecutePagingDataTable(cmd, pageIndex, pageSize, parameters)) {
                        Assert.AreEqual(pageIndex, pagingTable.PageIndex);
                        Assert.AreEqual(pageSize, pagingTable.PageSize);

                        Assert.IsTrue(pagingTable.TotalPageCount > 0);
                        Assert.IsTrue(pagingTable.TotalItemCount > 0);

                        Assert.IsTrue(pagingTable.Table.Rows.Count > 0);
                        Assert.IsTrue(pagingTable.Table.Rows.Count <= pageSize);

                        var table = pagingTable.Table;
                        Assert.IsNotNull(table);
                        Assert.IsFalse(table.HasErrors);
                        Assert.IsTrue(table.Rows.Count > 0);
                    }
            }
        }
Пример #3
0
        public void ExecuteReaderToInstanceByConverter()
        {
            Func <IDataReader, CustomerOrderHistory> @mapFunc
                = delegate(IDataReader dr) {
                var reader = dr;
                return(new CustomerOrderHistory
                {
                    ProductName = reader.AsString("ProductName"),
                    Total = reader.AsInt32Nullable("Total")
                });
                };

            using (var cmd = NorthwindAdoRepository.GetCommand(GetCustomerOrderHistorySql)) {
                var orderHistories = NorthwindAdoRepository.ExecuteInstance(@mapFunc, cmd, CustomerTestParameter);

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

            Func <IDataReader, CustomerOrderHistory> mapFunc2 = DataReaderToCustomerOrderHistory;

            using (var cmd = NorthwindAdoRepository.GetCommand(GetCustomerOrderHistorySql)) {
                var orderHistories = NorthwindAdoRepository.ExecuteInstance(mapFunc2, cmd, CustomerTestParameter);

                if (IsDebugEnabled)
                {
                    log.Debug(orderHistories.CollectionToString());
                }
            }
        }
Пример #4
0
        public void ExecuteDataSetInTransactionScope()
        {
            Action <int, int> loadMethod = (firstResult, maxResults) => {
                using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql))
                    using (var ds = NorthwindAdoRepository.ExecuteDataSet(cmd, 5, 5)) {
                        Assert.AreEqual(ds.Tables.Count, 1);
                        Assert.Greater(ds.Tables[0].Rows.Count, 1);
                        Console.WriteLine("RowCount: " + ds.Tables[0].Rows.Count);
                    }
            };

            AdoWith.TransactionScope(delegate {
                loadMethod(5, 10);
                loadMethod(5, 5);
                loadMethod(1, 1);
            },
                                     delegate {
                loadMethod(5, 10);
                loadMethod(5, 5);
                loadMethod(1, 1);
            },
                                     delegate {
                loadMethod(5, 10);
                loadMethod(5, 5);
                loadMethod(1, 1);
            });
        }
Пример #5
0
        public void ExecuteDataSet(int firstResult, int maxResults)
        {
            DataSet ds;

            using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql))
                using (ds = NorthwindAdoRepository.ExecuteDataSet(cmd, firstResult, maxResults)) {
                    Assert.AreEqual(ds.Tables.Count, 1);
                    Assert.IsFalse(ds.Tables[0].HasErrors);
                    Assert.Greater(ds.Tables[0].Rows.Count, 1);
                    Console.WriteLine("RowCount: " + ds.Tables[0].Rows.Count);
                }

            using (ds = NorthwindAdoRepository
                        .ExecuteDataSetBySqlString(GetOrderByOrderDateAndFreightAndCustomerSql,
                                                   firstResult,
                                                   maxResults,
                                                   new AdoParameter("OrderDate", DateTime.Today),
                                                   new AdoParameter("Freight", 2),
                                                   CustomerTestParameter)) {
                Assert.AreEqual(ds.Tables.Count, 1);
                Assert.IsFalse(ds.Tables[0].HasErrors);
                // Assert.Greater(ds.Tables[0].Rows.Count, 1);
                Console.WriteLine("RowCount: " + ds.Tables[0].Rows.Count);
            }
        }
Пример #6
0
        public void ExecuteReaderWithPagingByNameMapper(int pageIndex, int pageSize)
        {
            using (var cmd = NorthwindAdoRepository.GetCommand(SQL_ORDER_DETAIL_SELECT)) {
                var orderDetails = NorthwindAdoRepository.ExecuteInstance <OrderDetail>(TrimMapper, cmd, pageIndex, pageSize);

                Console.WriteLine(orderDetails);
            }
        }
Пример #7
0
 public void ExecuteDataTable(int firstResult, int maxResults)
 {
     using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql))
         using (var table = NorthwindAdoRepository.ExecuteDataTable(cmd, firstResult, maxResults)) {
             Assert.IsFalse(table.HasErrors);
             Assert.Greater(table.Rows.Count, 0);
             Console.WriteLine("RowCount=[{0}]", table.Rows.Count);
         }
 }
Пример #8
0
        public void ExecuteReaderToInstanceByNameMapping()
        {
            using (var cmd = NorthwindAdoRepository.GetCommand(GetCustomerOrderHistorySql)) {
                var orderHistories = NorthwindAdoRepository.ExecuteInstance <CustomerOrderHistory>(NameMappings, cmd,
                                                                                                   CustomerTestParameter);

                if (IsDebugEnabled)
                {
                    log.Debug(orderHistories.CollectionToString());
                }
            }
        }
Пример #9
0
        public void ExecuteDataTableAndCopy(int firstResult, int maxResults)
        {
            // DataTable을 반환받아 다른 DataSet에 저장할 수 있는지 파악한다.

            using (var dataset = new DataSet())
                using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql))
                    using (var table = NorthwindAdoRepository.ExecuteDataTable(cmd, firstResult, maxResults)) {
                        Assert.IsFalse(table.HasErrors);
                        Assert.Greater(table.Rows.Count, 0);
                        Console.WriteLine("RowCount=[{0}]", table.Rows.Count);

                        dataset.Tables.Add(table);
                        Assert.AreEqual(1, dataset.Tables.Count);
                    }
        }
Пример #10
0
        public void ExecuteDataSetByPaging(int firstResult, int maxResults)
        {
            DataSet ds = null;

            using (var cmd = NorthwindAdoRepository.GetCommand(GetOrderDetailsSql))
                using (ds = NorthwindAdoRepository.ExecuteDataSet(cmd, firstResult, maxResults)) {
                    Assert.AreEqual(ds.Tables.Count, 1);
                    Assert.Greater(ds.Tables[0].Rows.Count, 0);
                    Console.WriteLine("RowCount=[{0}]", ds.Tables[0].Rows.Count);
                }

            using (ds = NorthwindAdoRepository.ExecuteDataSetBySqlString(GetOrderDetailsSql, firstResult, maxResults)) {
                Assert.AreEqual(ds.Tables.Count, 1);
                Assert.Greater(ds.Tables[0].Rows.Count, 0);
                Console.WriteLine("RowCount=[{0}]", ds.Tables[0].Rows.Count);
            }
        }
Пример #11
0
        public void LoadDataSetByPLinqForAll()
        {
            //var results = new ConcurrentDictionary<string, DataSet>();

            //Sections2
            // .Do(section => log.Debug("이건 LINQ 작업을 확인하기 위한 함수입니다... ㅋㅋ... 지금 수행하고자 하는 Table은 " + section + "입니다."))
            //.AsParallel()
            //.WithDegreeOfParallelism(DegreeOfParallelism)
            //.ForAll(section =>
            Parallel.ForEach(Sections2,
                             section => {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryName);
                using (var cmd = NorthwindAdoRepository.GetCommand(query))
                    using (var ds = NorthwindAdoRepository.ExecuteDataSet(cmd)) {
                        Assert.AreEqual(1, ds.Tables.Count);
                        Assert.IsFalse(ds.Tables[0].HasErrors);

                        if (IsDebugEnabled)
                        {
                            log.Debug("[{0}] Table을 로드하는데 성공했습니다.", ds.Tables[0].TableName);
                        }
                    }
            });
        }