public void DeleteTest() { EnterpriseContact v = new EnterpriseContact(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.EnterpriseBasicInfoId = AddEnterpriseBasicInfo(); context.Set <EnterpriseContact>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(EnterpriseContactVM)); EnterpriseContactVM vm = rv.Model as EnterpriseContactVM; v = new EnterpriseContact(); 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 <EnterpriseContact>().Count(), 0); } }
public void EditTest() { EnterpriseContact v = new EnterpriseContact(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.EnterpriseBasicInfoId = AddEnterpriseBasicInfo(); context.Set <EnterpriseContact>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(EnterpriseContactVM)); EnterpriseContactVM vm = rv.Model as EnterpriseContactVM; v = new EnterpriseContact(); v.ID = vm.Entity.ID; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.EnterpriseBasicInfoId", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <EnterpriseContact>().FirstOrDefault(); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public ActionResult Edit(EnterpriseContactVM 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 void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(EnterpriseContactVM)); EnterpriseContactVM vm = rv.Model as EnterpriseContactVM; EnterpriseContact v = new EnterpriseContact(); v.EnterpriseBasicInfoId = AddEnterpriseBasicInfo(); vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <EnterpriseContact>().FirstOrDefault(); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }