Exemplo n.º 1
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);
            });
        }
Exemplo n.º 2
0
        public void Can_ExecuteScalarTask()
        {
            var executeScalarTasks = new List <Task <object> >();

            foreach (var section in Sections)
            {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryKey);
                Assert.IsNotEmpty(query);

                var countQuery = AdoTool.GetCountingSqlString(query);

                var task = NorthwindAdoRepository.ExecuteScalarAsync(countQuery);
                executeScalarTasks.Add(task);
            }

            Task.WaitAll(executeScalarTasks.ToArray());
            executeScalarTasks.All(t => t.IsCompleted).Should().Be.True();

            foreach (var task in executeScalarTasks)
            {
                var scalar = (int)task.Result;
                Assert.Greater(scalar, 0);

                if (IsDebugEnabled)
                {
                    log.Debug("Count = " + scalar);
                }
            }
        }
Exemplo n.º 3
0
 public static void MethodInTransaction()
 {
     using (var table = NorthwindAdoRepository.ExecuteDataTableBySqlString("SELECT * FROM sysobjects")) {
         Assert.IsFalse(table.HasErrors);
         Console.WriteLine("Data Table has {0} records", table.Rows.Count);
     }
 }
Exemplo n.º 4
0
        public void ExecutePagingDataTableBySelectSqlTest(int pageIndex, int pageSize, double discount)
        {
            const string selectSql  = GetOrderDetailsSql + @" WHERE Discount > @Discount";
            var          parameters = new[] { new AdoParameter("Discount", discount) };

            using (
                new OperationTimer(string.Format("ExecutePagingDataTableBySqlString(pageIndex={0}, pageSize={1})", pageIndex, pageSize))
                )
                using (var pagingTable = NorthwindAdoRepository.ExecutePagingDataTableBySqlString(selectSql, 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);
                }
        }
Exemplo n.º 5
0
        public void ExecuteScalar()
        {
            var count = NorthwindAdoRepository.ExecuteScalarBySqlString("SELECT COUNT(*) FROM dbo.Orders").AsInt();

            Assert.Greater(count, 0);

            var filterCount
                = NorthwindAdoRepository
                  .ExecuteScalarBySqlString("SELECT COUNT(*) FROM Orders where OrderDate < @OrderDate and Freight < @Freight",
                                            new AdoParameter("OrderDate", DateTime.Today),
                                            new AdoParameter("Freight", 2))
                  .AsInt();

            Assert.Greater(filterCount, 0);

            var orderId =
                NorthwindAdoRepository
                .ExecuteScalarBySqlString("SELECT TOP 1 ISNULL(OrderID, 0) FROM Orders ORDER BY ShippedDate")
                .AsInt(0);

            Assert.AreNotEqual(0, orderId);

            orderId =
                NorthwindAdoRepository
                .ExecuteScalarBySqlString("SELECT TOP 1 ISNULL(OrderID, 0) FROM Orders Where ShipVia=0 ORDER BY ShippedDate")
                .AsInt(0);

            Assert.AreEqual(0, orderId);
        }
Exemplo n.º 6
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);
                    }
            }
        }
Exemplo n.º 7
0
        public void Can_CountTask()
        {
            var countTasks = new List <Task <int> >();

            foreach (var section in Sections)
            {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryKey);
                Assert.IsNotEmpty(query);

                var task = NorthwindAdoRepository.CountAsync(query);
                countTasks.Add(task);
            }

            Task.WaitAll(countTasks.ToArray());
            countTasks.All(t => t.IsCompleted).Should().Be.True();

            foreach (var task in countTasks)
            {
                Assert.Greater(task.Result, 0);

                if (IsDebugEnabled)
                {
                    log.Debug("Count = " + task.Result);
                }
            }
        }
Exemplo n.º 8
0
        public void Load_MultipleResultSet()
        {
            var tables = new List <DataTable>();

            var sqlString = string.Concat(SQL_ORDER_SELECT, ";", SQL_ORDER_DETAIL_SELECT);

            using (var adapter = new AdoDataAdapter(NorthwindAdoRepository.GetDataAdapter()))
                using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(sqlString)) {
                    do
                    {
                        var table = new DataTable();
                        adapter.Fill(new[] { table }, reader, 0, 0);

                        tables.Add(table);
                    } while(reader.IsClosed == false && reader.NextResult());
                }

            Assert.AreEqual(2, tables.Count);
            tables.All(table => table.HasErrors == false);
            tables.RunEach(table => {
                Assert.Greater(table.Rows.Count, 0);
                if (IsDebugEnabled)
                {
                    log.Debug(table.CreateDataReader().ToString(true));
                }
            });
        }
        public void TransactionScope_ShouldNotPromoteToDTC2()
        {
            TestTool.RunTasks(10,
                              () => {
                using (var txScope = AdoTool.CreateTransactionScope()) {
                    var count = TotalCount();

                    var ds = NorthwindAdoRepository.ExecuteDataSetBySqlString(SQL_REGION_SELECT, 1, 10);
                    var dt = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_REGION_SELECT, 1, 10);

                    Assert.IsFalse(ds.Tables[0].HasErrors);
                    Assert.IsFalse(dt.HasErrors);

                    int rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT);
                    Assert.AreEqual(1, rows);
                    rows = NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_INSERT2);
                    Assert.AreEqual(1, rows);

                    NorthwindAdoRepository.ExecuteNonQueryBySqlString(SQL_REGION_DELETE);

                    ds = NorthwindAdoRepository.ExecuteDataSetBySqlString(SQL_REGION_SELECT);
                    dt = NorthwindAdoRepository.ExecuteDataTableBySqlString(SQL_REGION_SELECT);

                    txScope.Complete();
                }
            });
        }
Exemplo n.º 10
0
        public void Can_ExecutePagingDataTableTask()
        {
            var dsTasks = new List <Task>();

            // 여러 테이블의 정보를 비동기적으로 거의 동시에 로드합니다.
            //
            foreach (var section in Sections2)
            {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryKey);
                Assert.IsNotEmpty(query);

                var task = NorthwindAdoRepository
                           .ExecutePagingDataTableAsync(query, 1, 10)
                           .ContinueWith(antecedent => {
                    using (var pagingDataTable = antecedent.Result) {
                        Assert.IsFalse(pagingDataTable.Table.HasErrors);

                        //if(IsDebugEnabled)
                        //    log.Debug("PagingDataTable=", pagingDataTable);
                    }
                },
                                         TaskContinuationOptions.ExecuteSynchronously);
                dsTasks.Add(task);
            }

            Task.WaitAll(dsTasks.ToArray());
            dsTasks.All(t => t.IsCompleted).Should().Be.True();
        }
Exemplo n.º 11
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();
                }
            });
        }
Exemplo n.º 12
0
        public void PersistentObjectToDatabase()
        {
            try {
                var category = new Category {
                    CategoryName = "Test", Description = "FluentUtil"
                };

                // delete exist category
                NorthwindAdoRepository.ExecuteNonQueryBySqlString("DELETE FROM Categories where CategoryName = @CategoryName",
                                                                  new AdoParameter("CategoryName", category.CategoryName));

                // insert
                var result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, CapitalizeMapper);

                category.CategoryId = result.AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);

                // update
                result = NorthwindAdoRepository.ExecuteEntity("SaveOrUpdateCategory", category, CapitalizeMapper);
                Assert.IsTrue(result.AsInt() > 0);
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.Error(ex);
                }

                Assert.Fail(ex.Message);
            }
        }
Exemplo n.º 13
0
        public void ExecuteProcedure()
        {
            var outputs = NorthwindAdoRepository.ExecuteProcedure(GetCustomerOrderHistorySql, CustomerTestParameter);

            Assert.IsNotNull(outputs);
            Assert.Greater(outputs.Count(), 0);
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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();
            }
        }
Exemplo n.º 16
0
        public void SetParameterValuesGeneric()
        {
            var category = new Category {
                CategoryName = "Test",
                Description  = "FluentUtil"
            };

            // delete exist category
            NorthwindAdoRepository.ExecuteNonQueryBySqlString(
                @"DELETE FROM Categories where CategoryName = @CategoryName",
                new AdoParameter("CategoryName", category.CategoryName, DbType.String, 255));

            // insert
            using (var command = NorthwindAdoRepository.GetProcedureCommand("SaveOrUpdateCategory", true)) {
                AdoTool.SetParameterValues(NorthwindAdoRepository.Db,
                                           command,
                                           category,
                                           command.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')));


                category.CategoryId = NorthwindAdoRepository.ExecuteCommand(command).AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);
            }

            // update
            using (var command = NorthwindAdoRepository.GetProcedureCommand("SaveOrUpdateCategory", true)) {
                AdoTool.SetParameterValues(NorthwindAdoRepository.Db,
                                           command,
                                           category,
                                           command.Mapping(NameMappingUtil.CapitalizeMappingFunc('_', ' ')));

                category.CategoryId = NorthwindAdoRepository.ExecuteCommand(command).AsInt(-1);
                Assert.AreNotEqual(-1, category.CategoryId);
            }
        }
Exemplo n.º 17
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);
                }
            }
        }
Exemplo n.º 18
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();
            }
        }
Exemplo n.º 19
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();
            }
        }
Exemplo n.º 20
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();
            }
        }
Exemplo n.º 21
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();
            }
        }
Exemplo n.º 22
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();
            }
        }
Exemplo n.º 23
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();
            }
        }
Exemplo n.º 24
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);
                }
            }
        }
Exemplo n.º 25
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());
                }
            }
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
0
        public void Can_ExecuteDataSetTask()
        {
            var dsTasks = new List <Task>();

            // 여러 테이블의 정보를 비동기적으로 거의 동시에 로드합니다.
            //
            foreach (var section in Sections2)
            {
                var query = NorthwindAdoRepository.QueryProvider.GetQuery(section, QueryKey);
                Assert.IsNotEmpty(query);

                var task = NorthwindAdoRepository
                           .ExecuteDataSetAsync(query)
                           .ContinueWith(antecedent => {
                    using (var dataset = antecedent.Result) {
                        Assert.IsNotNull(dataset);
                        Assert.AreEqual(1, dataset.Tables.Count);
                        Assert.IsFalse(dataset.Tables[0].HasErrors);

                        //if(IsDebugEnabled)
                        //    log.Debug("Table[{0}] has [{1}] rows", dataset.Tables[0].TableName, dataset.Tables[0].Rows.Count);
                    }
                },
                                         TaskContinuationOptions.ExecuteSynchronously);
                dsTasks.Add(task);
            }

            Task.WaitAll(dsTasks.ToArray());
            dsTasks.All(t => t.IsCompleted).Should().Be.True();
        }
Exemplo n.º 28
0
 public void ExecuteDataTableByQuery(int firstResult, int maxResults)
 {
     using (var table = NorthwindAdoRepository.ExecuteDataTable(GetOrderDetailsSql, firstResult, maxResults)) {
         Assert.IsFalse(table.HasErrors);
         Assert.Greater(table.Rows.Count, 0);
         Console.WriteLine("RowCount=[{0}]", table.Rows.Count);
     }
 }
Exemplo n.º 29
0
 public void ExecuteDataSetByProcedure()
 {
     using (var ds = NorthwindAdoRepository.ExecuteDataSetByProcedure(GetCustomerOrderHistorySql, CustomerTestParameter)) {
         Assert.AreEqual(ds.Tables.Count, 1);
         Assert.Greater(ds.Tables[0].Rows.Count, 0);
         Console.WriteLine("RowCount=[{0}]", ds.Tables[0].Rows.Count);
     }
 }
Exemplo n.º 30
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);
            }
        }