public void DeleteTest()
        {
            GroupDicEntity v = new GroupDicEntity();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.Title = "IMx";
                v.Sort  = 16;
                context.Set <GroupDicEntity>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID);

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

            GroupDicEntityVM vm = rv.Model as GroupDicEntityVM;

            v         = new GroupDicEntity();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID, null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <GroupDicEntity>().Count(), 0);
            }
        }
Exemple #2
0
 public ActionResult Edit(GroupDicEntityVM 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 EditTest()
        {
            GroupDicEntity v = new GroupDicEntity();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.Title = "IMx";
                v.Sort  = 16;
                context.Set <GroupDicEntity>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID);

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

            GroupDicEntityVM vm = rv.Model as GroupDicEntityVM;

            v    = new GroupDicEntity();
            v.ID = vm.Entity.ID;

            v.Title   = "B3HO";
            v.Sort    = 53;
            vm.Entity = v;
            vm.FC     = new Dictionary <string, object>();

            vm.FC.Add("Entity.Title", "");
            vm.FC.Add("Entity.Sort", "");
            _controller.Edit(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <GroupDicEntity>().FirstOrDefault();

                Assert.AreEqual(data.Title, "B3HO");
                Assert.AreEqual(data.Sort, 53);
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

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

            GroupDicEntityVM vm = rv.Model as GroupDicEntityVM;
            GroupDicEntity   v  = new GroupDicEntity();

            v.Title   = "IMx";
            v.Sort    = 16;
            vm.Entity = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <GroupDicEntity>().FirstOrDefault();

                Assert.AreEqual(data.Title, "IMx");
                Assert.AreEqual(data.Sort, 16);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }