public void TestTDGFindCategoryById() { int orderId = 10693; OrderDetailTDG orderDetailTDG = new OrderDetailTDG(); IList <OrderDetailDto> orderDetailDtos = orderDetailTDG.FindOrderDetailById(orderId).ToList(); ProductTDG productTDG = new ProductTDG(); CategoryTDG categoryTDG = new CategoryTDG(); int productId0 = orderDetailDtos[0].ProductID; ProductDto productDto0 = productTDG.FindProductById(productId0).SingleOrDefault(); CategoryDto categoryDto0 = categoryTDG.FindCategoryById(productDto0.CategoryID).SingleOrDefault(); Assert.AreEqual("Meat/Poultry", categoryDto0.CategoryName); Assert.AreEqual(6, productDto0.CategoryID); int productId1 = orderDetailDtos[1].ProductID; ProductDto productDto1 = productTDG.FindProductById(productId1).SingleOrDefault(); CategoryDto categoryDto1 = categoryTDG.FindCategoryById(productDto1.CategoryID).SingleOrDefault(); Assert.AreEqual("Meat/Poultry", categoryDto1.CategoryName); int productId2 = orderDetailDtos[2].ProductID; ProductDto productDto2 = productTDG.FindProductById(productId2).SingleOrDefault(); CategoryDto categoryDto2 = categoryTDG.FindCategoryById(productDto2.CategoryID).SingleOrDefault(); Assert.AreEqual("Dairy Products", categoryDto2.CategoryName); int productId3 = orderDetailDtos[3].ProductID; ProductDto productDto3 = productTDG.FindProductById(productId3).SingleOrDefault(); CategoryDto categoryDto3 = categoryTDG.FindCategoryById(productDto3.CategoryID).SingleOrDefault(); Assert.AreEqual("Seafood", categoryDto3.CategoryName); }
public void TestTDGFindOrderDetailById() { int orderId = 10693; OrderDetailTDG orderDetailTDG = new OrderDetailTDG(); IList <OrderDetailDto> orderDetailDtos = orderDetailTDG.FindOrderDetailById(orderId).ToList(); Assert.AreEqual(4, orderDetailDtos.Count); Assert.AreEqual(orderId, orderDetailDtos[0].OrderID); Assert.AreEqual(9, orderDetailDtos[0].ProductID); Assert.AreEqual(6, orderDetailDtos[0].Quantity); Assert.AreEqual(0f, orderDetailDtos[0].Discount); Assert.AreEqual(orderId, orderDetailDtos[1].OrderID); Assert.AreEqual(54, orderDetailDtos[1].ProductID); Assert.AreEqual(60, orderDetailDtos[1].Quantity); Assert.AreEqual(0.15f, orderDetailDtos[1].Discount); Assert.AreEqual(orderId, orderDetailDtos[2].OrderID); Assert.AreEqual(69, orderDetailDtos[2].ProductID); Assert.AreEqual(30, orderDetailDtos[2].Quantity); Assert.AreEqual(0.15f, orderDetailDtos[2].Discount); Assert.AreEqual(orderId, orderDetailDtos[3].OrderID); Assert.AreEqual(73, orderDetailDtos[3].ProductID); Assert.AreEqual(15, orderDetailDtos[3].Quantity); Assert.AreEqual(0.15f, orderDetailDtos[3].Discount); }
public void LoadOrderDetailById(int orderId) { OrderDetailTDG orderDetailTDG = new OrderDetailTDG(); IList <OrderDetailDto> orderDetailDtos = orderDetailTDG.FindOrderDetailById(orderId).ToList(); DataTable orderDetailTable = new DataTable(); orderDetailTable.TableName = "OrderDetail"; Type orderDetailType = typeof(OrderDetailDto); PropertyInfo[] propertyInfos = orderDetailType.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = propertyInfo.Name; dataColumn.DataType = propertyInfo.PropertyType; orderDetailTable.Columns.Add(dataColumn); } foreach (OrderDetailDto orderDetailDto in orderDetailDtos) { DataRow newRow = orderDetailTable.NewRow(); foreach (PropertyInfo propertyInfo in propertyInfos) { newRow[propertyInfo.Name] = propertyInfo.GetValue(orderDetailDto); } orderDetailTable.Rows.Add(newRow); } Holder.AddTable(orderDetailTable); }
public void TestTDGFindProductById() { int orderId = 10693; OrderDetailTDG orderDetailTDG = new OrderDetailTDG(); IList <OrderDetailDto> orderDetailDtos = orderDetailTDG.FindOrderDetailById(orderId).ToList(); ProductTDG productTDG = new ProductTDG(); int productId0 = orderDetailDtos[0].ProductID; ProductDto productDto0 = productTDG.FindProductById(productId0).SingleOrDefault(); Assert.AreEqual(productId0, productDto0.ProductID); Assert.AreEqual("Mishi Kobe Niku", productDto0.ProductName); Assert.AreEqual(6, productDto0.CategoryID); int productId1 = orderDetailDtos[1].ProductID; ProductDto productDto1 = productTDG.FindProductById(productId1).SingleOrDefault(); Assert.AreEqual(productId1, productDto1.ProductID); Assert.AreEqual("Tourtière", productDto1.ProductName); Assert.AreEqual(6, productDto1.CategoryID); int productId2 = orderDetailDtos[2].ProductID; ProductDto productDto2 = productTDG.FindProductById(productId2).SingleOrDefault(); Assert.AreEqual(productId2, productDto2.ProductID); Assert.AreEqual("Gudbrandsdalsost", productDto2.ProductName); Assert.AreEqual(4, productDto2.CategoryID); int productId3 = orderDetailDtos[3].ProductID; ProductDto productDto3 = productTDG.FindProductById(productId3).SingleOrDefault(); Assert.AreEqual(productId3, productDto3.ProductID); Assert.AreEqual("Röd Kaviar", productDto3.ProductName); Assert.AreEqual(8, productDto3.CategoryID); }