public void CanGetStudentEnrollment() { // dummy username and course id string username = "******"; string courseId = Guid.NewGuid().ToString(); // Add the dummy student enrollment via the internal repository interfaces var dummyEnrollment = new StudentRecord(){ Username = username}; dummyEnrollment.StudentCourseEnrollments = new List<Enrollment>(); dummyEnrollment.StudentCourseEnrollments.Add( new Enrollment() { CourseId = courseId, DateStarted = DateTime.Now, DateCompleted = SqlServerHelper.GetSqlServerMinimumDateTimeValue() } ); var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>(); dummyEnrollment = enrollmentsRepo.AddOrUpdate(dummyEnrollment); // Get the student record via the enrollments model interface that the web // application will use to retrieve student enrollment records by username IStudentEnrollmentsModel enrollmentsModel = new StudentEnrollmentsModel(); var fromDb = enrollmentsModel.GetStudentRecord(username); Assert.NotNull(fromDb); Assert.AreEqual(fromDb.Username, dummyEnrollment.Username); Assert.NotNull(fromDb.StudentCourseEnrollments); Assert.AreEqual(fromDb.StudentCourseEnrollments.Count, dummyEnrollment.StudentCourseEnrollments.Count); Assert.AreEqual(fromDb.StudentCourseEnrollments[0].Id, dummyEnrollment.StudentCourseEnrollments[0].Id); Assert.AreEqual(fromDb.StudentCourseEnrollments[0].CourseId, dummyEnrollment.StudentCourseEnrollments[0].CourseId); Assert.AreEqual(fromDb.StudentCourseEnrollments[0].DateCompleted, dummyEnrollment.StudentCourseEnrollments[0].DateCompleted); // Clean up Db enrollmentsRepo.Remove(username); }
public void CanRemoveStudentEnrollment() { // dummy username and course id string username = "******"; string courseId = Guid.NewGuid().ToString(); // Add the dummy student enrollment via the internal repository interfaces var dummyEnrollment = new StudentRecord() { Username = username }; dummyEnrollment.StudentCourseEnrollments = new List<Enrollment>(); dummyEnrollment.StudentCourseEnrollments.Add( new Enrollment() { CourseId = courseId, DateStarted = DateTime.Now, DateCompleted = SqlServerHelper.GetSqlServerMinimumDateTimeValue() } ); var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>(); dummyEnrollment = enrollmentsRepo.AddOrUpdate(dummyEnrollment); // Remove the enrollment via the enrollmnent model interface that the webapp // will use to remove a student's enrollment from their record IStudentEnrollmentsModel enrollmentsModel = new StudentEnrollmentsModel(); enrollmentsModel.RemoveEnrollment(username, courseId); // retrieve the enrollment record from the Db and ensure the student has // no enrollments in his/her student record var fromDb = enrollmentsRepo.Get(username); Assert.NotNull(fromDb); Assert.AreEqual(fromDb.Username, username); Assert.AreEqual(fromDb.StudentCourseEnrollments.Count, 0); // clean up Db enrollmentsRepo.Remove(fromDb.Username); }
public void CanUpdateExistingStudentEnrollmentsCollection() { // dummy username and dummy courses string username = "******"; var dummyCourse1 = DummyDataGenerator.CreateDummyCourse(); var dummyCourse2 = DummyDataGenerator.CreateDummyCourse(); // Add the dummy courses to the database via the internal course repository interface IRepository<Course, string> coursesRepo = new BizCollegeRepository<Course, string>(); dummyCourse1.Id = coursesRepo.AddOrUpdate(dummyCourse1).Id; dummyCourse2.Id = coursesRepo.AddOrUpdate(dummyCourse2).Id; // Add the dummy student enrollment via the internal enrollments repository interfaces var dummyEnrollment = new StudentRecord() { Username = username }; dummyEnrollment.StudentCourseEnrollments = new List<Enrollment>(); dummyEnrollment.StudentCourseEnrollments.Add( new Enrollment() { CourseId = dummyCourse1.Id, DateStarted = DateTime.Now, DateCompleted = SqlServerHelper.GetSqlServerMinimumDateTimeValue() } ); var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>(); dummyEnrollment = enrollmentsRepo.AddOrUpdate(dummyEnrollment); // To update the student enrollment, we'll add another enrollment to their // current enrollment record (so we should have two enrollments after the update) IStudentEnrollmentsModel model = new StudentEnrollmentsModel(); var updatedRecord = model.AddEnrollment(username, dummyCourse2.Id); Assert.NotNull(updatedRecord); Assert.IsNotNullOrEmpty(updatedRecord.Username); Assert.AreEqual(updatedRecord.Username, username); Assert.NotNull(updatedRecord); Assert.IsNotNullOrEmpty(updatedRecord.Username); Assert.NotNull(updatedRecord.StudentCourseEnrollments); Assert.AreEqual(updatedRecord.StudentCourseEnrollments.Count, 2); var updatedEnrollments = new List<Enrollment>(updatedRecord.StudentCourseEnrollments); Assert.AreEqual(updatedEnrollments[0].CourseId, dummyCourse1.Id); Assert.AreEqual(updatedEnrollments[1].CourseId, dummyCourse2.Id); // Clean up Db enrollmentsRepo.Remove(username); coursesRepo.Remove(dummyCourse1.Id); coursesRepo.Remove(dummyCourse2.Id); }