public async Task <IActionResult> PostChooseCourse(PostChooseCourseRequest request) { try { var query = new GetCourseEpaosQuery { CourseId = request.SelectedCourseId }; var result = await _mediator.Send(query); if (result?.Epaos?.Count == 1) { return(RedirectToRoute(RouteNames.CourseEpao, new GetCourseEpaoDetailsRequest { Id = request.SelectedCourseId, EpaoId = result.Epaos.First().EpaoId })); } return(RedirectToRoute(RouteNames.CourseEpaos, new GetCourseEpaosRequest { Id = request.SelectedCourseId })); } catch (ValidationException) { return(RedirectToRoute( RouteNames.ChooseCourse, new GetChooseCourseRequest { SelectedCourseId = "-1" })); } }
public async Task Then_Gets_CourseEpaos_From_Service( GetCourseEpaosQuery query, CourseEpaos courseEpaos, DeliveryAreaList deliveryAreas, [Frozen] Mock <IValidator <GetCourseEpaosQuery> > mockValidator, [Frozen] Mock <ICourseService> mockCourseService, [Frozen] Mock <IEpaoService> mockEpaoService, GetCourseEpaosQueryHandler handler) { mockValidator .Setup(validator => validator.ValidateAsync(query)) .ReturnsAsync(new ValidationResult()); mockCourseService .Setup(service => service.GetCourseEpaos(query.CourseId)) .ReturnsAsync(courseEpaos); mockEpaoService .Setup(service => service.GetDeliveryAreas()) .ReturnsAsync(deliveryAreas); var result = await handler.Handle(query, CancellationToken.None); result.Course.Should().BeEquivalentTo(courseEpaos.Course); result.Epaos.Should().BeEquivalentTo(courseEpaos.Epaos); result.DeliveryAreas.Should().BeEquivalentTo(deliveryAreas.DeliveryAreas); }
public async Task Then_Gets_Epaos_From_Assessors_Api_And_Course_From_Courses_Api_And_Filters_Epaos( GetCourseEpaosQuery query, List <GetCourseEpaoListItem> epaoApiResponse, GetStandardsListItem coursesApiResponse, [Frozen] Mock <IAssessorsApiClient <AssessorsApiConfiguration> > mockAssessorsApiClient, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseEpaoIsValidFilterService> mockCourseEpaoFilter, GetCourseEpaosQueryHandler handler) { mockAssessorsApiClient .Setup(client => client.GetAll <GetCourseEpaoListItem>( It.Is <GetCourseEpaosRequest>(request => request.CourseId == query.CourseId))) .ReturnsAsync(epaoApiResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(request => request.StandardId == query.CourseId))) .ReturnsAsync(coursesApiResponse); mockCourseEpaoFilter .Setup(service => service.IsValidCourseEpao(It.Is <GetCourseEpaoListItem>(item => item.EpaoId == epaoApiResponse[0].EpaoId))) .Returns(true); var result = await handler.Handle(query, CancellationToken.None); result.Epaos.Should().BeEquivalentTo(epaoApiResponse.Where(item => item.EpaoId == epaoApiResponse[0].EpaoId).ToList()); result.Epaos.Should().BeInAscendingOrder(item => item.Name); result.Course.Should().BeEquivalentTo(coursesApiResponse); }
public async Task Then_Gets_Epaos_From_Assessors_Api_And_Course_From_Courses_Api_And_Filters_Epaos( GetCourseEpaosQuery query, List <GetCourseEpaoListItem> epaoApiResponse, GetStandardsListItem coursesApiResponse, IEnumerable <GetStandardsExtendedListItem> standardsResponse, [Frozen] Mock <IAssessorsApiClient <AssessorsApiConfiguration> > mockAssessorsApiClient, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseEpaoIsValidFilterService> mockCourseEpaoFilter, GetCourseEpaosQueryHandler handler) { mockAssessorsApiClient .Setup(client => client.GetAll <GetCourseEpaoListItem>( It.Is <GetCourseEpaosRequest>(request => request.CourseId == query.CourseId))) .ReturnsAsync(epaoApiResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(request => request.StandardId == query.CourseId))) .ReturnsAsync(coursesApiResponse); foreach (var epao in epaoApiResponse) { mockAssessorsApiClient .Setup(client => client.Get <IEnumerable <GetStandardsExtendedListItem> >( It.Is <GetCourseEpaosStandardVersionsRequest>(request => request.LarsCode == query.CourseId && request.organisationId == epao.EpaoId))) .ReturnsAsync(standardsResponse); } mockCourseEpaoFilter .Setup(service => service.IsValidCourseEpao(It.Is <GetCourseEpaoListItem>(item => item.EpaoId == epaoApiResponse[0].EpaoId))) .Returns(true); mockCourseEpaoFilter .Setup(service => service.ValidateEpaoStandardDates(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns(true); mockCourseEpaoFilter .Setup(service => service.ValidateVersionDates(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns(true); var result = await handler.Handle(query, CancellationToken.None); result.Epaos.Select(x => x.CourseEpaoDetails.StandardVersions) .FirstOrDefault().Should().BeEquivalentTo(standardsResponse.Select(x => x.Version)); result.Epaos.Should().BeEquivalentTo(epaoApiResponse.Where(item => item.EpaoId == epaoApiResponse[0].EpaoId).ToList()); result.Epaos.Should().BeInAscendingOrder(item => item.Name); result.Course.Should().BeEquivalentTo(coursesApiResponse); }
public async Task And_Query_InValid_Then_Throws_ValidationException( GetCourseEpaosQuery query, string propertyName, ValidationResult validationResult, [Frozen] Mock <IValidator <GetCourseEpaosQuery> > mockValidator, GetCourseEpaosQueryHandler handler) { validationResult.AddError(propertyName); mockValidator .Setup(validator => validator.ValidateAsync(query)) .ReturnsAsync(validationResult); var act = new Func <Task>(async() => await handler.Handle(query, CancellationToken.None)); act.Should().Throw <ValidationException>() .WithMessage($"*{propertyName}*"); }
public async Task And_Course_Not_Found_Then_Invalid( GetCourseEpaosQuery query, CourseList courseList, [Frozen] Mock <ICourseService> mockCourseService, GetCourseEpaosQueryValidator validator) { mockCourseService .Setup(service => service.GetCourses()) .ReturnsAsync(courseList); var result = await validator.ValidateAsync(query); result.IsValid().Should().BeFalse(); result.ValidationDictionary.Count.Should().Be(1); result.ValidationDictionary .Should().ContainKey(nameof(GetCourseEpaosQuery.CourseId)) .WhichValue.Should().Be($"{nameof(GetCourseEpaosQuery.CourseId)} not found"); }
public async Task And_Course_Is_Found_Then_Valid( GetCourseEpaosQuery query, List <CourseListItem> courses, [Frozen] Mock <ICourseService> mockCourseService, GetCourseEpaosQueryValidator validator) { courses.Add(new CourseListItem(query.CourseId, "title", 2, false)); var courseList = new CourseList { Courses = courses }; mockCourseService .Setup(service => service.GetCourses()) .ReturnsAsync(courseList); var result = await validator.ValidateAsync(query); result.IsValid().Should().BeTrue(); }
public async Task If_No_Valid_Standards_Found_Returns_Zero_Epaos( GetCourseEpaosQuery query, List <GetCourseEpaoListItem> epaoApiResponse, GetStandardsListItem coursesApiResponse, IEnumerable <GetStandardsExtendedListItem> standardsResponse, [Frozen] Mock <IAssessorsApiClient <AssessorsApiConfiguration> > mockAssessorsApiClient, [Frozen] Mock <ICoursesApiClient <CoursesApiConfiguration> > mockCoursesApiClient, [Frozen] Mock <ICourseEpaoIsValidFilterService> mockCourseEpaoFilter, GetCourseEpaosQueryHandler handler) { mockAssessorsApiClient .Setup(client => client.GetAll <GetCourseEpaoListItem>( It.Is <GetCourseEpaosRequest>(request => request.CourseId == query.CourseId))) .ReturnsAsync(epaoApiResponse); mockCoursesApiClient .Setup(client => client.Get <GetStandardsListItem>( It.Is <GetStandardRequest>(request => request.StandardId == query.CourseId))) .ReturnsAsync(coursesApiResponse); foreach (var epao in epaoApiResponse) { mockAssessorsApiClient .Setup(client => client.Get <IEnumerable <GetStandardsExtendedListItem> >( It.Is <GetCourseEpaosStandardVersionsRequest>(request => request.LarsCode == query.CourseId && request.organisationId == epao.EpaoId))) .ReturnsAsync(standardsResponse); } mockCourseEpaoFilter .Setup(service => service.IsValidCourseEpao(It.IsAny <GetCourseEpaoListItem>())) .Returns(true); mockCourseEpaoFilter .Setup(service => service.ValidateVersionDates(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns(false); var result = await handler.Handle(query, CancellationToken.None); result.Epaos.Should().BeEmpty(); }
public async Task <IActionResult> CourseEpaos(GetCourseEpaosRequest request) { try { var query = new GetCourseEpaosQuery { CourseId = request.Id }; var result = await _mediator.Send(query); var model = new CourseEpaosViewModel { Course = result.Course, Epaos = result.Epaos.Select(item => new EpaoListItemViewModel( item, result.DeliveryAreas, _locationStringBuilder.BuildLocationString)) }; return(View(model)); } catch (ValidationException) { return(RedirectToRoute(RouteNames.Error404)); } }