public void CanAddNewStudentCourseEnrollment()
        {
            // dummy username (provided by an external accounts
            // data store (e.g. ASP .net membership/authentication)
            string username = "******";

            // Create a dummy course and add it to the database (since the student
            // enrollments model will not allow an enrollment to be added to a student
            // for a course that doesn't exist in the database)
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();
            ICoursesModel courseModel = new CoursesModel();
            dummyCourse.Id = courseModel.AddOrUpdateCourse(dummyCourse).Id;

            // add the new enrollment for the given user and specified course
            IStudentEnrollmentsModel model = new StudentEnrollmentsModel();
            StudentRecord studentEnrollmentRecord = model.AddEnrollment(username, dummyCourse.Id);

            Assert.NotNull(studentEnrollmentRecord);
            Assert.IsNotNullOrEmpty(studentEnrollmentRecord.Username);
            Assert.AreEqual(studentEnrollmentRecord.Username, username);
            Assert.NotNull(studentEnrollmentRecord.StudentCourseEnrollments);
            Assert.AreEqual(studentEnrollmentRecord.StudentCourseEnrollments.Count, 1);

            var enrollments = new List<Enrollment>(studentEnrollmentRecord.StudentCourseEnrollments);
            Assert.AreEqual(enrollments[0].CourseId, dummyCourse.Id);

            // clean up Db:  remove student record
            var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>();
            enrollmentsRepo.Remove(studentEnrollmentRecord.Username);

            // clean up Db:  remove dummy course
            var coursesRepo = new BizCollegeRepository<Course, string>();
            coursesRepo.Remove(dummyCourse.Id);
        }
        public void CanSetStudentEnrollmentLastViewedSlide()
        {
            string username = "******";

            // Create a dummy course
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();
            ICoursesModel courseModel = new CoursesModel();
            dummyCourse.Id = courseModel.AddOrUpdateCourse(dummyCourse).Id;

            // add a new enrollment for the given user and specified dummy course
            IStudentEnrollmentsModel model = new StudentEnrollmentsModel();
            StudentRecord studentEnrollmentRecord = model.AddEnrollment(username, dummyCourse.Id);

            // Simulate that the user last viewed/accessed slide 5 of the dummy course
            int lastViewedSlideIndex = 5;

            // Update the student enrollment for the dummy course with the specified last viewed slide index
            StudentRecord updatedRecord = model.SetStudentEnrollmentLastViewedSlide(username, dummyCourse.Id, lastViewedSlideIndex);

            Assert.NotNull(updatedRecord);
            Assert.AreEqual(updatedRecord.StudentCourseEnrollments[0].LastViewedSlideIndex, lastViewedSlideIndex);

            // clean up Db:  remove student record
            var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>();
            enrollmentsRepo.Remove(studentEnrollmentRecord.Username);

            // clean up Db:  remove dummy course
            var coursesRepo = new BizCollegeRepository<Course, string>();
            coursesRepo.Remove(dummyCourse.Id);
        }
        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);
        }
        public void CanSetStudentEnrollmentCourseCompletion()
        {
            string username = "******";

            // Create a dummy course and add it to the database
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();
            ICoursesModel courseModel = new CoursesModel();
            dummyCourse.Id = courseModel.AddOrUpdateCourse(dummyCourse).Id;

            // add the new enrollment for the given user and specified course
            IStudentEnrollmentsModel model = new StudentEnrollmentsModel();
            StudentRecord studentEnrollmentRecord = model.AddEnrollment(username, dummyCourse.Id);

            // set the course as completed
            model.SetStudentCourseCompletion(username, dummyCourse.Id);

            //  retrieve the record from the database and make sure that course
            // was set to complete.
            var enrollmentsRepo = new BizCollegeRepository<StudentRecord, string>();
            var fromDb = enrollmentsRepo.Get(studentEnrollmentRecord.Username);

            Assert.NotNull(fromDb);
            Assert.IsTrue(fromDb.StudentCourseEnrollments[0].WasCourseCompleted);

            // clean up Db:  remove student record
            enrollmentsRepo.Remove(studentEnrollmentRecord.Username);

            // clean up Db:  remove dummy course
            var coursesRepo = new BizCollegeRepository<Course, string>();
            coursesRepo.Remove(dummyCourse.Id);
        }