public async Task ThenWillReturnCurrentSelectedPage(
            [Frozen] GetApprenticeshipsQuery query,
            List <Apprenticeship> apprenticeships,
            ApprenticeshipSearchResult searchResult,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IApprenticeshipSearch> mockSearch,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField   = "test";
            query.ReverseSort = true;
            query.ProviderId  = null;

            apprenticeships[1].Cohort.EmployerAccountId = query.EmployerAccountId.Value;

            mockSearch.Setup(x => x.Find(It.IsAny <ReverseOrderedApprenticeshipSearchParameters>()))
            .ReturnsAsync(new ApprenticeshipSearchResult
            {
                Apprenticeships = apprenticeships
            });

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(new List <Apprenticeship>());

            mockSearch.Setup(x => x.Find(It.IsAny <ReverseOrderedApprenticeshipSearchParameters>()))
            .ReturnsAsync(searchResult);

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

            Assert.AreEqual(searchResult.PageNumber, result.PageNumber);
        }
        public async Task ThenQueriesApprenticeshipsWithEmployerIdWhenOrderingInReverse(

            [Frozen] GetApprenticeshipsQuery query,
            List <Apprenticeship> apprenticeships,
            GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IApprenticeshipSearch> mockSearch,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField   = "test";
            query.ReverseSort = true;
            query.ProviderId  = null;

            apprenticeships[1].Cohort.EmployerAccountId = query.EmployerAccountId.Value;

            mockSearch.Setup(x => x.Find(It.IsAny <ReverseOrderedApprenticeshipSearchParameters>()))
            .ReturnsAsync(new ApprenticeshipSearchResult
            {
                Apprenticeships = apprenticeships
            });

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(new List <Apprenticeship>());

            await handler.Handle(query, CancellationToken.None);

            mockSearch.Verify(x => x.Find(It.Is <ReverseOrderedApprenticeshipSearchParameters>(sp =>
                                                                                               sp.EmployerAccountId.Equals(query.EmployerAccountId) &&
                                                                                               sp.ProviderId == null)), Times.Once);
        }
Exemplo n.º 3
0
        public async Task ThenReturnUnsortedApprenticeshipsWhenNotOrdering(
            List <Apprenticeship> apprenticeships,
            [Frozen] GetApprenticeshipsQuery query,
            [Frozen] Mock <IApprenticeshipSearch> mockSearch,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField         = "";
            query.EmployerAccountId = null;

            apprenticeships[1].Cohort.ProviderId = query.ProviderId ?? 0;

            mockSearch.Setup(x => x.Find(It.IsAny <ApprenticeshipSearchParameters>()))
            .ReturnsAsync(new ApprenticeshipSearchResult
            {
                Apprenticeships = apprenticeships
            });

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(new List <Apprenticeship>());

            await handler.Handle(query, CancellationToken.None);

            mockSearch.Verify(x => x.Find(It.Is <ApprenticeshipSearchParameters>(sp =>
                                                                                 sp.ProviderId.Equals(query.ProviderId) &&
                                                                                 sp.EmployerAccountId == null)), Times.Once);

            mockMapper
            .Verify(mapper => mapper.Map(It.IsIn(apprenticeships
                                                 .Where(apprenticeship => apprenticeship.Cohort.ProviderId == query.ProviderId))), Times.Once());
        }
Exemplo n.º 4
0
        public async Task ThenReturnsMappedApprenticeships(
            [Frozen] GetApprenticeshipsQuery query,
            List <Apprenticeship> apprenticeships,
            [Frozen] GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IApprenticeshipSearch> search,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField         = "";
            query.EmployerAccountId = null;

            apprenticeships[1].Cohort.ProviderId = query.ProviderId ?? 0;

            search.Setup(x => x.Find(It.IsAny <ApprenticeshipSearchParameters>()))
            .ReturnsAsync(new ApprenticeshipSearchResult
            {
                Apprenticeships = apprenticeships
            });

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);

            mockMapper
            .Setup(mapper => mapper.Map(It.IsIn(apprenticeships
                                                .Where(apprenticeship => apprenticeship.Cohort.ProviderId == query.ProviderId))))
            .ReturnsAsync(apprenticeshipDetails);

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

            result.Apprenticeships.Should().AllBeEquivalentTo(apprenticeshipDetails);
        }
Exemplo n.º 5
0
        public void Setup()
        {
            _apiResponse = _fixture.Create <GetApprenticeshipsResponse>();
            _apiClient   = new Mock <ICommitmentsV2ApiClient <CommitmentsV2ApiConfiguration> >();

            _apiClient.Setup(x => x.Get <GetApprenticeshipsResponse>(It.IsAny <GetApprenticeshipsRequest>()))
            .ReturnsAsync(_apiResponse);

            _courseList          = _fixture.Create <List <Course> >();
            _courseLookupService = new Mock <ICourseLookupService>();
            _courseLookupService.Setup(x => x.GetAllCourses()).ReturnsAsync(_courseList);
            _apiResponse.Apprenticeships.ForEach(x => x.CourseCode = _courseList.First().Id);

            _handler = new GetApprenticeshipsQueryHandler(_apiClient.Object, _courseLookupService.Object);

            _query = _fixture.Create <GetApprenticeshipsQuery>();
        }
Exemplo n.º 6
0
        public async Task ThenReturnsApprenticeshipsData(
            int totalApprenticeshipsFoundWithAlertsCount,
            int totalApprenticeshipsFoundCount,
            List <Apprenticeship> apprenticeships,
            GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails,
            [Frozen] GetApprenticeshipsQuery query,
            [Frozen] Mock <IApprenticeshipSearch> search,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IMapper <Apprenticeship, GetApprenticeshipsQueryResult.ApprenticeshipDetails> > mockMapper,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField         = "";
            query.EmployerAccountId = null;

            apprenticeships[1].Cohort.ProviderId = query.ProviderId ?? 0;

            search.Setup(x => x.Find(It.IsAny <ApprenticeshipSearchParameters>()))
            .ReturnsAsync(new ApprenticeshipSearchResult
            {
                Apprenticeships = new Apprenticeship[0],
                TotalAvailableApprenticeships       = apprenticeships.Count,
                TotalApprenticeshipsFound           = totalApprenticeshipsFoundCount,
                TotalApprenticeshipsWithAlertsFound = totalApprenticeshipsFoundWithAlertsCount
            });

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(new List <Apprenticeship>());

            mockMapper
            .Setup(mapper => mapper.Map(It.IsIn(apprenticeships
                                                .Where(apprenticeship => apprenticeship.Cohort.ProviderId == query.ProviderId))))
            .ReturnsAsync(apprenticeshipDetails);

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

            result.TotalApprenticeshipsFound.Should().Be(totalApprenticeshipsFoundCount);
            result.TotalApprenticeshipsWithAlertsFound.Should().Be(totalApprenticeshipsFoundWithAlertsCount);
            result.TotalApprenticeships.Should().Be(apprenticeships.Count);
        }
Exemplo n.º 7
0
        public async Task ThenReturnsPageNumber(
            [Frozen] GetApprenticeshipsQuery query,
            List <Apprenticeship> apprenticeships,
            ApprenticeshipSearchResult searchResult,
            [Frozen] Mock <IProviderCommitmentsDbContext> mockContext,
            [Frozen] Mock <IApprenticeshipSearch> search,
            GetApprenticeshipsQueryHandler handler)
        {
            query.SortField         = "";
            query.EmployerAccountId = null;

            apprenticeships[1].Cohort.ProviderId = query.ProviderId ?? 0;

            search.Setup(x => x.Find(It.IsAny <ApprenticeshipSearchParameters>()))
            .ReturnsAsync(searchResult);

            mockContext
            .Setup(context => context.Apprenticeships)
            .ReturnsDbSet(apprenticeships);

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

            result.PageNumber.Should().Be(searchResult.PageNumber);
        }