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);
        }
        public void InsertStudent(Student student, ref List<string> errors)
        {
            if (student == null)
            {
                errors.Add("Student cannot be null");
                throw new ArgumentException();
            }

            if (student.StudentId.Length < 5)
            {
                errors.Add("Invalid student ID");
                throw new ArgumentException();
            }

            this.repository.InsertStudent(student, ref errors);
        }
        public void InsertStudent(Student student, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            try
            {
                var adapter = new SqlDataAdapter(InsertStudentInfoProcedure, conn)
                                  {
                                      SelectCommand =
                                          {
                                              CommandType = CommandType.StoredProcedure
                                          }
                                  };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 20));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@ssn", SqlDbType.VarChar, 9));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@first_name", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@last_name", SqlDbType.VarChar, 50));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@email", SqlDbType.VarChar, 64));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar, 64));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@shoe_size", SqlDbType.Float));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@weight", SqlDbType.Int));

                adapter.SelectCommand.Parameters["@student_id"].Value = student.StudentId;
                adapter.SelectCommand.Parameters["@ssn"].Value = student.SSN;
                adapter.SelectCommand.Parameters["@first_name"].Value = student.FirstName;
                adapter.SelectCommand.Parameters["@last_name"].Value = student.LastName;
                adapter.SelectCommand.Parameters["@email"].Value = student.Email;
                adapter.SelectCommand.Parameters["@password"].Value = student.Password;
                adapter.SelectCommand.Parameters["@shoe_size"].Value = student.ShoeSize;
                adapter.SelectCommand.Parameters["@weight"].Value = student.Weight;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }
        }
        public void UpdateStudent(Student student, ref List<string> errors)
        {
            if (student == null)
            {
                errors.Add("Student cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(student.StudentId))
            {
                errors.Add("Invalid student id");
                throw new ArgumentException();
            }

            if (student.StudentId.Length < 5)
            {
                errors.Add("Invalid student id");
                throw new ArgumentException();
            }

            this.repository.UpdateStudent(student, ref errors);
        }
Exemple #5
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());
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
0
        public void UpdateStudent(Student s, ref List<string> errors)
        {
            var db_student = new student();

            try
            {
                db_student = this.context.students.Find(s.StudentId);
                db_student.first_name = s.FirstName;
                db_student.last_name = s.LastName;
                db_student.password = s.Password;
                db_student.email = s.Email;
                this.context.SaveChanges();
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.UpdateStudent: " + e);
            }
        }
 public string UpdateStudent(Student student)
 {
     this.service.UpdateStudent(student, ref this.errors);
     return this.errors.Count == 0 ? "ok" : "Error occurred";
 }
 /// <summary>
 /// insert a new student
 /// </summary>
 /// <param name="student">student object</param>
 /// <param name="errors">error list</param>
 public void InsertStudent(Student student, ref List<string> errors)
 {
     this.service.InsertStudent(student, ref errors);
 }
        public string InsertStudent(Student student)
        {
            var errors = new List<string>();
            var repository = new StudentRepository();
            var service = new StudentService(repository);
            service.InsertStudent(student, ref errors);
            if (errors.Count == 0)
            {
                return "ok";
            }

            return "error";
        }
        public List<Student> GetStudentsByScheduleId(int scheduleId, ref List<string> errors)
        {
            IEnumerable<enrollment> enrollmentList;
            List<Student> studentList = new List<Student>();
            try
            {
                enrollmentList = this.context.enrollments.Include("student").Where(x => x.schedule_id == scheduleId);
                foreach (enrollment db_Student in enrollmentList)
                {
                    var poco = new Student();
                    poco.StudentId = db_Student.student.student_id;
                    poco.FirstName = db_Student.student.first_name;
                    poco.LastName = db_Student.student.last_name;
                    poco.Email = db_Student.student.email;
                    poco.Password = db_Student.student.password;
                    poco.Grade = db_Student.grade;

                    studentList.Add(poco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }

            return studentList;
        }
        public List<Student> GetStudentList(ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            var studentList = new List<Student>();

            try
            {
                var adapter = new SqlDataAdapter(GetStudentListProcedure, conn)
                                  {
                                      SelectCommand =
                                          {
                                              CommandType = CommandType.StoredProcedure
                                          }
                                  };

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return null;
                }

                for (var i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    var student = new Student
                                      {
                                          StudentId = dataSet.Tables[0].Rows[i]["student_id"].ToString(),
                                          FirstName = dataSet.Tables[0].Rows[i]["first_name"].ToString(),
                                          LastName = dataSet.Tables[0].Rows[i]["last_name"].ToString(),
                                          SSN = dataSet.Tables[0].Rows[i]["ssn"].ToString(),
                                          Email = dataSet.Tables[0].Rows[i]["email"].ToString(),
                                          Password = dataSet.Tables[0].Rows[i]["password"].ToString(),
                                          ShoeSize =
                                              (float)
                                              Convert.ToDouble(dataSet.Tables[0].Rows[i]["shoe_size"].ToString()),
                                          Weight = Convert.ToInt32(dataSet.Tables[0].Rows[i]["weight"].ToString())
                                      };
                    studentList.Add(student);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return studentList;
        }
        public void StudentIntegrationTest()
        {
            var student = new Student
            {
                FirstName = "first", 
                LastName = " last", 
                StudentId = Guid.NewGuid().ToString().Substring(0, 20), 
                SSN = "888991234", 
                Email = "*****@*****.**", 
                Password = "******", 
                ShoeSize = 0, 
                Weight = 0
            };

            var errors = new List<string>();
            this.studentRepository.InsertStudent(student, ref errors);

            Assert.AreEqual(0, errors.Count);

            var verifyStudent = this.studentRepository.GetStudentDetail(student.StudentId, ref errors);

            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(student.FirstName, verifyStudent.FirstName);
            Assert.AreEqual(student.LastName, verifyStudent.LastName);
            Assert.AreEqual(student.StudentId, verifyStudent.StudentId);
            Assert.AreEqual(student.SSN, verifyStudent.SSN);
            Assert.AreEqual(student.Email, verifyStudent.Email);
            Assert.AreEqual(student.Password, verifyStudent.Password);
            Assert.AreEqual(student.ShoeSize, verifyStudent.ShoeSize);
            Assert.AreEqual(student.Weight, verifyStudent.Weight);

            var student2 = new Student
            {
                FirstName = "first2", 
                LastName = " last2", 
                StudentId = student.StudentId, 
                SSN = "777664321", 
                Email = "*****@*****.**", 
                Password = "******", 
                ShoeSize = 2, 
                Weight = 2
            };

            this.studentRepository.UpdateStudent(student2, ref errors);

            verifyStudent = this.studentRepository.GetStudentDetail(student2.StudentId, ref errors);
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(student2.FirstName, verifyStudent.FirstName);
            Assert.AreEqual(student2.LastName, verifyStudent.LastName);
            Assert.AreEqual(student2.StudentId, verifyStudent.StudentId);
            Assert.AreEqual(student2.SSN, verifyStudent.SSN);
            Assert.AreEqual(student2.Email, verifyStudent.Email);
            Assert.AreEqual(student2.Password, verifyStudent.Password);
            Assert.AreEqual(student2.ShoeSize, verifyStudent.ShoeSize);
            Assert.AreEqual(student2.Weight, verifyStudent.Weight);

            var scheduleList = this.scheduleRepositoryRepository.GetScheduleList(string.Empty, string.Empty, ref errors);
            Assert.AreEqual(0, errors.Count);

            // enroll all available scheduled courses for this student
            foreach (var schedule in scheduleList)
            {
                this.studentRepository.EnrollSchedule(student.StudentId, schedule.ScheduleId, ref errors);
                Assert.AreEqual(0, errors.Count);
            }

            // drop all available scheduled courses for this student
            foreach (var schedule in scheduleList)
            {
                this.studentRepository.DropEnrolledSchedule(student.StudentId, schedule.ScheduleId, ref errors);
                Assert.AreEqual(0, errors.Count);
            }

            this.studentRepository.DeleteStudent(student.StudentId, ref errors);

            var verifyEmptyStudent = this.studentRepository.GetStudentDetail(student.StudentId, ref errors);
            Assert.AreEqual(0, errors.Count);
            Assert.AreEqual(null, verifyEmptyStudent);
        }
Exemple #15
0
        public void UpdateStudent(Student student, ref List<string> errors)
        {
            if (student == null)
            {
                errors.Add("Student cannot be null");
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(student.StudentId))
            {
                errors.Add("Invalid student id");
                throw new ArgumentException();
            }

            if (student.StudentId.Length < 5)
            {
                errors.Add("Invalid student id");
                throw new ArgumentException();
            }

            if (!Regex.IsMatch(student.Email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"))
            {
                errors.Add("Invalid student email");
                throw new ArgumentException();
            }

            this.repository.UpdateStudent(student, ref errors);
        }
Exemple #16
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);
        }
Exemple #17
0
        public string UpdateStudent(Student student)
        {
            var errors = new List<string>();
            var repository = new StudentRepository(this.entities);
            var service = new StudentService(repository);
            service.UpdateStudent(student, ref errors);

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

            return "error";
        }
Exemple #18
0
        public Student FindStudentById(int student_id, ref List<string> errors)
        {
            student db_student;
            Student pocoStudent = new Student();

            try
            {
                db_student = this.context.students.Find(student_id);
                pocoStudent.StudentId = db_student.student_id;
                pocoStudent.FirstName = db_student.first_name;
                pocoStudent.LastName = db_student.last_name;
                pocoStudent.Password = db_student.password;
                pocoStudent.Email = db_student.email;
                pocoStudent.Enrolled = new List<Schedule>();
                foreach (enrollment enrolledCourse in db_student.enrollments)
                {
                    var pocoSchedule = new Schedule();
                    var db_Schedule = new course_schedule();

                    db_Schedule.schedule_id = enrolledCourse.schedule_id;
                    db_Schedule = this.context.course_schedule.Find(db_Schedule);

                    pocoSchedule.ScheduleId = db_Schedule.schedule_id;
                    pocoSchedule.Quarter = db_Schedule.quarter;
                    pocoSchedule.Year = db_Schedule.year.ToString();
                    pocoSchedule.Session = db_Schedule.session;

                    pocoStudent.Enrolled.Add(pocoSchedule);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.FindStudentById: " + e);
            }

            return pocoStudent;
        }
 /// <summary>
 /// update student info
 /// </summary>
 /// <param name="student">student info</param>
 /// <param name="errors">error list</param>
 public void UpdateStudent(Student student, ref List<string> errors)
 {
     this.service.UpdateStudent(student, ref errors);
 }
Exemple #20
0
        public Student GetStudentDetail(string id, ref List<string> errors)
        {
            var conn = new SqlConnection(ConnectionString);
            Student student = null;

            try
            {
                var adapter = new SqlDataAdapter(GetStudentInfoProcedure, conn)
                {
                    SelectCommand = { CommandType = CommandType.StoredProcedure }
                };
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 20));

                adapter.SelectCommand.Parameters["@student_id"].Value = id;

                var dataSet = new DataSet();
                adapter.Fill(dataSet);

                if (dataSet.Tables[0].Rows.Count == 0)
                {
                    return null;
                }

                student = new Student
                              {
                                  StudentId = dataSet.Tables[0].Rows[0]["student_id"].ToString(),
                                  FirstName = dataSet.Tables[0].Rows[0]["first_name"].ToString(),
                                  LastName = dataSet.Tables[0].Rows[0]["last_name"].ToString(),
                                  Email = dataSet.Tables[0].Rows[0]["email"].ToString(),
                                  Password = dataSet.Tables[0].Rows[0]["password"].ToString()
                              };

                if (dataSet.Tables[1] != null)
                {
                    student.Enrolled = new List<Schedule>();
                    for (var i = 0; i < dataSet.Tables[1].Rows.Count; i++)
                    {
                        var schedule = new Schedule();
                        var course = new Course
                                         {
                                             CourseId = int.Parse(dataSet.Tables[1].Rows[i]["course_id"].ToString()),
                                             Title = dataSet.Tables[1].Rows[i]["course_title"].ToString(),
                                             Description =
                                                 dataSet.Tables[1].Rows[i]["course_description"].ToString()
                                         };
                        schedule.Course = course;

                        schedule.Quarter = dataSet.Tables[1].Rows[i]["quarter"].ToString();
                        schedule.Year = dataSet.Tables[1].Rows[i]["year"].ToString();
                        schedule.Session = dataSet.Tables[1].Rows[i]["session"].ToString();
                        schedule.ScheduleId = Convert.ToInt32(dataSet.Tables[1].Rows[i]["schedule_id"].ToString());
                        student.Enrolled.Add(schedule);
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.GetStudentDetail: " + e);
            }
            finally
            {
                conn.Dispose();
            }

            return student;
        }
        public void InsertStudent(Student student, ref List<string> errors)
        {
            if (student == null)
            {
                errors.Add("Student cannot be null");
                throw new ArgumentException();
            }

            if (student.StudentId.Length < 5)
            {
                errors.Add("Invalid student ID");
                throw new ArgumentException();
            }

            Regex r = new Regex("^[a-zA-Z0-9]*$");
            if (!(r.IsMatch(student.StudentId))) {
                errors.Add("Invalid student ID");
                throw new ArgumentException();
            }

            this.repository.InsertStudent(student, ref errors);
        }
Exemple #22
0
        public List<Student> GetStudentList(ref List<string> errors)
        {
            List<POCO.Student> pocoStudentList = new List<POCO.Student>();
            List<student> db_studentList;
            try
            {
                db_studentList = this.context.students.ToList();

                foreach (student i_student in db_studentList)
                {
                    var tempPoco = new POCO.Student();
                    tempPoco.StudentId = i_student.student_id;
                    tempPoco.FirstName = i_student.first_name;
                    tempPoco.LastName = i_student.last_name;
                    tempPoco.StudentId = i_student.student_id;
                    tempPoco.Email = i_student.email;
                    pocoStudentList.Add(tempPoco);
                }
            }
            catch (Exception e)
            {
                errors.Add("Error occured in StudentRepository.GetStudentList: " + e);
            }

            return pocoStudentList;
        }