public void BatchDeleteTest() { MajorInfo v1 = new MajorInfo(); MajorInfo v2 = new MajorInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.ID = 97; v1.Code = "OvF"; v1.Name = "YTWPQ2Nb"; v2.ID = 39; v2.Code = "Am0"; v2.Name = "Ids"; context.Set <MajorInfo>().Add(v1); context.Set <MajorInfo>().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 <MajorInfo>().Find(v1.ID); var data2 = context.Set <MajorInfo>().Find(v2.ID); Assert.AreEqual(data1.IsValid, false); Assert.AreEqual(data2.IsValid, false); } rv = _controller.BatchDelete(new string[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); }
private Int32 AddMajorInfo() { MajorInfo v = new MajorInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 13; v.Code = "Bif"; v.Name = "wCku2uz"; context.Set <MajorInfo>().Add(v); context.SaveChanges(); } return(v.ID); }
private Int32 AddMajorInfo() { MajorInfo v = new MajorInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 95; v.Code = "CSiT"; v.Name = "b2SGAGBlh"; context.Set <MajorInfo>().Add(v); context.SaveChanges(); } return(v.ID); }
public void GetTest() { MajorInfo v = new MajorInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 97; v.Code = "OvF"; v.Name = "YTWPQ2Nb"; context.Set <MajorInfo>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID.ToString()); Assert.IsNotNull(rv); }
public List <MajorInfo> GetAllMajorInfo(int collegeID) //以学院编号获取专业信息的方法 { MajorInfo major; List <MajorInfo> list = new List <MajorInfo>(); string sql = "select * from MajorInfo where CollegeID=@CollegeID"; SqlParameter[] parameter = { new SqlParameter("@CollegeID", collegeID) }; //parameter[0].Value = collegeID; using (SqlDataReader sdr = DBHelpers.GetAllInfo(sql, parameter)) { while (sdr.Read()) { major = new MajorInfo(); major.MajorInfoID = int.Parse(sdr["MajorInfoID"].ToString()); major.MajorSimple = sdr["MajorSimple"].ToString(); list.Add(major); } } return(list); }
public void EditTest() { MajorInfo v = new MajorInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.ID = 97; v.Code = "OvF"; v.Name = "YTWPQ2Nb"; context.Set <MajorInfo>().Add(v); context.SaveChanges(); } MajorInfoVM vm = _controller.Wtm.CreateVM <MajorInfoVM>(); var oldID = v.ID; v = new MajorInfo(); v.ID = oldID; v.Code = "Am0"; v.Name = "Ids"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.ID", ""); vm.FC.Add("Entity.Code", ""); vm.FC.Add("Entity.Name", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <MajorInfo>().Find(v.ID); Assert.AreEqual(data.Code, "Am0"); Assert.AreEqual(data.Name, "Ids"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public void CreateTest() { MajorInfoVM vm = _controller.Wtm.CreateVM <MajorInfoVM>(); MajorInfo v = new MajorInfo(); v.ID = 97; v.Code = "OvF"; v.Name = "YTWPQ2Nb"; 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 <MajorInfo>().Find(v.ID); Assert.AreEqual(data.ID, 97); Assert.AreEqual(data.Code, "OvF"); Assert.AreEqual(data.Name, "YTWPQ2Nb"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }