예제 #1
0
        public void CanUpsertAndDeleteCourse()
        {
            var category = GetCategories(false).FirstOrDefault(c => c.sub_categories.Any());
            Assert.IsNotNull(category);

            var newCourse = new m_course
            {
                title = "New Course",
                state_ceus = new[]
                {
                    new m_state_ceu {state = "OH", hours = 1, category_id = new Guid()},
                    new m_state_ceu {state = "CA", hours = 1.25m, category_id = new Guid()}
                },
                category = category.id,
                sub_category = category.sub_categories.First().id
            };

            var course = UpsertCourse(newCourse);
            Assert.IsNotNull(course);
            Assert.IsFalse(course.id.IsNullOrEmpty());
            Assert.IsTrue(course.date_created.Year == DateTime.UtcNow.Year);

            var courses = GetCourses();
            Assert.IsNotNull(courses);
            Assert.IsTrue(courses.Count(c => c.id == course.id) == 1);

            course.title = "New Course Updated";
            var updatedCourse = UpsertCourse(course);
            Assert.IsNotNull(updatedCourse);
            Assert.AreEqual(course.id, updatedCourse.id);
            Assert.AreEqual(course.title, updatedCourse.title);

            courses = GetCourses();
            Assert.IsNotNull(courses);
            Assert.IsTrue(courses.Count(c => c.id == course.id) == 1);

            DeleteCourse(updatedCourse);

            courses = GetCourses();
            Assert.IsNotNull(courses);
            Assert.IsFalse(courses.Any(c => c.id == course.id));
        }
예제 #2
0
        public void CanUpsertAndDeleteSectionQuestions()
        {
            var category = GetCategories().FirstOrDefault(c => c.sub_categories.Any());
            Assert.IsNotNull(category);

            var newCourse = new m_course
            {
                title = "New Course",
                state_ceus = new[]
                {
                    new m_state_ceu {state = "OH", hours = 1, category_id = new Guid()},
                    new m_state_ceu {state = "CA", hours = 1.25m, category_id = new Guid()}
                },
                category = category.id,
                sub_category = category.sub_categories.First().id
            };

            var course = UpsertCourse(newCourse);
            Assert.IsNotNull(course);

            var section = UpsertSection(course.id, new m_section_overview { title = "New Section" });
            Assert.IsNotNull(section);

            var questions = new[]
            {
                new m_question
                {
                    question_text = "Question text 1.",
                    question_type = QuestionType.Text,
                    response_heading = "Heading",
                    response_message = "Message",
                    tip = "Tip",
                    options = new[]
                    {
                        new m_option {correct = true, text = "Correct"},
                        new m_option {correct = false, text = "Wrong"}
                    }
                },
                new m_question
                {
                    question_text = "Question text 2.",
                    question_type = QuestionType.Text,
                    response_heading = "Heading",
                    response_message = "Message",
                    tip = "Tip",
                    options = new[]
                    {
                        new m_option {correct = true, text = "Correct"},
                        new m_option {correct = false, text = "Wrong"}
                    }
                }
            };

            var newQuestions = UpsertQuestions(course.id, section.id, questions);
            Assert.IsNotNull(newQuestions);
            Assert.IsTrue(newQuestions.Any());
            Assert.IsFalse(newQuestions.Any(q => q.id.IsNullOrEmpty()));
            Assert.AreEqual(questions[0].question_text, newQuestions[0].question_text);

            newQuestions[0].question_text = "Updated Question Text";

            var resortedQuestions = newQuestions.Reverse().ToArray();

            var updatedQuestion = UpsertQuestions(course.id, section.id, resortedQuestions);
            Assert.IsNotNull(updatedQuestion);
            Assert.AreEqual(newQuestions[0].id, updatedQuestion[1].id);
            Assert.AreEqual(newQuestions[0].question_text, updatedQuestion[1].question_text);

            var questions2 = GetQuestions(course.id, section.id);
            Assert.IsNotNull(questions2);
            Assert.IsTrue(questions.Length == questions2.Length);

            DeleteCourse(course);
        }
예제 #3
0
 public m_course UpsertCourse(m_course course)
 {
     return new CourseControllerTests().UpsertCourse(course);
 }
예제 #4
0
 public void DeleteCourse(m_course course)
 {
     new CourseControllerTests().DeleteCourse(course);
 }
예제 #5
0
 public m_course UpsertCourse(m_course course)
 {
     return ExecutePutRequest<m_course>("", course);
 }
예제 #6
0
 public void DeleteCourse(m_course course)
 {
     ExecuteDeleteRequest(course.id.ToString());
 }
예제 #7
0
        public m_course UpsertCourse(m_course course)
        {
            Course c = null;
            if (!course.id.IsNullOrEmpty())
            {
                c = _courseService.GetCourse(course.id, status: null);
                if (c == null)
                    throw new NullReferenceException("Course not found to update.");
            }
            if (c == null)
                c = new Course {DateCreatedUtc = DateTime.UtcNow, Status = CourseStatus.Draft};

            c.Title = course.title;

            c.Category = course.sub_category.HasValue ? _entityRepository.GetByID<SubCategory>(course.sub_category.Value) : null;

            c.Manufacturer = course.manufacturer.HasValue ? _entityRepository.GetByID<Manufacturer>(course.manufacturer.Value) : null;

            c.PrerequisiteCourses.Clear();
            if (course.prerequisite_course.HasValue)
            {
                var prereq = _courseService.GetCourse(course.prerequisite_course.Value, status: null);
                if(prereq != null)
                c.PrerequisiteCourses.Add(prereq);
            }

            c.StateCEUs.Clear();
            course.state_ceus.ForEach(
                s =>
                    c.StateCEUs.Add(new StateCEU
                    {
                        StateAbbr = s.state,
                        Category =
                            s.category_id.HasValue
                                ? _entityRepository.GetByID<CertificationCategory>(s.category_id.Value)
                                : null,
                        Hours = s.hours,
                        ActivityID = s.activity_id,
                        ActivityType = s.activity_type
                    }));

            _entityRepository.Save(c);

            return c;
        }