public void BatchDeleteTest() { Student v1 = new Student(); Student v2 = new Student(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.Name = "zKk"; v2.Name = "qXR"; context.Set <Student>().Add(v1); context.Set <Student>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new Guid[] { v1.ID, v2.ID }); Assert.IsInstanceOfType(rv.Model, typeof(StudentBatchVM)); StudentBatchVM vm = rv.Model as StudentBatchVM; vm.Ids = new Guid[] { v1.ID, v2.ID }; _controller.DoBatchDelete(vm, null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <Student>().Count(), 0); } }
public void BatchEditTest() { Student v1 = new Student(); Student v2 = new Student(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.Name = "Ig1N37FOm"; v1.Age = 20; v2.Name = "fQFq"; v2.Age = 92; context.Set <Student>().Add(v1); context.Set <Student>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof(StudentBatchVM)); StudentBatchVM vm = rv.Model as StudentBatchVM; vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() }; vm.LinkedVM.Name = "QSln"; vm.LinkedVM.Age = 13; vm.FC = new Dictionary <string, object>(); vm.FC.Add("LinkedVM.Name", ""); vm.FC.Add("LinkedVM.Age", ""); _controller.DoBatchEdit(vm, null); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data1 = context.Set <Student>().Find(v1.ID); var data2 = context.Set <Student>().Find(v2.ID); Assert.AreEqual(data1.Name, "QSln"); Assert.AreEqual(data2.Name, "QSln"); Assert.AreEqual(data1.Age, 13); Assert.AreEqual(data2.Age, 13); Assert.AreEqual(data1.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data1.UpdateTime.Value).Seconds < 10); Assert.AreEqual(data2.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data2.UpdateTime.Value).Seconds < 10); } }