public void TestEditPost() { var db = new CsK23T2aEntities1(); var model = new tableBILL { idHD = db.tableBILLs.AsNoTracking().First().idHD, tenKH = "Nguyen", tenSP = "Vay Sieu Nhan" }; var controller = new Admin_tableBILLsController(); using (var scope = new TransactionScope()) { var result = controller.Create(model); var view = result as ViewResult; controller = new Admin_tableBILLsController(); result = controller.Edit(model); var redirect = result as RedirectToRouteResult; Assert.IsNotNull(redirect); Assert.AreEqual("Index", redirect.RouteValues["action"]); var item = db.tableBILLs.Find(model.idHD); Assert.IsNotNull(item); Assert.AreEqual(model.tenKH, item.tenKH); Assert.AreEqual(model.tenSP, item.tenSP); } }
public ActionResult Edit(tableBILL model) { if (ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; db.SaveChanges(); TempData["StatusMessage"] = "Edit successfully"; return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(tableBILL model) { if (ModelState.IsValid) { //Add Day model.ngaydathang = DateTime.Today; db.tableBILLs.Add(model); db.SaveChanges(); TempData["StatusMessage"] = "Create successfully"; return(RedirectToAction("Index")); } return(View(model)); }
public void TestCreatePost() { var db = new CsK23T2aEntities1(); var model = new tableBILL { tenKH = "Nguyen", sodienthoaiKH = "0979320779", ngaydathang = null, ngaynhanhang = null, diachinhanhang = "HCM", tenSP = "sda", dongiaSP = 100, soluongSP = 5, ghichuSP = "khong", thanhtienBILL = 500, ghichuBILL = "khong" }; var controller = new Admin_tableBILLsController(); using (var scope = new TransactionScope()) { var result = controller.Create(model); var redirect = result as RedirectToRouteResult; Assert.IsNotNull(redirect); Assert.AreEqual("Index", redirect.RouteValues["action"]); var item = db.tableBILLs.Find(model.idHD); Assert.IsNotNull(item); Assert.AreEqual(model.tenKH, item.tenKH); Assert.AreEqual(model.sodienthoaiKH, item.sodienthoaiKH); Assert.AreEqual(model.ngaydathang, item.ngaydathang); Assert.AreEqual(model.ngaynhanhang, item.ngaynhanhang); Assert.AreEqual(model.diachinhanhang, item.diachinhanhang); Assert.AreEqual(model.tenSP, item.tenSP); Assert.AreEqual(model.dongiaSP, item.dongiaSP); Assert.AreEqual(model.soluongSP, item.soluongSP); Assert.AreEqual(model.ghichuSP, item.ghichuSP); Assert.AreEqual(model.thanhtienBILL, item.thanhtienBILL); Assert.AreEqual(model.ghichuBILL, item.ghichuBILL); } }