예제 #1
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Student testStudent = new Student("Nicole");

            testStudent.Save();

            //Act
            Student savedStudent = Student.GetAll()[0];

            int result = savedStudent.GetId();
            int testId = testStudent.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
예제 #2
0
 public override bool Equals(System.Object otherStudent)
 {
     if (!(otherStudent is Student))
     {
         return(false);
     }
     else
     {
         Student newStudent             = (Student)otherStudent;
         bool    idEquality             = this.GetId() == newStudent.GetId();
         bool    nameEquality           = this.GetName() == newStudent.GetName();
         bool    enrollmentDateEquality = this.GetEnrollmentDate() == newStudent.GetEnrollmentDate();
         bool    departmentIdEqualtiy   = this.GetDepartmentId() == newStudent.GetDepartmentId();
         return(idEquality && nameEquality && enrollmentDateEquality);
     }
 }
예제 #3
0
        public void Test_Save_AssignsIdToStudentObject()
        {
            //Arrange
            Student testStudent = new Student("Britton", "2010-09-01");

            testStudent.Save();

            //Act
            Student savedStudent = Student.GetAll()[0];

            int result = savedStudent.GetId();
            int testId = testStudent.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
예제 #4
0
        public void Test_Add_AddStudentToDepartment()
        {
            //Arrange
            Department testDepartment = new Department("English");

            testDepartment.Save();
            Student testStudent = new Student("Britton", "2010-09-01", testDepartment.GetId());

            testStudent.Save();

            //Act
            testDepartment.AddStudent(testStudent.GetId());
            int result   = testDepartment.GetId();
            int expected = testStudent.GetDepartmentId();

            //Assert
            Assert.Equal(expected, result);
        }
예제 #5
0
        public void AddStudent_AddStudentToDepartment_true()
        {
            Department testDepartment = new Department("Business");

            testDepartment.Save();
            Student testStudent = new Student("Bill Jones", "March 30th");

            testStudent.Save();
            testDepartment.AddStudent(testStudent.GetId());

            List <Student> testList  = testDepartment.GetStudents();
            List <Student> testList2 = new List <Student>()
            {
                testStudent
            };

            Assert.Equal(testList2, testList);
        }
예제 #6
0
        public void AddStudent_AddStudentToCourse_true()
        {
            Course testCourse = new Course("Real Analysis", "MTH327");

            testCourse.Save();
            Student testStudent = new Student("Poor Soul", "Tomorrow");

            testStudent.Save();
            testCourse.AddStudent(testStudent.GetId());

            List <Student> testList  = testCourse.GetStudents();
            List <Student> testList2 = new List <Student>()
            {
                testStudent
            };

            Assert.Equal(testList2, testList);
        }
예제 #7
0
        public void Test_Add_AssignsStudentToACourse()
        {
            //Arrange
            Course testCourse = new Course("English", "ENGL120");

            testCourse.Save();
            Student testStudent = new Student("Britton", "2010-09-01");

            testStudent.Save();

            //Act
            testCourse.Add(testStudent.GetId());
            List <Student> allStudents = testCourse.GetStudents();
            List <Student> result      = new List <Student> {
                testStudent
            };

            //Assert
            Assert.Equal(result, allStudents);
        }
예제 #8
0
        public void Test_GetMajorCourse_ReturnIfStudentsIsMajorRelated()
        {
            //Arrange
            Department testDepartment = new Department("English");

            testDepartment.Save();
            Course testCourse = new Course("English", "ENGL120", testDepartment.GetId());

            testCourse.Save();
            Student testStudent = new Student("Britton", "2010-09-01", testDepartment.GetId());

            testStudent.Save();

            //Act
            testCourse.Add(testStudent.GetId());
            int result   = testStudent.GetMajorCourse(testCourse.GetId());
            int expected = 1;

            //Assert
            Assert.Equal(expected, result);
        }
예제 #9
0
        public void Test_GetCompleted_ReturnIfCourseIsCompleted()
        {
            //Arrange
            Course testCourse1 = new Course("English", "ENGL120");

            testCourse1.Save();
            Course testCourse2 = new Course("Math", "MATH101");

            testCourse2.Save();
            Student testStudent = new Student("Britton", "2010-09-01");

            testStudent.Save();

            //Act
            testStudent.Add(testCourse1.GetId());
            testStudent.Add(testCourse2.GetId());
            int result   = testCourse1.GetCompleted(testStudent.GetId());
            int expected = 0;

            //Assert
            Assert.Equal(expected, result);
        }
예제 #10
0
        public void AddStudent(Student newStudent)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO students_courses (student_id, course_id) VALUES (@StudentId, @CourseId);", conn);

            SqlParameter studentIdParameter = new SqlParameter("@StudentId", newStudent.GetId());

            cmd.Parameters.Add(studentIdParameter);

            SqlParameter courseIdParameter = new SqlParameter("@CourseId", this.GetId());

            cmd.Parameters.Add(courseIdParameter);

            cmd.ExecuteNonQuery();

            if (conn != null)
            {
                conn.Close();
            }
        }
예제 #11
0
        public void AddStudent(Student newStudent)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("INSERT INTO courses_students (course_id, student_id) VALUES (@CourseId, @StudentId)", conn);
              SqlParameter courseIdParameter = new SqlParameter();
              courseIdParameter.ParameterName = "@CourseId";
              courseIdParameter.Value = this.GetId();
              cmd.Parameters.Add(courseIdParameter);

              SqlParameter studentIdParameter = new SqlParameter();
              studentIdParameter.ParameterName = "@StudentId";
              studentIdParameter.Value = newStudent.GetId();
              cmd.Parameters.Add(studentIdParameter);

              cmd.ExecuteNonQuery();

              if (conn != null)
              {
            conn.Close();
              }
        }
        public void UpdateName_UpdatesStudentName()
        {
            //Arrange
            Student testStudent = new Student("Lucille Ball", DateTime.Today);

            testStudent.Save();
            Student expectedResult = new Student("Lucy Ball", testStudent.GetEnrollmentDate(), testStudent.GetId());

            //Act
            testStudent.UpdateName("Lucy Ball");
            //Assert
            Assert.Equal(expectedResult, testStudent);
        }
예제 #13
0
        public void Test_Find_FindsStudentInDatabase()
        {
            //Arrange
              Student testStudent = new Student("Mow the lawn", new DateTime(2015, 1, 18));
              testStudent.Save();

              //Act
              Student foundStudent = Student.Find(testStudent.GetId());

              //Assert
              Assert.Equal(testStudent, foundStudent);
        }
예제 #14
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
              Student testStudent = new Student("Mow the lawn", new DateTime(2015, 1, 18));

              //Act
              testStudent.Save();
              Student savedStudent = Student.GetAll()[0];

              int result = savedStudent.GetId();
              int testId = testStudent.GetId();

              //Assert
              Assert.Equal(testId, result);
        }