public void buildCourseCommentViewModelTest_NullParameter()
        {
            Comment testComment = null;
            CourseCommentViewModel courseCommentViewModel = _viewModelService.buildCourseCommentViewModel(testComment);

            Assert.Null(courseCommentViewModel);
        }
        public void buildCourseCommentViewModelTest_HappyPath()
        {
            Enrolled tempEnrolled = _context.Enrolled.Find(1);

            tempEnrolled.course = _context.Courses.Find(tempEnrolled.courseId);
            Comment testComment = new Comment(tempEnrolled);
            CourseCommentViewModel courseCommentViewModel = _viewModelService.buildCourseCommentViewModel(testComment);

            Assert.True(courseCommentViewModel.ratingScore == 90, "rating should be 90");
            Assert.Equal("I like that course", courseCommentViewModel.comment);
            Assert.True(courseCommentViewModel.takenDate.Equals(new DateTime(2019, 9, 6)), "should have same date");
        }
Exemplo n.º 3
0
        public ActionResult Details(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(RedirectToAction("Index", new { page = 0 }));
            }

            var course = courseClient.GetCourseByCode(code);
            var model  = new CourseViewModels()
            {
                Code       = course.Code,
                Desp       = course.Desp,
                Name       = course.Name,
                PicUrl     = course.PicUrl,
                University = utilityClient.NameOfUniversity(course.University),
            };

            var teacherList = utilityClient.GetTeacherByCourseId(code);
            var list        = new List <string>();

            foreach (var item in teacherList)
            {
                list.Add(teacherClient.GetTeacherInfo(item).UserName);
            }
            ViewBag.Teacher = list;

            // 查询评论
            ViewBag.CmtList = new List <CourseCommentViewModel>();
            var retList = courseCommentClient.GetCommentByCode(code);

            foreach (var item in retList)
            {
                var tmp      = new CourseCommentViewModel(item);
                var userInfo = accountClient.GetUserInfo(item.Email);
                tmp.UserAvatar = string.IsNullOrEmpty(userInfo.Avatar) ? "00.jpg" : userInfo.Avatar;
                tmp.UserName   = string.IsNullOrEmpty(userInfo.Nick) ? userInfo.UserName : userInfo.Nick;
                tmp.UserEmail  = item.Email;
                ViewBag.CmtList.Add(tmp);
            }

            return(View(model));
        }