示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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 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 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 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 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);
        }