public Student GetStudent(string id)
 {
     var errors = new List<string>();
     var repository = new StudentRepository();
     var service = new StudentService(repository);
     return service.GetStudent(id, ref errors);
 }
        //在getAllStudent()里把datatable遍历,增加新的一列
        public DataTable getAllStudent()
        {
            StudentService stuService = new StudentService();
            DataTable dt = stuService.getAllStudent();
            //添加性别列
            dt.Columns.Add("trans_gender",typeof(string));
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["gender"].ToString() == "0")
                {
                    dr["trans_gender"] = "女";
                }
                else
                {
                    dr["trans_gender"] = "男";
                }

            }
            //添加学院列
            dt.Columns.Add("trans_college", typeof(string));
            CollegeService collegeService = new CollegeService();
            foreach (DataRow dr in dt.Rows)
            {
                dr["trans_college"] = collegeService.getCollegeNameByCid(int.Parse(dr["collegeid"].ToString())).Cname;
            }
            return dt;
        }
 public List<Enrollment> GetEnrollments(string id)
 {
     var errors = new List<string>();
     var repository = new StudentRepository();
     var service = new StudentService(repository);
     return service.GetEnrollments(id, ref errors);
 }
 public List<Student> GetStudentList()
 {
     var errors = new List<string>();
     var repository = new StudentRepository();
     var service = new StudentService(repository);
     return service.GetStudentList(ref errors);
 }
 public int addstudent(string stunum, string sname, int gender, string startyear, int collegeid)
 {
     UserService userService = new UserService();
     int uid, sid = 0;
     uid = userService.insert(stunum, "123456", 1);
     if (uid != 0)
     {
         StudentService studentService = new StudentService();
         sid = studentService.insert(uid, stunum, sname, gender, startyear, collegeid);
     }
     return sid;
 }
        public void StudentErrorTest()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);

            //// Act
            studentService.GetStudent(null, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Example #7
0
        public string EnrollSchedule(string studentId, int scheduleId)
        {
            var errors = new List<string>();
            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            service.EnrollSchedule(studentId, scheduleId, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Example #8
0
        public void CalculateGpaErrorTest()
        {
            //// Arrange
            var errors = new List<string>();

            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);

            //// Act
            studentService.CalculateGpa(string.Empty, ref errors);

            //// Assert
            Assert.AreEqual(2, errors.Count);
        }
Example #9
0
        public string DeleteStudent(string id)
        {
            var errors = new List<string>();
            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            service.DeleteStudent(id, ref errors);

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

            return "error";
        }
        public void InsertStudentErrorTest2()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var student = new Student { StudentId = string.Empty };

            //// Act
            studentService.InsertStudent(student, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Example #11
0
        public void DeleteStudent()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);

            mockRepository.Setup(x => x.DeleteStudent("aaaaaa", ref errors));

            //// Act
            studentService.DeleteStudent("aaaaaa", ref errors);

            //// Assert
            mockRepository.Verify(x => x.DeleteStudent("aaaaaa", ref errors), Times.Once());
        }
Example #12
0
        public void CalculateGpaNoEnrollmentTest()
        {
            //// Arrange
            var errors = new List<string>();

            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            mockRepository.Setup(x => x.GetEnrollments("testId", ref errors)).Returns(new List<Enrollment>());

            //// Act
            var enrollments = studentService.GetEnrollments("testId", ref errors);
            var gap = studentService.CalculateGpa("testId", ref errors);

            //// Assert
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(0.0f, gap);
        }
Example #13
0
        public void CalculateGpaWithEnrollmentTest()
        {
            //// Arrange
            var errors = new List<string>();

            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var enrollments = new List<Enrollment>();
            enrollments.Add(new Enrollment { Grade = "A", GradeValue = 4.0f, ScheduleId = 1, StudentId = "testId" });
            enrollments.Add(new Enrollment { Grade = "B", GradeValue = 3.0f, ScheduleId = 2, StudentId = "testId" });
            enrollments.Add(new Enrollment { Grade = "C+", GradeValue = 2.7f, ScheduleId = 3, StudentId = "testId" });

            mockRepository.Setup(x => x.GetEnrollments("testId", ref errors)).Returns(enrollments);

            //// Act
            var gap = studentService.CalculateGpa("testId", ref errors);

            //// Assert
            Assert.AreEqual(0, errors.Count);
        }
Example #14
0
        public float GetGpa(string id)
        {
            var errors = new List<string>();

            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            return service.CalculateGpa(id, ref errors);
        }
        public void UpdateGradingOptionTest2()
        {
            // Arrange
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var enrollments = new List<Enrollment>();
            enrollments.Add(new Enrollment { Grade = "A", GradeValue = 4.0f, ScheduleId = 1, StudentId = "testId" });
            mockRepository.Setup(x => x.GetEnrollments("testId")).Returns(enrollments);

            // Act
            studentService.UpdateGradingOption("testId", 1, "Letter", ref errors);

            // Assert
            Assert.AreEqual(0, errors.Count);
        }
        public void DeleteCapeReviewErrorTest()
        {
            //// Arrange
            var errors = new List<string>();

            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);

            //// Act
            studentService.DeleteCapeReview(string.Empty, -1, ref errors);

            //// Assert
            Assert.AreEqual(2, errors.Count);
        }
Example #17
0
        public void UpdateStudentErrorTest4()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var student = new Student { StudentId = "aaaaaa", Email = "c@c" };

            //// Act
            studentService.UpdateStudent(student, ref errors);

            //// Assert
            Assert.AreEqual(1, errors.Count);
        }
Example #18
0
        public void UpdateStudent()
        {
            //// Arranage
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var student = new Student { StudentId = "aaaaaa", Email = "*****@*****.**" };

            mockRepository.Setup(x => x.UpdateStudent(student, ref errors));

            //// Act
            studentService.UpdateStudent(student, ref errors);

            //// Assert
            mockRepository.Verify(x => x.UpdateStudent(student, ref errors), Times.Once());
        }
        public void UpdateGradingOptionTest()
        {
            // Arrange
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);

            // Act
            studentService.UpdateGradingOption(string.Empty, 0, string.Empty, ref errors);

            // Assert
            Assert.AreEqual(1, errors.Count);
        }
Example #20
0
        public string InsertStudent(Student student)
        {
            var errors = new List<string>();
            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            service.InsertStudent(student, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public string UpdateGradeChangeRequest(string studentId, int scheduleId, bool requestChange)
        {
            var errors = new List<string>();
            var repository = new StudentRepository();
            var service = new StudentService(repository);
            service.UpdateGradeChangeRequest(studentId, scheduleId, requestChange, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public string UpdateStudent(Student student)
        {
            var errors = new List<string>();
            var repository = new StudentRepository();
            var service = new StudentService(repository);
            service.UpdateStudent(student, ref errors);

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

            return "error";
        }
        public string UpdateGradingOption(string studentId, int scheduleId, string gradingOpt)
        {
            var errors = new List<string>();
            var repository = new StudentRepository();
            var service = new StudentService(repository);
            service.UpdateGradingOption(studentId, scheduleId, gradingOpt, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Example #24
0
        public string RequestPreReqOverride(PreReqOverride pr)
        {
            var errors = new List<string>();
            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            service.RequestPreReqOverride(pr.ScheduleId, pr.StudentId, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
Example #25
0
        public void GetStudent()
        {
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var student = new Student { StudentId = "aaaaaa", Email = "*****@*****.**" };
            var returnStudent = new Student();

            mockRepository.Setup(x => x.GetStudentDetail("aaaaaa", ref errors)).Returns(student);
            returnStudent = studentService.GetStudent("aaaaaa", ref errors);

            Assert.AreEqual("aaaaaa", returnStudent.StudentId);
            Assert.AreEqual("*****@*****.**", returnStudent.Email);
        }
Example #26
0
        public void GetStudentList()
        {
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var studentList = new List<Student>();
            var student1 = new Student { StudentId = "aaaaaa", Email = "*****@*****.**" };
            var student2 = new Student { StudentId = "bbbbbb", Email = "*****@*****.**" };
            var returnStudent = new List<Student>();

            studentList.Add(student1);
            studentList.Add(student2);

            mockRepository.Setup(x => x.GetStudentList(ref errors)).Returns(studentList);
            returnStudent = studentService.GetStudentList(ref errors);

            Assert.AreEqual(returnStudent.Count, 2);
        }
        public void GetEnrollmentsTest2()
        {
            // Arrange
            var errors = new List<string>();
            var mockRepository = new Mock<IStudentRepository>();
            var studentService = new StudentService(mockRepository.Object);
            var studentId = string.Empty;

            // Act
            studentService.GetEnrollments(studentId, ref errors);

            // Assert
            Assert.AreEqual(1, errors.Count);
        }