public override bool Equals(Object otherStudent) { if (!(otherStudent is Student)) { return(false); } else { Student newStudent = (Student)otherStudent; bool idEquality = (this._id == newStudent.GetId()); bool nameEquality = (this._name == newStudent.GetName()); bool enrollmentEquality = (this._enrollment == newStudent.GetEnrollment()); return(idEquality && nameEquality && enrollmentEquality); } }
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 doeEquality = (this.GetDoe() == newStudent.GetDoe()); return(idEquality && nameEquality && doeEquality); } }
//add rows to students_courses join table public void AddStudent(Student newStudent) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO students_courses (students_id, courses_id) VALUES (@StudentId, @CourseId);", conn); cmd.Parameters.Add(new SqlParameter("@StudentId", newStudent.GetId())); cmd.Parameters.Add(new SqlParameter("@CourseId", this.GetId())); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
public void AddStudent_AddsStudentToCourse_true() { Course newCourse = new Course("Intro", "CS101"); Student student1 = new Student("James", DateTime.Today); Student student2 = new Student("Sarah", DateTime.Today); Student student3 = new Student("Grace", DateTime.Today); newCourse.Save(); student1.Save(); student2.Save(); student3.Save(); List <Student> expectedList = new List <Student> { student1, student3 }; newCourse.AddStudent(student1.GetId()); newCourse.AddStudent(student3.GetId()); List <Student> result = newCourse.GetAllStudents(); Assert.Equal(expectedList, result); }
public void Test_Save_AssignsIdToObject() { //Arrange Student testStudent = new Student("Chad", enrollmentDate); //Act testStudent.Save(); Student savedStudent = Student.GetAll()[0]; int result = savedStudent.GetId(); int testId = testStudent.GetId(); //Assert Assert.Equal(testId, result); }
public void Test_Find_FindsStudentInDatabase() { //Arrange Student testStudent = new Student("Chad", enrollmentDate); testStudent.Save(); //Act Student foundStudent = Student.Find(testStudent.GetId()); //Assert Assert.Equal(testStudent, foundStudent); }