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 LoadCategoryById(int categoryId) { CategoryTDG categoryTDG = new CategoryTDG(); List <CategoryDto> categoryDtos = categoryTDG.FindCategoryById(categoryId).ToList(); DataTable categoryTable = new DataTable(); categoryTable.TableName = "Category"; Type categoryType = typeof(CategoryDto); PropertyInfo[] propertyInfos = categoryType.GetProperties(); foreach (PropertyInfo propertyInfo in propertyInfos) { DataColumn dataColumn = new DataColumn(); dataColumn.ColumnName = propertyInfo.Name; dataColumn.DataType = propertyInfo.PropertyType; categoryTable.Columns.Add(dataColumn); } foreach (CategoryDto categoryDto in categoryDtos) { DataRow newRow = categoryTable.NewRow(); foreach (PropertyInfo propertyInfo in propertyInfos) { newRow[propertyInfo.Name] = propertyInfo.GetValue(categoryDto); } categoryTable.Rows.Add(newRow); } Holder.AddTable(categoryTable); }