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 DataReaderGetByName() { using (var dr = NorthwindAdoRepository.ExecuteReaderBySqlString("SELECT * FROM Employees")) { while (dr.Read()) { Assert.IsNotEmpty(DataReaderTool.AsString(dr, "Title")); Assert.IsNotNull(DataReaderTool.AsDateTimeNullable(dr, "BirthDate")); } } }
public void MapFromDataReader_Employee_Paginated(int firstResult, int maxResults) { using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_EMPLOYEE_SELECT)) { var employees = reader.Map <Employee>(firstResult, maxResults, new string[0]).ToList(); Assert.Greater(employees.Count, 0); employees.All(emp => emp.EmployeeID > 0).Should().Be.True(); employees.All(emp => emp.BirthDate.HasValue).Should().Be.True(); employees.All(emp => emp.Photo != null && emp.Photo.Length > 0).Should().Be.True(); } }
public void ExecuteReaderByQuery() { using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(GetOrderDetailsSql)) { Assert.IsTrue(reader.Read()); if (IsDebugEnabled) { log.Debug(reader.ToString(true)); } } }
public void MapFromDataReader_OrderDetails() { using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_ORDER_DETAIL_SELECT)) { var orderDetails = reader.Map <OrderDetail>().ToList(); Assert.Greater(orderDetails.Count, 0); orderDetails.All(od => od.OrderID > 0).Should().Be.True(); orderDetails.All(od => od.ProductID > 0).Should().Be.True(); orderDetails.All(od => od.Quantity > 0).Should().Be.True(); orderDetails.All(od => od.Discount >= 0.0f).Should().Be.True(); } }
public void MapFromDataReader_Employee() { using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_EMPLOYEE_SELECT)) { var employees = reader.Map <Employee>(new[] { "Photo" }).ToList(); employees.Count.Should().Be.GreaterThan(0); employees.All(emp => emp.EmployeeID > 0).Should().Be.True(); employees.All(emp => emp.BirthDate.HasValue).Should().Be.True(); // Photo 속성은 매핑에서 제외 했습니다. employees.All(emp => emp.Photo == null).Should().Be.True(); } }
public void MapFromDataReader_Employee_With_DynamicProxy() { var capitalizeNameMapper = new CapitalizeNameMapper(); using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_EMPLOYEE_SELECT)) { var employees = reader.Map <Employee>(DynamicProxyTool.CreateEditablePropertyChanged <Employee>, capitalizeNameMapper); Assert.Greater(employees.Count, 0); employees.All(emp => emp.EmployeeID > 0).Should().Be.True(); employees.All(emp => emp.BirthDate.HasValue).Should().Be.True(); // 모든 엔티티가 Proxy 된 것입니다!!! employees.All(emp => emp.IsDynamicProxy()).Should().Be.True(); } }
public void DataReaderGetByIndex() { using (var dr = NorthwindAdoRepository.ExecuteReaderBySqlString("SELECT * FROM [Order Details]")) { while (dr.Read()) { var orderId = DataReaderTool.AsInt32(dr, 0, () => 10000); Assert.AreNotEqual(10000, orderId); var productId = DataReaderTool.AsInt32(dr, 1); Assert.AreNotEqual(0, productId); var unitPrice = DataReaderTool.AsDecimal(dr, 2); Assert.AreNotEqual(0M, unitPrice); } } }
public void CanGetNullableFromProducts() { using (var dr = NorthwindAdoRepository.ExecuteReaderBySqlString("SELECT * FROM Products")) { while (dr.Read()) { var unitPrice = DataReaderTool.AsDecimalNullable(dr, "UnitPrice"); Assert.IsTrue(unitPrice.HasValue); //Console.WriteLine("UnitPrice = " + unitPrice); Assert.Greater(unitPrice.Value, 0m); var reorderLevel = DataReaderTool.AsInt16Nullable(dr, "ReorderLevel"); Assert.IsTrue(reorderLevel.HasValue); Assert.GreaterOrEqual(reorderLevel.Value, 0); } } }
public void MapFromDataReader_OrderDetails_DynamicProxy() { var capitalizeNameMapper = new CapitalizeNameMapper(); using (var reader = NorthwindAdoRepository.ExecuteReaderBySqlString(SQL_ORDER_DETAIL_SELECT)) { var orderDetails = reader.Map <OrderDetail>(DynamicProxyTool.CreateEditablePropertyChanged <OrderDetail>, CapitalizeMapper); Assert.Greater(orderDetails.Count, 0); orderDetails.All(od => od.OrderID > 0).Should().Be.True(); orderDetails.All(od => od.ProductID > 0).Should().Be.True(); orderDetails.All(od => od.Quantity > 0).Should().Be.True(); orderDetails.All(od => od.Discount >= 0.0f).Should().Be.True(); // 모든 엔티티가 Proxy 된 것입니다!!! orderDetails.All(od => od.IsDynamicProxy()).Should().Be.True(); } }
public void CanGetNullableFromOrderDetails() { using (var dr = NorthwindAdoRepository.ExecuteReaderBySqlString("SELECT * FROM [Order Details]")) { while (dr.Read()) { var orderId = DataReaderTool.AsInt32Nullable(dr, 0); Assert.IsTrue(orderId.HasValue); Assert.AreEqual(orderId, dr.GetInt32(0)); var productId = DataReaderTool.AsInt32Nullable(dr, 1); Assert.IsTrue(productId.HasValue); Assert.AreEqual(productId, dr.GetInt32(1)); var unitPrice = DataReaderTool.AsDecimalNullable(dr, 2); Assert.IsTrue(unitPrice.HasValue); Assert.AreEqual(unitPrice, dr.GetDecimal(2)); var discount = DataReaderTool.AsFloatNullable(dr, "Discount"); Assert.IsNotNull(discount); } } }
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(); } }