public void WhenMappingLevelAggregation() { MappingService mappingService = new MappingService(null); var searchResultItem1 = new ApprenticeshipSearchResultsItem { StandardId = "101", Title = "Standard 1" }; var resultList = new List <ApprenticeshipSearchResultsItem> { searchResultItem1 }; var levels = new Dictionary <int, long?> { { 2, 3L }, { 3, 38L }, { 4, 380L } }; var model = new ApprenticeshipSearchResponse { TotalResults = 1234L, SearchTerm = "apprenticeship", Results = resultList, AggregationLevel = levels, SelectedLevels = new List <int> { 2 } }; var mappedResult = mappingService.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(model); mappedResult.AggregationLevel.Count().Should().Be(3); mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "2")?.Checked.Should().BeTrue(); mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "3")?.Checked.Should().BeFalse(); mappedResult.AggregationLevel.FirstOrDefault(m => m.Value == "4")?.Count.Should().Be(380); }
public void TotalPageCountReturnsCorrectCount(int totalCount, int pageSize, int expectedTotalPages) { var query = new ApprenticeshipSearchResponse { TotalApprenticeships = totalCount, PageSize = pageSize }; query.TotalPages.Should().Be(expectedTotalPages); }
public void GivenThisSearchRequestFindsNoApprovedApprenticeships() { SetupIncentiveDetailsResponse(); var response = new ApprenticeshipSearchResponse { Apprenticeships = new ApprenticeshipItem[0] }; SetApprenticeshipSearchToReturn(response); }
public ApprenticeshipSearchResponse Search(ApprenticeshipSearchRequestParameters searchParameters) { SanitizeSearchParameters(searchParameters); ValidateSearchParameters(searchParameters); var results = PerformSearch(searchParameters); var aggregationResults = searchParameters.CalculateSubCategoryAggregations ? GetAggregationResultsFrom(results.Aggregations) : null; var response = new ApprenticeshipSearchResponse(results.Total, results.Documents, aggregationResults, searchParameters); return(response); }
private void SetApprenticeshipSearchToReturn(ApprenticeshipSearchResponse response) { _context.CommitmentsV2InnerApi.MockServer .Given( Request.Create().WithPath($"/api/apprenticeships") .WithParam("accountId", _accountId.ToString()) .WithParam("accountLegalEntityId", _accountLegalEntityId.ToString()) .WithParam("startDateRangeFrom", _eligibilityStartDate.ToString("u")) .WithParam("startDateRangeTo", _eligibilityEndDate.ToString("u")) .UsingGet()) .RespondWith( Response.Create() .WithStatusCode((int)HttpStatusCode.OK) .WithHeader("Content-Type", "application/json") .WithBody(JsonSerializer.Serialize(response)) ); }
public void WhenCallingSearchApprenticeship() { _fixture = new Fixture(); _searchApprenticeshipParameters = _fixture.Create <SearchApprenticeshipParameters>(); _apprenticeshipSearchResponse = _fixture.Create <ApprenticeshipSearchResponse>(); var searchApprenticeshipVacanciesRequest = _fixture.Create <SearchApprenticeshipVacanciesRequest>(); var searchApprenticeshipVacanciesResponse = _fixture.Create <SearchApprenticeshipVacanciesResponse>(); _expectedErrorMessage = _fixture.Create <string>(); var mockMapper = new Mock <IMapper>(); mockMapper .Setup(mapper => mapper.Map <SearchApprenticeshipVacanciesRequest>(_searchApprenticeshipParameters)) .Returns(searchApprenticeshipVacanciesRequest); mockMapper .Setup(mapper => mapper.Map <ApprenticeshipSearchResponse>(searchApprenticeshipVacanciesResponse)) .Returns(_apprenticeshipSearchResponse); var mockMediator = new Mock <IMediator>(); mockMediator .Setup(mediator => mediator.Send(searchApprenticeshipVacanciesRequest, CancellationToken.None)) .ReturnsAsync(searchApprenticeshipVacanciesResponse); var mockSettings = new Mock <IProvideSettings>(); mockSettings .Setup(x => x.GetSetting(ApplicationSettingKeys.LiveApprenticeshipVacancyBaseUrlKey)) .Returns(FAABaseUrl); _mockValidationExceptionBuilder = _fixture.Freeze <Mock <IValidationExceptionBuilder> >(composer => composer.Do(mock => mock .Setup(builder => builder.Build(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(new ValidationException(new List <ValidationFailure> { new ValidationFailure("", _expectedErrorMessage) })) )); _orchestrator = new SearchApprenticeshipVacanciesOrchestrator(mockMediator.Object, mockMapper.Object, mockSettings.Object, _mockValidationExceptionBuilder.Object); }
public void GivenThisSearchRequestFindsSeveralApprovedApprenticeships() { SetupIncentiveDetailsResponse(); _eligibleApprenticeship1 = _fixture.Create <ApprenticeshipItem>(); _eligibleApprenticeship2 = _fixture.Create <ApprenticeshipItem>(); _nonEligibleApprenticeship3 = _fixture.Create <ApprenticeshipItem>(); _nonEligibleApprenticeship4 = _fixture.Create <ApprenticeshipItem>(); _nonEligibleApprenticeship5 = _fixture.Create <ApprenticeshipItem>(); var response = new ApprenticeshipSearchResponse { Apprenticeships = new ApprenticeshipItem[] { _eligibleApprenticeship1, _eligibleApprenticeship2, _nonEligibleApprenticeship3, _nonEligibleApprenticeship4, _nonEligibleApprenticeship5 } }; SetApprenticeshipSearchToReturn(response); }
public void GivenThisSearchRequestFindsSeveralApprovedApprenticeshipsWhichAreStopped() { SetupIncentiveDetailsResponse(); _eligibleApprenticeship1 = _fixture.Build <ApprenticeshipItem>().With(a => a.ApprenticeshipStatus, ApprenticeshipStatus.Stopped).Create(); _eligibleApprenticeship2 = _fixture.Build <ApprenticeshipItem>().With(a => a.ApprenticeshipStatus, ApprenticeshipStatus.Stopped).Create(); _nonEligibleApprenticeship3 = _fixture.Build <ApprenticeshipItem>().With(a => a.ApprenticeshipStatus, ApprenticeshipStatus.Stopped).Create(); _nonEligibleApprenticeship4 = _fixture.Build <ApprenticeshipItem>().With(a => a.ApprenticeshipStatus, ApprenticeshipStatus.Stopped).Create(); _nonEligibleApprenticeship5 = _fixture.Build <ApprenticeshipItem>().With(a => a.ApprenticeshipStatus, ApprenticeshipStatus.Stopped).Create(); var response = new ApprenticeshipSearchResponse { Apprenticeships = new ApprenticeshipItem[] { _eligibleApprenticeship1, _eligibleApprenticeship2, _nonEligibleApprenticeship3, _nonEligibleApprenticeship4, _nonEligibleApprenticeship5 } }; SetApprenticeshipSearchToReturn(response); }
public void WhenMappingLevelAggregationIsNull() { MappingService mappingService = new MappingService(null); var searchResultItem1 = new ApprenticeshipSearchResultsItem { StandardId = "101", Title = "Standard 1" }; var resultList = new List <ApprenticeshipSearchResultsItem> { searchResultItem1 }; var model = new ApprenticeshipSearchResponse { TotalResults = 1234L, SearchTerm = "apprenticeship", Results = resultList, AggregationLevel = null, SelectedLevels = new List <int> { 2 } }; var mappedResult = mappingService.Map <ApprenticeshipSearchResponse, ApprenticeshipSearchResultViewModel>(model); mappedResult.AggregationLevel.Count().Should().Be(0); }
private string FormatVacancyDetailsUrl(ApprenticeshipSearchResponse apprenticeshipSearchResponse) { return(string.Format("{0}{1}/apprenticeship/{2}", HttpsScheme, _siteDomainName, apprenticeshipSearchResponse.Id)); }
protected override IEnumerable <LevelAggregationViewModel> ResolveCore(ApprenticeshipSearchResponse source) { return(CreateLevelAggregation(source.AggregationLevel, source.SelectedLevels?.ToList())); }