Example #1
0
        public void BatchDeleteTest()
        {
            School v1 = new School();
            School v2 = new School();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v1.SchoolCode = "G15";
                v1.SchoolName = "I8KN8vsf2";
                v1.SchoolType = Ray.BiliBiliToolPro.AdminWeb.Model.SchoolTypeEnum.PUB;
                v1.Remark     = "cRS";
                v2.SchoolCode = "c4Z";
                v2.SchoolName = "Fw9Zg";
                v2.SchoolType = Ray.BiliBiliToolPro.AdminWeb.Model.SchoolTypeEnum.PRI;
                v2.Remark     = "LwU";
                context.Set <School>().Add(v1);
                context.Set <School>().Add(v2);
                context.SaveChanges();
            }

            var rv = _controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() });

            Assert.IsInstanceOfType(rv, typeof(OkObjectResult));

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data1 = context.Set <School>().Find(v1.ID);
                var data2 = context.Set <School>().Find(v2.ID);
                Assert.AreEqual(data1, null);
                Assert.AreEqual(data2, null);
            }

            rv = _controller.BatchDelete(new string[] {});
            Assert.IsInstanceOfType(rv, typeof(OkResult));
        }
        public void BatchDeleteTest()
        {
            School v1 = new School();
            School v2 = new School();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v1.SchoolCode = "ece";
                v1.SchoolName = "QZ8AgkqPf";
                v2.SchoolCode = "xLq";
                v2.SchoolName = "36xgZ9K7";
                context.Set <School>().Add(v1);
                context.Set <School>().Add(v2);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() });

            Assert.IsInstanceOfType(rv.Model, typeof(SchoolBatchVM));

            SchoolBatchVM vm = rv.Model as SchoolBatchVM;

            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 <School>().Count(), 0);
            }
        }
        public void BatchDeleteTest()
        {
            School v1 = new School();
            School v2 = new School();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v1.SchoolCode = "p6k";
                v1.SchoolName = "ko5Ms";
                v2.SchoolCode = "YuH";
                v2.SchoolName = "TuRmzGxE";
                context.Set <School>().Add(v1);
                context.Set <School>().Add(v2);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new Guid[] { v1.ID, v2.ID });

            Assert.IsInstanceOfType(rv.Model, typeof(SchoolBatchVM));

            SchoolBatchVM vm = rv.Model as SchoolBatchVM;

            vm.Ids = new Guid[] { v1.ID, v2.ID };
            _controller.DoBatchDelete(vm, null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <School>().Count(), 0);
            }
        }