public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(BackgroundJobVM)); BackgroundJobVM vm = rv.Model as BackgroundJobVM; BackgroundJob v = new BackgroundJob(); v.DeviceId = "Erut2"; v.Command = "YVMBjEd"; v.Period = 63; v.ExecutedCount = 98; vm.Entity = v; _controller.Create(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <BackgroundJob>().FirstOrDefault(); Assert.AreEqual(data.DeviceId, "Erut2"); Assert.AreEqual(data.Command, "YVMBjEd"); Assert.AreEqual(data.Period, 63); Assert.AreEqual(data.ExecutedCount, 98); } }
public async Task <ActionResult> Create(BackgroundJobVM vm) { if (!ModelState.IsValid) { return(PartialView(vm)); } else { var backgroupJobGrain = _client.GetGrain <IBackgroundJobGrain>(Guid.NewGuid(), vm.Entity.DeviceId); if (vm.Entity.JobType == BackgroundJobType.Timer) { await backgroupJobGrain.CreateTimer(vm.Entity.Command, new JobPeriod(vm.Entity.StartTime, vm.Entity.Period, vm.Entity.EndTime.Value)); } else { await backgroupJobGrain.CreateReminder(vm.Entity.Command, new JobPeriod(vm.Entity.StartTime, vm.Entity.Period, vm.Entity.EndTime.Value)); } //vm.DoAdd(); if (!ModelState.IsValid) { vm.DoReInit(); return(PartialView(vm)); } else { return(FFResult().CloseDialog().RefreshGrid()); } } }
public void DeleteTest() { BackgroundJob v = new BackgroundJob(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.DeviceId = "Erut2"; v.Command = "YVMBjEd"; v.Period = 63; v.ExecutedCount = 98; context.Set <BackgroundJob>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(BackgroundJobVM)); BackgroundJobVM vm = rv.Model as BackgroundJobVM; v = new BackgroundJob(); 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 <BackgroundJob>().Count(), 0); } }
public void EditTest() { BackgroundJob v = new BackgroundJob(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.DeviceId = "Erut2"; v.Command = "YVMBjEd"; v.Period = 63; v.ExecutedCount = 98; context.Set <BackgroundJob>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(BackgroundJobVM)); BackgroundJobVM vm = rv.Model as BackgroundJobVM; v = new BackgroundJob(); v.ID = vm.Entity.ID; v.DeviceId = "MtCMB5LAV"; v.Command = "mof"; v.Period = 15; v.ExecutedCount = 52; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.DeviceId", ""); vm.FC.Add("Entity.Command", ""); vm.FC.Add("Entity.Period", ""); vm.FC.Add("Entity.ExecutedCount", ""); _controller.Edit(vm); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <BackgroundJob>().FirstOrDefault(); Assert.AreEqual(data.DeviceId, "MtCMB5LAV"); Assert.AreEqual(data.Command, "mof"); Assert.AreEqual(data.Period, 15); Assert.AreEqual(data.ExecutedCount, 52); } }
public ActionResult Edit(BackgroundJobVM 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)); } } }