public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

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

            PlayerStateVM vm = rv.Model as PlayerStateVM;
            PlayerState   v  = new PlayerState();

            v.LevelExp    = 44;
            v.MaxLifeTime = 69;
            v.CurrentLife = 52;
            v.Energy      = 93;
            v.Money       = 7;
            v.Gold        = 55;
            vm.Entity     = v;
            _controller.Create(vm);

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

                Assert.AreEqual(data.LevelExp, 44);
                Assert.AreEqual(data.MaxLifeTime, 69);
                Assert.AreEqual(data.CurrentLife, 52);
                Assert.AreEqual(data.Energy, 93);
                Assert.AreEqual(data.Money, 7);
                Assert.AreEqual(data.Gold, 55);
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
        public void DeleteTest()
        {
            PlayerState v = new PlayerState();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.LevelExp    = 44;
                v.MaxLifeTime = 69;
                v.CurrentLife = 52;
                v.Energy      = 93;
                v.Money       = 7;
                v.Gold        = 55;
                context.Set <PlayerState>().Add(v);
                context.SaveChanges();
            }

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

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

            PlayerStateVM vm = rv.Model as PlayerStateVM;

            v         = new PlayerState();
            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 <PlayerState>().Count(), 0);
            }
        }
        public void EditTest()
        {
            PlayerState v = new PlayerState();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.LevelExp    = 44;
                v.MaxLifeTime = 69;
                v.CurrentLife = 52;
                v.Energy      = 93;
                v.Money       = 7;
                v.Gold        = 55;
                context.Set <PlayerState>().Add(v);
                context.SaveChanges();
            }

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

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

            PlayerStateVM vm = rv.Model as PlayerStateVM;

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

            v.LevelExp    = 72;
            v.MaxLifeTime = 88;
            v.CurrentLife = 5;
            v.Energy      = 87;
            v.Money       = 16;
            v.Gold        = 40;
            vm.Entity     = v;
            vm.FC         = new Dictionary <string, object>();

            vm.FC.Add("Entity.LevelExp", "");
            vm.FC.Add("Entity.MaxLifeTime", "");
            vm.FC.Add("Entity.CurrentLife", "");
            vm.FC.Add("Entity.Energy", "");
            vm.FC.Add("Entity.Money", "");
            vm.FC.Add("Entity.Gold", "");
            _controller.Edit(vm);

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

                Assert.AreEqual(data.LevelExp, 72);
                Assert.AreEqual(data.MaxLifeTime, 88);
                Assert.AreEqual(data.CurrentLife, 5);
                Assert.AreEqual(data.Energy, 87);
                Assert.AreEqual(data.Money, 16);
                Assert.AreEqual(data.Gold, 40);
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }
 public ActionResult Edit(PlayerStateVM 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 ActionResult Create(PlayerStateVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoAdd();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGrid());
         }
     }
 }