public void TestEditP() { var db = new CS4PEEntities(); var model = new BubleTea { id = db.BubleTeas.AsNoTracking().First().id, Name = "Hoa huong duong", Topping = "tran chau,banh flan", Price = 0, }; var controller = new VLTeaController(); using (var scope = new TransactionScope()) { var result = controller.Edit(model); var view = result as ViewResult; Assert.IsNotNull(view); Assert.IsInstanceOfType(view.Model, typeof(BubleTea)); Assert.AreEqual(Resource1.PRICE_LESS_0, controller.ViewData.ModelState["Price"].Errors[0].ErrorMessage); model.Price = 26000; controller = new VLTeaController(); result = controller.Edit(model); var redirect = result as RedirectToRouteResult; Assert.IsNotNull(redirect); Assert.AreEqual("Index", redirect.RouteValues["action"]); var item = db.BubleTeas.Find(model.id); Assert.IsNotNull(item); Assert.AreEqual(model.Name, item.id); Assert.AreEqual(model.Name, item.Name); Assert.AreEqual(model.Topping, item.Topping); Assert.AreEqual(model.Price, item.Price); } }
public void TestEditG() { var db = new CS4PEEntities(); var item = db.BubleTeas.First(); var controller = new VLTeaController(); var result0 = controller.Edit(0); Assert.IsInstanceOfType(result0, typeof(HttpNotFoundResult)); var result1 = controller.Edit(item.id) as ViewResult; Assert.IsNotNull(result1); var model = result1.Model as BubleTea; Assert.IsNotNull(model); Assert.AreEqual(item.id, model.id); }
public void TestEditP()//Cũ { var controller = new VLTeaController(); var db = new CS4PEEntities(); var item = db.BubleTeas.First(); var result1 = controller.Edit(item.id) as ViewResult; Assert.IsNotNull(result1); var model = result1.Model as BubleTea; Assert.IsNotNull(model); var result = controller.Edit(model); var redirect = result as RedirectToRouteResult; Assert.IsNotNull(redirect); Assert.AreEqual("Index", redirect.RouteValues["action"]); }
public void TestEditG() { var db = new CS4PEEntities(); var controller = new VLTeaController(); var result = controller.Edit(0); Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult)); var item = db.BubleTeas.First(); result = controller.Edit(item.id); var view = result as ViewResult; Assert.IsNotNull(view); var model = view.Model as BubleTea; Assert.IsNotNull(model); Assert.AreEqual(item.id, model.id); Assert.AreEqual(item.Name, model.Name); Assert.AreEqual(item.Topping, model.Topping); Assert.AreEqual(item.Price, model.Price); }
public void TestEdit() { var db = new CS4PEEntities(); var update = db.BubleTeas.First(); var controller = new VLTeaController(); var result = controller.Edit(update.id); var item = db.BubleTeas.Find(update.id); Assert.IsNotNull(update); Assert.AreEqual(update.Name, item.Name); Assert.AreEqual(update.Price, item.Price); Assert.AreEqual(update.Topping, item.Topping); }
public void testEditP() { var db = new CS4PEEntities(); var model = new BubleTea { id = db.BubleTeas.AsNoTracking().First().id, Name = "Bông cúc", Topping = "trân châu, bánh flan", Price = 0 }; var controller = new VLTeaController(); using (var scope = new TransactionScope()) { var result = controller.Edit(model); var view = result as ViewResult; Assert.IsNotNull(view); Assert.IsInstanceOfType(view.Model, typeof(BubleTea)); Assert.AreEqual(Resource1.PRICE_LESS_0, controller.ViewData.ModelState["Price"].Errors[0].ErrorMessage); model.Price = 20000; controller = new VLTeaController(); result = controller.Edit(model); var redirect = result as RedirectToRouteResult; Assert.IsNotNull(redirect); Assert.AreEqual("Index", redirect.RouteValues["action"]); var item = db.BubleTeas.Find(model.id); Assert.IsNotNull(item); Assert.AreEqual(model.Name, item.Name); Assert.AreEqual(model.Topping, item.Topping); Assert.AreEqual(model.Price, item.Price); } //var controller = new VLTeaController(); //{ // var db = new CS4PEEntities(); // var result = controller.Edit(0); // Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult)); // var item = db.BubleTeas.First(); // var kq = controller.Edit(item.id) as ViewResult; // Assert.IsNotNull(kq); // var model = kq.Model as BubleTea; // Assert.AreEqual(item.id, model.id); //} }