public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(StoreHouseVM)); StoreHouseVM vm = rv.Model as StoreHouseVM; StoreHouse v = new StoreHouse(); v.WarehouseCode = "Jm78"; v.WarehouseAddress = "M9B"; v.ContractName = "TxlQdb31"; v.ContractPhone = "Vww3t"; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <StoreHouse>().FirstOrDefault(); Assert.AreEqual(data.WarehouseCode, "Jm78"); Assert.AreEqual(data.WarehouseAddress, "M9B"); Assert.AreEqual(data.ContractName, "TxlQdb31"); Assert.AreEqual(data.ContractPhone, "Vww3t"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
public void DeleteTest() { StoreHouse v = new StoreHouse(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.WarehouseCode = "Jm78"; v.WarehouseAddress = "M9B"; v.ContractName = "TxlQdb31"; v.ContractPhone = "Vww3t"; context.Set <StoreHouse>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(StoreHouseVM)); StoreHouseVM vm = rv.Model as StoreHouseVM; v = new StoreHouse(); 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 <StoreHouse>().Count(), 1); } }
public void EditTest() { StoreHouse v = new StoreHouse(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.WarehouseCode = "Jm78"; v.WarehouseAddress = "M9B"; v.ContractName = "TxlQdb31"; v.ContractPhone = "Vww3t"; context.Set <StoreHouse>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(StoreHouseVM)); StoreHouseVM vm = rv.Model as StoreHouseVM; v = new StoreHouse(); v.ID = vm.Entity.ID; v.WarehouseCode = "NgIudeNx"; v.WarehouseAddress = "INq1"; v.ContractName = "zE7Ho"; v.ContractPhone = "6dCP"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.WarehouseCode", ""); vm.FC.Add("Entity.WarehouseAddress", ""); vm.FC.Add("Entity.ContractName", ""); vm.FC.Add("Entity.ContractPhone", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <StoreHouse>().FirstOrDefault(); Assert.AreEqual(data.WarehouseCode, "NgIudeNx"); Assert.AreEqual(data.WarehouseAddress, "INq1"); Assert.AreEqual(data.ContractName, "zE7Ho"); Assert.AreEqual(data.ContractPhone, "6dCP"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public ActionResult Edit(StoreHouseVM 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(StoreHouseVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }