private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "") { MessageBox.Show("Please fill food's name."); return; } DAL.MenuItem newMenuItem = new DAL.MenuItem { Name = txtName.Text, Price = txtPrice.Value, Image = Utilities.UtilsImage.ImageToByteArray(this.pictureBox.Image), MenuID = menu.ID }; MenuItemBLL menuItemBLL = new MenuItemBLL(); if (this.MenuItem == null) { menuItemBLL.CreateMenuItem(newMenuItem); } else { menuItemBLL.Update(this.MenuItem, newMenuItem); } this.DialogResult = DialogResult.OK; this.Close(); }
public void TestUpdateMenuItem(MenuItem menuItemOld) { List <Menu> menus = menuBLL.ListMenu(); int menuIDTest = menus[0].ID; string nameTest = "Phá lấu bò gà heo chuột dê mèo"; int priceTest = 50000; int priceAfterTest = 35000; string rootPath = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName; byte[] imageTest = File.ReadAllBytes(rootPath + "/data/images/com-chien-ca-man.jpg"); MenuItem menuItemNew = new MenuItem(); menuItemNew = menuItemOld; menuItemNew.MenuID = menuIDTest; menuItemNew.Name = nameTest; menuItemNew.Price = priceTest; menuItemNew.PriceAfter = priceAfterTest; menuItemNew.Image = imageTest; menuItemBLL.Update(menuItemOld, menuItemNew); List <MenuItem> menuItems = menuItemBLL.FindByMenuID(menus[0]); MenuItem menuItemExpected = new MenuItem(); for (int i = 0; i < menuItems.Count; i++) { if (menuItems[i].ID == menuItemNew.ID) { menuItemExpected.ID = menuItems[i].ID; menuItemExpected.MenuID = menuItems[i].MenuID; menuItemExpected.Name = menuItems[i].Name; menuItemExpected.Price = menuItems[i].Price; menuItemExpected.PriceAfter = menuItems[i].PriceAfter; menuItemExpected.Image = imageTest; } } Assert.AreEqual(menuItemNew.ID, menuItemExpected.ID); Assert.AreEqual(menuItemNew.MenuID, menuItemExpected.MenuID); Assert.AreEqual(menuItemNew.Name, menuItemExpected.Name); Assert.AreEqual(menuItemNew.Price, menuItemExpected.Price); Assert.AreEqual(menuItemNew.PriceAfter, menuItemExpected.PriceAfter); Assert.AreEqual(menuItemNew.Image, imageTest); TestDeleteMenuItem(menuItemNew); }