public void GetAllCoursesTest() { var response = controller.GetAllCourses().Result; Utilits.CheckResponseValue <OkObjectResult, List <Course> >(response, new List <Course> { course }); }
public void GetLessonByIdTest() { var response = controller.GetLessonById(courseData.Id, 0).Result; var expecteResult = course.Lessons[0]; Utilits.CheckResponseValue <OkObjectResult, Lesson>(response, expecteResult); }
public void StartCourseTest_ValidTest() { var response = controller.StartCourse(new CourseStartOptions { CourseId = courseData.Id }, null).Result; Utilits.CheckResponseValue <CreatedResult, CourseProgressData>(response, courseProgressData); }
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); }
public void GetAllStepsTest() { var response = controller.GetAllSteps(courseData.Id, 0).Result; var expectedResult = course.Lessons[0].Steps; Utilits.CheckResponseValue <OkObjectResult, List <LessonStep> >(response, expectedResult); }
public void GetAllCoursesProgressesTest_ValidTest() { var response = controller.GetAllCoursesProgresses(null).Result; Utilits.CheckResponseValue <OkObjectResult, List <CourseProgressData> >( response, new List <CourseProgressData> { courseProgressData }); }
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(); }
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); }
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); }
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); }
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); }
public void Init() { courseData = Utilits.CreateCourse(); course = courseData.ToApiModel(); controller = CreateCourseController(); }
public void GetCourseTest_ValidTest() { var response = controller.GetCourseProgress(courseProgressData.Id).Result; Utilits.CheckResponseValue <OkObjectResult, CourseProgressData>(response, courseProgressData); }
public void GetCourseTest() { var response = controller.GetCourse(courseData.Id).Result; Utilits.CheckResponseValue <OkObjectResult, Course>(response, course); }
public void GetDescriptionTest() { var response = controller.GetDescription(courseData.Id).Result; Utilits.CheckResponseValue <OkObjectResult, Description>(response, course.Description); }