예제 #1
0
        public void GetAllCoursesTest()
        {
            var response = controller.GetAllCourses().Result;

            Utilits.CheckResponseValue <OkObjectResult, List <Course> >(response, new List <Course> {
                course
            });
        }
예제 #2
0
        public void GetLessonByIdTest()
        {
            var response = controller.GetLessonById(courseData.Id, 0).Result;

            var expecteResult = course.Lessons[0];

            Utilits.CheckResponseValue <OkObjectResult, Lesson>(response, expecteResult);
        }
예제 #3
0
        public void StartCourseTest_ValidTest()
        {
            var response = controller.StartCourse(new CourseStartOptions {
                CourseId = courseData.Id
            }, null).Result;

            Utilits.CheckResponseValue <CreatedResult, CourseProgressData>(response, courseProgressData);
        }
예제 #4
0
        public void GetCourseLessonStep_ValidTest()
        {
            var response = controller.GetLessonStep(courseProgressData.Id, lessonId: 0, stepId: 0).Result;

            var expectedResult = courseProgressData.LessonProgresses[0].StepProgresses[0];

            Utilits.CheckResponseValue <OkObjectResult, StepProgressData>(response, expectedResult);
        }
예제 #5
0
        public void GetAllStepsTest()
        {
            var response = controller.GetAllSteps(courseData.Id, 0).Result;

            var expectedResult = course.Lessons[0].Steps;

            Utilits.CheckResponseValue <OkObjectResult, List <LessonStep> >(response, expectedResult);
        }
예제 #6
0
        public void GetAllCoursesProgressesTest_ValidTest()
        {
            var response = controller.GetAllCoursesProgresses(null).Result;

            Utilits.CheckResponseValue <OkObjectResult, List <CourseProgressData> >(
                response,
                new List <CourseProgressData> {
                courseProgressData
            });
        }
예제 #7
0
 public void Init()
 {
     courseData = Utilits.CreateCourse();
     courseData.SetUpLinks();
     userId                = "1";
     user                  = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, userId) }));
     courseProgressData    = courseData.CreateProgress(userId);
     courseProgressData.Id = $"{userId}{courseData.Id}";
     courseProgressData.SetUpLinks();
     controller = CreateProgressController();
 }
예제 #8
0
        public void GetCourseWithInvalidIdTest()
        {
            var invalidId = ObjectId.GenerateNewId().ToString();
            var response  = controller.GetCourse(invalidId).Result;

            var expectedResult = new Error {
                Code = Error.ErrorCode.NotFound, Message = $"Invalid course id = {invalidId}"
            };

            Utilits.CheckResponseValue <NotFoundObjectResult, Error>(response, expectedResult);
        }
예제 #9
0
        public void GetCourseProgress_InvalidUrl()
        {
            var invalidId = ObjectId.GenerateNewId().ToString();
            var response  = controller.GetCourseProgress(invalidId).Result;

            var expectedValue = new Error
            {
                Code    = Error.ErrorCode.NotFound,
                Message = $"Invalid progressId = {invalidId}"
            };

            Utilits.CheckResponseValue <NotFoundObjectResult, Error>(response, expectedValue);
        }
        public void GetIdTest()
        {
            var repo = new Mock <IUserRepository>();

            repo
            .Setup(x => x.GetByLoginAsync(registrationInfo.Login))
            .Returns(() => Task.FromResult(userData));

            var usersController = new UsersController(repo.Object);

            var response = usersController.GetId(registrationInfo.Login).Result;

            Utilits.CheckResponseValue <OkObjectResult, string>(response, userData.Id);
        }
        public void PostInvalidUserTest()
        {
            var usersController = new UsersController(null);
            var invalidUser     = new RegistrationInfo();

            var response = usersController.PostUser(invalidUser).Result;

            var extectedResult = new Error
            {
                Code    = Error.ErrorCode.BadArgument,
                Message = "Invalid user object"
            };

            Utilits.CheckResponseValue <BadRequestObjectResult, Error>(response, extectedResult);
        }
        public void PostExistingUserTest()
        {
            var repo = new Mock <IUserRepository>();

            repo
            .Setup(x => x.ContainsByLoginAsync(registrationInfo.Login))
            .Returns(() => Task.FromResult(true));

            var usersController = new UsersController(repo.Object);

            var response = usersController.PostUser(registrationInfo).Result;

            var extectedResult = new Error {
                Code    = Error.ErrorCode.InvalidOperation,
                Message = $"User with login {registrationInfo.Login} already exists"
            };

            Utilits.CheckResponseValue <BadRequestObjectResult, Error>(response, extectedResult);
        }
예제 #13
0
        public void PostAnswerTest()
        {
            const int lessonId   = 0;
            const int stepId     = 0;
            const int questionId = 0;

            var answer = new Answer {
                QuestionId = questionId, SelectedAnswers = new List <int> {
                    0
                }
            };
            var result = controller.PostAnswer(courseProgressData.Id, lessonId, stepId, answer).Result;

            var question      = courseData.Lessons[lessonId].Steps[stepId].Questions[questionId];
            var expectedValue = question.GetQuestionState().Update(question, answer.SelectedAnswers);

            expectedValue.ProgressId = courseProgressData.Id;
            Utilits.CheckResponseValue <OkObjectResult, QuestionStateData>(result, expectedValue);
        }
예제 #14
0
        private ProgressController CreateProgressController()
        {
            var mockCourseProgressRepo = new Mock <IProgressRepository>();

            mockCourseProgressRepo
            .Setup(courseProgressRepo => courseProgressRepo.ContainsAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(false));

            mockCourseProgressRepo
            .Setup(courseProgressRepo => courseProgressRepo.ContainsAsync(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(false));

            mockCourseProgressRepo
            .Setup(courseProgressRepo => courseProgressRepo.InsertAsync(It.IsAny <CourseProgressData>()))
            .Returns(Task.FromResult($"{userId}{courseData.Id}"));

            mockCourseProgressRepo.Setup(repo => repo.GetAsync(userId, courseData.Id))
            .Returns(Task.FromResult(courseProgressData));

            mockCourseProgressRepo.Setup(repo => repo.GetAsync(courseProgressData.Id))
            .Returns(Task.FromResult(courseProgressData));

            mockCourseProgressRepo.Setup(repo => repo.GetAllByUserAsync(userId))
            .Returns(Task.FromResult(new List <CourseProgressData> {
                courseProgressData
            }));

            var mockCourseRepo = new Mock <IRepository <CourseData> >();

            mockCourseRepo
            .Setup(courseRepo => courseRepo.GetAsync(courseData.Id))
            .Returns(Task.FromResult(courseData));


            var result = new ProgressController(
                mockCourseProgressRepo.Object,
                mockCourseRepo.Object)
            {
                ControllerContext = { HttpContext = Utilits.CreateContext("http", "host", "path", user) }
            };

            return(result);
        }
예제 #15
0
 public void Init()
 {
     courseData = Utilits.CreateCourse();
     course     = courseData.ToApiModel();
     controller = CreateCourseController();
 }
예제 #16
0
        public void GetCourseTest_ValidTest()
        {
            var response = controller.GetCourseProgress(courseProgressData.Id).Result;

            Utilits.CheckResponseValue <OkObjectResult, CourseProgressData>(response, courseProgressData);
        }
예제 #17
0
        public void GetCourseTest()
        {
            var response = controller.GetCourse(courseData.Id).Result;

            Utilits.CheckResponseValue <OkObjectResult, Course>(response, course);
        }
예제 #18
0
        public void GetDescriptionTest()
        {
            var response = controller.GetDescription(courseData.Id).Result;

            Utilits.CheckResponseValue <OkObjectResult, Description>(response, course.Description);
        }