public void BatchDeleteTest() { BackgroundJob v1 = new BackgroundJob(); BackgroundJob v2 = new BackgroundJob(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.DeviceId = "Erut2"; v1.Command = "YVMBjEd"; v1.Period = 63; v1.ExecutedCount = 98; v2.DeviceId = "MtCMB5LAV"; v2.Command = "mof"; v2.Period = 15; v2.ExecutedCount = 52; context.Set <BackgroundJob>().Add(v1); context.Set <BackgroundJob>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof(BackgroundJobBatchVM)); BackgroundJobBatchVM vm = rv.Model as BackgroundJobBatchVM; vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() }; _controller.DoBatchDelete(vm, null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <BackgroundJob>().Count(), 0); } }
public ActionResult DoBatchDelete(BackgroundJobBatchVM vm, IFormCollection nouse) { if (!ModelState.IsValid || !vm.DoBatchDelete()) { return(PartialView("BatchDelete", vm)); } else { return(FFResult().CloseDialog().RefreshGrid().Alert("操作成功,共有" + vm.Ids.Length + "条数据被删除")); } }