public void DeleteTest() { VOS_Shop v = new VOS_Shop(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.CustomerId = AddCustomer(); v.ShopName = "PvZ"; context.Set <VOS_Shop>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(VOS_ShopVM)); VOS_ShopVM vm = rv.Model as VOS_ShopVM; v = new VOS_Shop(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID.ToString(), null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <VOS_Shop>().Count(), 1); } }
public ActionResult Edit(VOS_ShopVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoEdit(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID)); } } }
public ActionResult Create(VOS_ShopVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }
public void EditTest() { VOS_Shop v = new VOS_Shop(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.CustomerId = AddCustomer(); v.ShopName = "PvZ"; context.Set <VOS_Shop>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(VOS_ShopVM)); VOS_ShopVM vm = rv.Model as VOS_ShopVM; v = new VOS_Shop(); v.ID = vm.Entity.ID; v.ShopName = "b1Qcz"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.CustomerId", ""); vm.FC.Add("Entity.ShopName", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <VOS_Shop>().FirstOrDefault(); Assert.AreEqual(data.ShopName, "b1Qcz"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(VOS_ShopVM)); VOS_ShopVM vm = rv.Model as VOS_ShopVM; VOS_Shop v = new VOS_Shop(); v.CustomerId = AddCustomer(); v.ShopName = "PvZ"; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <VOS_Shop>().FirstOrDefault(); Assert.AreEqual(data.ShopName, "PvZ"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }