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 LoadProductById(int productId) { ProductTDG productTDG = new ProductTDG(); List <ProductDto> productDtos = productTDG.FindProductById(productId).ToList(); DataTable producTable = new DataTable(); producTable.TableName = "Product"; Type producType = typeof(ProductDto); PropertyInfo[] propertyInfos = producType.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = propertyInfo.Name; dataColumn.DataType = propertyInfo.PropertyType; producTable.Columns.Add(dataColumn); } foreach (ProductDto productDto in productDtos) { DataRow newRow = producTable.NewRow(); foreach (PropertyInfo propertyInfo in propertyInfos) { newRow[propertyInfo.Name] = propertyInfo.GetValue(productDto); } producTable.Rows.Add(newRow); } Holder.AddTable(producTable); }
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); }