public async Task Then_Gets_The_Shortlist_From_CourseDeliveryApi_And_Course_From_CoursesApi(
            GetShortlistForUserQuery query,
            GetShortlistForUserResponse apiResponse,
            GetStandardsListResponse cachedCourses,
            List <GetStandardsListItem> standards,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockCourseDeliveryApiClient,
            [Frozen] Mock <ICachedCoursesService> mockCachedCoursesService,
            GetShortlistForUserQueryHandler handler)
        {
            var shortlistFromApi = apiResponse.Shortlist.ToList();

            for (var i = 0; i < shortlistFromApi.Count; i++)
            {
                standards[i].LarsCode = shortlistFromApi[i].CourseId;
            }
            cachedCourses.Standards = standards;
            mockCourseDeliveryApiClient
            .Setup(client => client.Get <GetShortlistForUserResponse>(
                       It.Is <GetShortlistForUserRequest>(request =>
                                                          request.ShortlistUserId == query.ShortlistUserId)))
            .ReturnsAsync(apiResponse);
            mockCachedCoursesService
            .Setup(service => service.GetCourses())
            .ReturnsAsync(cachedCourses);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Shortlist.Should().BeEquivalentTo(apiResponse.Shortlist,
                                                     options => options.Excluding(item => item.Course));
            foreach (var item in result.Shortlist)
            {
                item.Course.Should().NotBeNull();
                item.Course.Should().BeEquivalentTo(cachedCourses.Standards.Single(listItem => listItem.LarsCode == item.CourseId));
            }
        }
Exemplo n.º 2
0
        public async Task Then_Returns_Results_From_Service(
            GetShortlistForUserQuery query,
            Domain.Shortlist.ShortlistForUser shortlistFromService,
            [Frozen] Mock <IShortlistService> mockService,
            GetShortlistForUserQueryHandler handler)
        {
            mockService
            .Setup(service => service.GetShortlistForUser(query.ShortlistUserId))
            .ReturnsAsync(shortlistFromService);

            var result = await handler.Handle(query, CancellationToken.None);

            result.Shortlist.Should().BeEquivalentTo(shortlistFromService.Shortlist);
        }
Exemplo n.º 3
0
        public async Task Then_Gets_The_Shortlist_From_CourseDeliveryApi_And_Course_From_CoursesApi(
            GetShortlistForUserQuery query,
            GetShortlistForUserResponse apiResponse,
            List <GetApprenticeFeedbackResponse> apprenticeFeedbackResponse,
            GetStandardsListResponse cachedCourses,
            List <GetStandardsListItem> standards,
            [Frozen] Mock <ICourseDeliveryApiClient <CourseDeliveryApiConfiguration> > mockCourseDeliveryApiClient,
            [Frozen] Mock <IApprenticeFeedbackApiClient <ApprenticeFeedbackApiConfiguration> > mockApprenticeFeedbackClient,
            [Frozen] Mock <ICachedCoursesService> mockCachedCoursesService,
            GetShortlistForUserQueryHandler handler)
        {
            var shortlistFromApi = apiResponse.Shortlist.ToList();

            for (var i = 0; i < shortlistFromApi.Count; i++)
            {
                standards[i].LarsCode = shortlistFromApi[i].CourseId;
                apprenticeFeedbackResponse[i].Ukprn = shortlistFromApi[i].ProviderDetails.Ukprn;
            }
            cachedCourses.Standards = standards;
            mockCourseDeliveryApiClient
            .Setup(client => client.Get <GetShortlistForUserResponse>(
                       It.Is <GetShortlistForUserRequest>(request =>
                                                          request.ShortlistUserId == query.ShortlistUserId)))
            .ReturnsAsync(apiResponse);
            mockCachedCoursesService
            .Setup(service => service.GetCourses())
            .ReturnsAsync(cachedCourses);
            mockApprenticeFeedbackClient
            .Setup(s => s.PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> >(It.Is <PostApprenticeFeedbackRequest>
                                                                                                  (t =>
                                                                                                  ((PostApprenticeFeedbackRequestData)t.Data).Ukprns.Except(apiResponse.Shortlist.Select(s => s.ProviderDetails.Ukprn)).Count() == 0 &&
                                                                                                  apiResponse.Shortlist.Select(s => s.ProviderDetails.Ukprn).Except(((PostApprenticeFeedbackRequestData)t.Data).Ukprns).Count() == 0
                                                                                                  ))).ReturnsAsync(new ApiResponse <IEnumerable <GetApprenticeFeedbackResponse> >(apprenticeFeedbackResponse, HttpStatusCode.OK, string.Empty));


            var result = await handler.Handle(query, CancellationToken.None);

            result.Shortlist.Should().BeEquivalentTo(apiResponse.Shortlist,
                                                     options => options.Excluding(item => item.Course).Excluding(item => item.ProviderDetails.ApprenticeFeedback));
            foreach (var item in result.Shortlist)
            {
                item.Course.Should().NotBeNull();
                item.Course.Should().BeEquivalentTo(cachedCourses.Standards.Single(listItem => listItem.LarsCode == item.CourseId));

                item.ProviderDetails.ApprenticeFeedback.Should().NotBeNull();
                item.ProviderDetails.ApprenticeFeedback.Should().BeEquivalentTo(apprenticeFeedbackResponse.First(s => s.Ukprn == item.ProviderDetails.Ukprn));
            }
        }
Exemplo n.º 4
0
        public async Task Then_Gets_Shortlist_From_The_Services(
            GetShortlistForUserQuery query,
            List <Domain.Models.Shortlist> shortlistFromService,
            ProviderLocation providerLocationFromService,
            [Frozen] Mock <IShortlistService> mockShortlistService,
            GetShortlistForUserQueryHandler handler)
        {
            //Arrange
            mockShortlistService
            .Setup(x => x.GetAllForUserWithProviders(query.UserId))
            .ReturnsAsync(shortlistFromService);

            //Act
            var actual = await handler.Handle(query, It.IsAny <CancellationToken>());

            //Assert
            actual.Shortlist.Should().BeEquivalentTo(shortlistFromService);
        }