public void CanGetAllCourses()
        {
            List<Course> dummyCourses = new List<Course>();
            dummyCourses.Add(DummyDataGenerator.CreateDummyCourse());
            dummyCourses.Add(DummyDataGenerator.CreateDummyCourse());

            // Add two dummy courses to the database
            ICoursesModel model = new CoursesModel();
            dummyCourses[0].Id = model.AddOrUpdateCourse(dummyCourses[0]).Id;
            dummyCourses[1].Id = model.AddOrUpdateCourse(dummyCourses[1]).Id;

            // Retrieve all the courses in the database (should be only two we added above)
            var repo = new BizCollegeRepository<Course, string>();
            var allCoursesFromDb = repo.GetAllItems();

            Assert.NotNull(allCoursesFromDb);
            Assert.AreEqual(allCoursesFromDb.Count, dummyCourses.Count);

            foreach (var courseInDb in allCoursesFromDb)
            {
                Assert.IsTrue(dummyCourses.Contains(courseInDb));
            }

            // clean up Db
            repo.Remove(dummyCourses[0].Id);
            repo.Remove(dummyCourses[1].Id);
        }
        public void CanAddNewCourse()
        {
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();

            // Course Id's are autogenerated by the database, so when we
            // add a new one to the db, we cache the assigned Id after the
            // add operation has completed (that way we can retrieve the course
            // from the db to run our assertions on the data
            ICoursesModel model = new CoursesModel();
            dummyCourse.Id = model.AddOrUpdateCourse(dummyCourse).Id;

            // Retrieve the newly added course back out from the Db
            var repo = new BizCollegeRepository<Course, string>();
            var fromDb = repo.Get(dummyCourse.Id);

            // Check the values against our dummy course
            Assert.NotNull(fromDb);
            Assert.AreEqual(dummyCourse.Id, fromDb.Id);
            Assert.AreEqual(dummyCourse.Name, fromDb.Name);
            Assert.AreEqual(dummyCourse.Description, fromDb.Description);
            Assert.AreEqual(dummyCourse.CreatedByUsername, fromDb.CreatedByUsername);
            Assert.AreEqual(dummyCourse.LastUpdateByUsername, fromDb.LastUpdateByUsername);
            Assert.AreEqual(dummyCourse.CourseSlides.Count, fromDb.CourseSlides.Count);

            // clean-up db
            repo.Remove(fromDb.Id);
        }
        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 CanGetCourseByCourseId()
        {
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();

            ICoursesModel model = new CoursesModel();
            dummyCourse.Id = model.AddOrUpdateCourse(dummyCourse).Id;

            var fromDb = model.GetCourse(dummyCourse.Id);

            // Check the values against our dummy course
            Assert.NotNull(fromDb);
            Assert.AreEqual(dummyCourse.Id, fromDb.Id);
            Assert.AreEqual(dummyCourse.Name, fromDb.Name);
            Assert.AreEqual(dummyCourse.Description, fromDb.Description);
            Assert.AreEqual(dummyCourse.CreatedByUsername, fromDb.CreatedByUsername);
            Assert.AreEqual(dummyCourse.LastUpdateByUsername, fromDb.LastUpdateByUsername);
            Assert.AreEqual(dummyCourse.CourseSlides.Count, fromDb.CourseSlides.Count);

            // clean-up db
            var repo = new BizCollegeRepository<Course, string>();
            repo.Remove(fromDb.Id);
        }
        public void CanUpdateExistingCourse()
        {
            // Create a dummy course and add it to the database
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();
            ICoursesModel model = new CoursesModel();
            dummyCourse.Id = model.AddOrUpdateCourse(dummyCourse).Id;

            // Update the course by adding a course slide and changing
            dummyCourse.CourseSlides.Add(new CourseContent()
            {
                CourseContentType = ContentType.Video,
                Description = "This video talks about how to start your own business",
                ResourcePath = "http://www.youtube.com",
                Title = "Business Course Introduction Video",
                IndexInSquence = 0,
            });

            // Also update the other properties of the coures
            dummyCourse.Name = "Business Savvy 101";
            dummyCourse.Description = "Tips on how to run a business properly";
            dummyCourse.State = CourseState.Active;
            dummyCourse.LastUpdateByUsername = "******";
            dummyCourse.CreatedByUsername = "******";

            //  Persist the course udpates to the database
            model.AddOrUpdateCourse(dummyCourse);

            // Retrieve a copy of the updated course back out from the Db
            var repo = new BizCollegeRepository<Course, string>();
            var fromDb = repo.Get(dummyCourse.Id);

            // Check that the course properties we updated were persisted
            Assert.NotNull(fromDb);
            Assert.AreEqual(dummyCourse.Id, fromDb.Id);

            Assert.AreEqual(dummyCourse.Name,                 fromDb.Name);
            Assert.AreEqual(dummyCourse.Description,          fromDb.Description);
            Assert.AreEqual(dummyCourse.State,                fromDb.State);
            Assert.AreEqual(dummyCourse.LastUpdateByUsername, fromDb.LastUpdateByUsername);
            Assert.AreEqual(dummyCourse.CreatedByUsername,    fromDb.CreatedByUsername);

            Assert.NotNull(fromDb.CourseSlides[0]);
            Assert.AreEqual(dummyCourse.CourseSlides.Count,                fromDb.CourseSlides.Count);
            Assert.AreEqual(dummyCourse.CourseSlides[0].CourseContentType, fromDb.CourseSlides[0].CourseContentType);
            Assert.AreEqual(dummyCourse.CourseSlides[0].Description,       fromDb.CourseSlides[0].Description);
            Assert.AreEqual(dummyCourse.CourseSlides[0].ResourcePath,      fromDb.CourseSlides[0].ResourcePath);
            Assert.AreEqual(dummyCourse.CourseSlides[0].Title,             fromDb.CourseSlides[0].Title);
            Assert.AreEqual(dummyCourse.CourseSlides[0].IndexInSquence,    fromDb.CourseSlides[0].IndexInSquence);

            // clean-up db
            repo.Remove(fromDb.Id);
        }
        public void CanRemoveExistingCourse()
        {
            var dummyCourse = DummyDataGenerator.CreateDummyCourse();

            ICoursesModel model = new CoursesModel();
            dummyCourse.Id = model.AddOrUpdateCourse(dummyCourse).Id;

            // Remove the dummyCourse
            model.RemoveCourse(dummyCourse.Id);

            // Check that the course was removed from the Db
            var repo = new BizCollegeRepository<Course, string>();
            var fromDb = repo.Get(dummyCourse.Id);

            Assert.IsNull(fromDb);
        }
        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 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);
        }