public void BatchDeleteTest() { TeacherProjectManager v1 = new TeacherProjectManager(); TeacherProjectManager v2 = new TeacherProjectManager(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.ID = 93; v1.ProjectId = AddProject(); v1.TeacherId = AddTeacher(); v2.ID = 10; v2.ProjectId = v1.ProjectId; v2.TeacherId = v1.TeacherId; context.Set <TeacherProjectManager>().Add(v1); context.Set <TeacherProjectManager>().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 <TeacherProjectManager>().Find(v1.ID); var data2 = context.Set <TeacherProjectManager>().Find(v2.ID); Assert.AreEqual(data1.IsValid, false); Assert.AreEqual(data2.IsValid, false); } rv = _controller.BatchDelete(new string[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); }
public void GetTest() { TeacherProjectManager v = new TeacherProjectManager(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 93; v.ProjectId = AddProject(); v.TeacherId = AddTeacher(); context.Set <TeacherProjectManager>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID.ToString()); Assert.IsNotNull(rv); }
public void CreateTest() { TeacherProjectManagerVM vm = _controller.Wtm.CreateVM <TeacherProjectManagerVM>(); TeacherProjectManager v = new TeacherProjectManager(); v.ID = 93; v.ProjectId = AddProject(); v.TeacherId = AddTeacher(); vm.Entity = v; var rv = _controller.Add(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <TeacherProjectManager>().Find(v.ID); Assert.AreEqual(data.ID, 93); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
public void EditTest() { TeacherProjectManager v = new TeacherProjectManager(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 93; v.ProjectId = AddProject(); v.TeacherId = AddTeacher(); context.Set <TeacherProjectManager>().Add(v); context.SaveChanges(); } TeacherProjectManagerVM vm = _controller.Wtm.CreateVM <TeacherProjectManagerVM>(); var oldID = v.ID; v = new TeacherProjectManager(); v.ID = oldID; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.ID", ""); vm.FC.Add("Entity.ProjectId", ""); vm.FC.Add("Entity.TeacherId", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <TeacherProjectManager>().Find(v.ID); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }