Пример #1
0
 public Course GetCourse(int id)
 {
     var errors = new List<string>();
     var repository = new CourseRepository(this.entities);
     var service = new CourseService(repository);
     return service.GetCourse(id, ref errors);
 }
        public List<Course> GetCourseList()
        {
            var service = new CourseService(new CourseRepository());
            var errors = new List<string>();

            //// we could log the errors here if there are any...
            return service.GetCourseList(ref errors);
        }
 public bool deleteSelectedCourse(int sid, int cid)
 {
     CourseService courseService = new CourseService();
     if (courseService.deleteSelectedCourse(sid, cid, global_semester))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #4
0
        public void AssignPreReqErrorTest2()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            int? nullInt = null;
            //// Act
            courseService.AssignPreReq(1, (int)nullInt, ref errors);

            //// Assert course object not null
            Assert.AreEqual(1, errors.Count);
        }
Пример #5
0
        public string DeleteCourse(int id)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.DeleteCourse(id, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Пример #6
0
        public string AssignPreReq(int cId, int pr_Id)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.AssignPreReq(cId, pr_Id, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Пример #7
0
        public void AddCourseTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService iserv = new CourseService(mockRepository.Object);

            Course s = new Course { CourseId = 99, Title = "T", Description = "Test" };

            mockRepository.Setup(x => x.AddCourse(s, ref errors));
            mockRepository.Setup(x => x.IsNotDuplicateCourse(s, ref errors)).Returns(true);

            //// Act
            iserv.InsertCourse(s, ref errors);

            //// Assert
            mockRepository.Verify(x => x.AddCourse(s, ref errors), Times.Once());
        }
        public DataTable getAllCoursebySid(int sid)
        {
            CourseService couService = new CourseService();
            DataTable dt = couService.getCourseBySid(sid,1);
            dt.Columns.Add("trans_week", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["week"].ToString() == "1")
                {
                    dr["trans_week"] = "1-16";
                }
                else if (dr["week"].ToString() == "2")
                {
                    dr["trans_week"] = "1-8";
                }
                else
                {
                    dr["trans_week"] = "9-16";
                }

            }
            TeacherService teachService = new TeacherService();
            dt.Columns.Add("tname", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["tname"] = teachService.getTnameByTid(int.Parse(dr["tid"].ToString()));
            }
            return dt;
        }
 public CourseInfo getCourseInfobyCid(int cid)
 {
     CourseModel cModel = new CourseService().getCoursebyCid(cid);
     TeacherModel tModel = new TeacherService().getTeacherByTid(cModel.Tid);
     PlaceModel pModel = new PlaceService().getPlacebyPid(cModel.Pid);
     string precName = (new CourseService().getCoursebyCid(cModel.Precourse)).Cname;
     CourseInfo courseInfo = new CourseInfo(cModel, tModel, pModel, precName);
     return courseInfo;
 }
Пример #10
0
        public void AssignPreReqPassTest()
        {
            //// Arranage
            string courseName1 = "Test5";
            string courseName2 = "Test6";
            string courseName3 = "Test7";
            var errors1 = new List<string>();
            var errors2 = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course1 = new Course { Title = courseName1 };
            var course2 = new Course { Title = courseName2 };
            var course3 = new Course { Title = courseName3 };
            courseService.InsertCourse(course1, ref errors1);
            courseService.InsertCourse(course2, ref errors1);
            courseService.InsertCourse(course3, ref errors1);

            //// Act
            courseService.AssignPreReq(1, 2, ref errors2);

            //// Assert
            Assert.AreEqual(0, errors2.Count);
        }
Пример #11
0
 public List<Course> GetPreReqList(int courseId)
 {
     var errors = new List<string>();
     var repository = new CourseRepository(this.entities);
     var service = new CourseService(repository);
     return service.GetPreReqList(courseId, ref errors);
 }
Пример #12
0
        public void DeleteCourseErrorTest()
        {
            //// Arrange
            var errors = new List<string>();

            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);

            //// Act
            courseService.DeleteCourse(0, ref errors);

            //// Assert course id cannot be null
            Assert.AreEqual(1, errors.Count);
        }
Пример #13
0
        public List<Course> GetPreReqScheduleList()
        {
            var service = new CourseService(new CourseRepository(this.entities));
            var errors = new List<string>();

            //// we could log the errors here if there are any...
            return service.GetPreReqScheduleList(ref errors);
        }
        public DataTable getAllCourse()
        {
            CourseService couService = new CourseService();
            DataTable dt = couService.getAllCourse();
            dt.Columns.Add("trans_week", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["week"].ToString() == "1")
                {
                    dr["trans_week"] = "1-16";
                }
                else if (dr["week"].ToString() == "2")
                {
                    dr["trans_week"] = "1-8";
                }
                else
                {
                    dr["trans_week"] = "9-16";
                }

            }
            dt.Columns.Add("trans_section", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                switch (dr["section"].ToString())
                {
                    case "1": dr["trans_section"] = "周一(1)"; break;
                    case "2": dr["trans_section"] = "周一(2)"; break;
                    case "3": dr["trans_section"] = "周一(3)"; break;
                    case "4": dr["trans_section"] = "周一(4)"; break;
                    case "5": dr["trans_section"] = "周一(5)"; break;
                    case "6": dr["trans_section"] = "周一(6)"; break;
                    case "7": dr["trans_section"] = "周二(1)"; break;
                    case "8": dr["trans_section"] = "周二(2)"; break;
                    case "9": dr["trans_section"] = "周二(3)"; break;
                    case "10": dr["trans_section"] = "周二(4)"; break;
                    case "11": dr["trans_section"] = "周二(5)"; break;
                    case "12": dr["trans_section"] = "周二(6)"; break;
                    case "13": dr["trans_section"] = "周三(1)"; break;
                    case "14": dr["trans_section"] = "周三(2)"; break;
                    case "15": dr["trans_section"] = "周三(3)"; break;
                    case "16": dr["trans_section"] = "周三(4)"; break;
                    case "17": dr["trans_section"] = "周三(5)"; break;
                    case "18": dr["trans_section"] = "周三(6)"; break;
                    case "19": dr["trans_section"] = "周四(1)"; break;
                    case "20": dr["trans_section"] = "周四(2)"; break;
                    case "21": dr["trans_section"] = "周四(3)"; break;
                    case "22": dr["trans_section"] = "周四(4)"; break;
                    case "23": dr["trans_section"] = "周四(5)"; break;
                    case "24": dr["trans_section"] = "周四(6)"; break;
                    case "25": dr["trans_section"] = "周五(1)"; break;
                    case "26": dr["trans_section"] = "周五(2)"; break;
                    case "27": dr["trans_section"] = "周五(3)"; break;
                    case "28": dr["trans_section"] = "周五(4)"; break;
                    case "29": dr["trans_section"] = "周五(5)"; break;
                    case "30": dr["trans_section"] = "周五(6)"; break;
                    case "31": dr["trans_section"] = "周六(1)"; break;
                    case "32": dr["trans_section"] = "周六(2)"; break;
                    case "33": dr["trans_section"] = "周六(3)"; break;
                    case "34": dr["trans_section"] = "周六(4)"; break;
                    case "35": dr["trans_section"] = "周六(5)"; break;
                    case "36": dr["trans_section"] = "周六(6)"; break;
                    case "37": dr["trans_section"] = "周日(1)"; break;
                    case "38": dr["trans_section"] = "周日(2)"; break;
                    case "39": dr["trans_section"] = "周日(3)"; break;
                    case "40": dr["trans_section"] = "周日(4)"; break;
                    case "41": dr["trans_section"] = "周日(5)"; break;
                    case "42": dr["trans_section"] = "周日(6)"; break;
                }
            }
            TeacherService teachService = new TeacherService();
            dt.Columns.Add("tname", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["tname"] = teachService.getTnameByTid(int.Parse(dr["tid"].ToString()));
            }
            dt.Columns.Add("trans_pid", typeof(string));
            PlaceService placeService = new PlaceService();
            foreach (DataRow dr in dt.Rows)
            {
                dr["trans_pid"] = placeService.getPlacebyPid(int.Parse(dr["pid"].ToString())).Pname;
            }
            //已选人数
            dt.Columns.Add("takenstunum", typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                dr["takenstunum"] = couService.getTakeStuNumByCid(int.Parse(dr["cid"].ToString()), global_semester);
            }
            return dt;
        }
 public int deleteCourse(int cid)
 {
     CourseService courseService = new CourseService();
     return courseService.delete(cid);
 }
 public DataTable getSelectedCourse(int sid)
 {
     int startyear = int.Parse(new StudentBusiness().getStuBySid(sid).Startyear.ToString());
     int year = DateTime.Now.Year;
     int month = DateTime.Now.Month;
     int semester = (month >= 1 && month <= 6) ? 2 * (year - startyear) : 2 * (year - startyear) + 1;
     CourseService couService = new CourseService();
     DataTable dt = couService.getSelectedCourse(sid, semester);
     dt.Columns.Add("trans_week", typeof(string));
     foreach (DataRow dr in dt.Rows)
     {
         if (dr["week"].ToString() == "1")
         {
             dr["trans_week"] = "1-16";
         }
         else if (dr["week"].ToString() == "2")
         {
             dr["trans_week"] = "1-8";
         }
         else
         {
             dr["trans_week"] = "9-16";
         }
     }
     dt.Columns.Add("trans_section", typeof(string));
     foreach (DataRow dr in dt.Rows)
     {
         switch (dr["section"].ToString())
         {
             case "1": dr["trans_section"] = "周一(1)"; break;
             case "2": dr["trans_section"] = "周一(2)"; break;
             case "3": dr["trans_section"] = "周一(3)"; break;
             case "4": dr["trans_section"] = "周一(4)"; break;
             case "5": dr["trans_section"] = "周一(5)"; break;
             case "6": dr["trans_section"] = "周一(6)"; break;
             case "7": dr["trans_section"] = "周二(1)"; break;
             case "8": dr["trans_section"] = "周二(2)"; break;
             case "9": dr["trans_section"] = "周二(3)"; break;
             case "10": dr["trans_section"] = "周二(4)"; break;
             case "11": dr["trans_section"] = "周二(5)"; break;
             case "12": dr["trans_section"] = "周二(6)"; break;
             case "13": dr["trans_section"] = "周三(1)"; break;
             case "14": dr["trans_section"] = "周三(2)"; break;
             case "15": dr["trans_section"] = "周三(3)"; break;
             case "16": dr["trans_section"] = "周三(4)"; break;
             case "17": dr["trans_section"] = "周三(5)"; break;
             case "18": dr["trans_section"] = "周三(6)"; break;
             case "19": dr["trans_section"] = "周四(1)"; break;
             case "20": dr["trans_section"] = "周四(2)"; break;
             case "21": dr["trans_section"] = "周四(3)"; break;
             case "22": dr["trans_section"] = "周四(4)"; break;
             case "23": dr["trans_section"] = "周四(5)"; break;
             case "24": dr["trans_section"] = "周四(6)"; break;
             case "25": dr["trans_section"] = "周五(1)"; break;
             case "26": dr["trans_section"] = "周五(2)"; break;
             case "27": dr["trans_section"] = "周五(3)"; break;
             case "28": dr["trans_section"] = "周五(4)"; break;
             case "29": dr["trans_section"] = "周五(5)"; break;
             case "30": dr["trans_section"] = "周五(6)"; break;
             case "31": dr["trans_section"] = "周六(1)"; break;
             case "32": dr["trans_section"] = "周六(2)"; break;
             case "33": dr["trans_section"] = "周六(3)"; break;
             case "34": dr["trans_section"] = "周六(4)"; break;
             case "35": dr["trans_section"] = "周六(5)"; break;
             case "36": dr["trans_section"] = "周六(6)"; break;
             case "37": dr["trans_section"] = "周日(1)"; break;
             case "38": dr["trans_section"] = "周日(2)"; break;
             case "39": dr["trans_section"] = "周日(3)"; break;
             case "40": dr["trans_section"] = "周日(4)"; break;
             case "41": dr["trans_section"] = "周日(5)"; break;
             case "42": dr["trans_section"] = "周日(6)"; break;
         }
     }
     TeacherService teachService = new TeacherService();
     dt.Columns.Add("tname", typeof(string));
     foreach (DataRow dr in dt.Rows)
     {
         dr["tname"] = teachService.getTnameByTid(int.Parse(dr["tid"].ToString()));
     }
     dt.Columns.Add("trans_pid", typeof(string));
     PlaceService placeService = new PlaceService();
     foreach (DataRow dr in dt.Rows)
     {
         dr["trans_pid"] = placeService.getPlacebyPid(int.Parse(dr["pid"].ToString())).Pname;
     }
     return dt;
 }
Пример #17
0
        public void GetCourseListTest()
        {
            //// Arrange
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService courseservice = new CourseService(mockRepository.Object);

            List<Course> crl = new List<Course>();
            crl.Add(new Course { CourseId = 99, Title = "T", Description = "Test" });

            mockRepository.Setup(x => x.GetCourseList(ref errors)).Returns(crl);

            //// Act
            Course temp = courseservice.GetCourseList(ref errors)[0];

            //// Assert
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(99, temp.CourseId);
        }
Пример #18
0
        public void GetCourseErrorTest()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);

            //// Act
            courseService.GetCourse(0, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
 public int selectCourse(int sid, int cid)
 {
     int startyear = int.Parse(new StudentBusiness().getStuBySid(sid).Startyear.ToString());
     int year = DateTime.Now.Year;
     int month = DateTime.Now.Month;
     int semester = (month >= 1 && month <= 6) ? 2 * (year - startyear) : 2 * (year - startyear) + 1;
     ScModel scModel = new ScModel(sid, cid, semester);
     CourseService courseService = new CourseService();
     //判断是否有先修
     if (!courseService.ifPrecourceYes(sid,cid,semester))
     {
         return 2;
     }
     //判断是否冲突
     else if (courseService.isSectionNotAvailable(sid,cid,semester))
     {
         return 3;
     }
     else
     {
         return courseService.insertSelectedCourse(scModel);
     }
 }
Пример #20
0
        public void RemoveCourseTest()
        {
            //// Arranage
            var errors = new List<string>();

            Mock<ICourseRepository> mockRepository = new Mock<ICourseRepository>();
            CourseService iserv = new CourseService(mockRepository.Object);

            Course s = new Course { CourseId = 99, Title = "T", Description = "Test" };

            mockRepository.Setup(x => x.RemoveCourse(99, ref errors));

            //// Act
            iserv.DeleteCourse(99, ref errors);

            //// Assert
            mockRepository.Verify(x => x.RemoveCourse(99, ref errors), Times.Once());
        }
Пример #21
0
        public void UpdateCourseErrorTest1()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);

            //// Act
            courseService.UpdateCourse(null, ref errors);

            //// Assert course object not null
            Assert.AreEqual(1, errors.Count);
        }
Пример #22
0
        public void UpdateCourseErrorTest2()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<ICourseRepository>();
            var courseService = new CourseService(mockRepository.Object);
            var course = new Course { Title = string.Empty };

            //// Act
            courseService.UpdateCourse(course, ref errors);

            //// Assert first name cannot be empty
            Assert.AreEqual(1, errors.Count);
        }
Пример #23
0
 /// <summary>
 /// Get a list of available courses
 /// </summary>
 /// <param name="errors">error list</param>
 /// <returns>list of courses</returns>
 public List<Course> GetCourseList(ref List<string> errors)
 {
     var service = new CourseService(new CourseRepository());
     return service.GetCourseList(ref errors);
 }
Пример #24
0
        public string UpdateCourse(Course course)
        {
            var errors = new List<string>();
            var repository = new CourseRepository(this.entities);
            var service = new CourseService(repository);
            service.UpdateCourse(course, ref errors);

            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }