public async Task GivenUlnSearchResultHasErrorShouldReturnSearchViewWithErrorResponse() { // Arrange var errorResponse = "InvalidUrn"; var query = new ApprenticeshipSearchQuery { SearchTerm = "", SearchType = ApprenticeshipSearchType.SearchByUln, HashedAccountId = "ASDNA" }; _orchestrator .Setup(x => x.GetApprenticeshipsByUln(It.IsAny <ApprenticeshipSearchQuery>())) .ReturnsAsync(new UlnSummaryViewModel { ReponseMessages = { errorResponse } }) .Verifiable(); // Act var result = await _sut.SearchRequest(query.HashedAccountId, query.SearchType, query.SearchTerm); // Assert var view = result as ViewResult; view.Should().NotBeNull(); Assert.AreEqual(view.ViewName, "Search"); var model = view.Model as ApprenticeshipSearchQuery; model.ReponseMessages.Should().Contain(errorResponse); }
public void TestDefaultQuery() { var query = new ApprenticeshipSearchQuery(); var queryString = _sut.GetQueryString(query); queryString.Should().Be("?PageNumber=1&PageSize=25"); }
public void ShouldFilterOnName(Originator caller) { _apprenticeships.Add(new Apprenticeship { Id = 009, FirstName = "Should", LastName = "Find", TrainingCode = "123-00-009", ULN = "1234567890" }); _apprenticeships.Add(new Apprenticeship { Id = 010, FirstName = "Should", LastName = "Not Find", TrainingCode = "10", ULN = "0987654321" }); var query = new ApprenticeshipSearchQuery { SearchKeyword = "ld fi" }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(1); result.PageOfResults.Single().Id.Should().Be(009); }
public async Task GivenValidCohortIdSearchShouldReturnCohortSummaryView() { // Arrange var query = new ApprenticeshipSearchQuery { SearchTerm = "JRML7V", SearchType = ApprenticeshipSearchType.SearchByCohort, HashedAccountId = "ASDNA" }; _orchestrator .Setup(x => x.GetCommitmentSummary(It.IsAny <ApprenticeshipSearchQuery>())) .ReturnsAsync(new CommitmentSummaryViewModel()) .Verifiable(); // Act var result = await _sut.SearchRequest(query.HashedAccountId, query.SearchType, query.SearchTerm); // Assert var view = result as ViewResult; view.Should().NotBeNull(); Assert.AreEqual(view.ViewName, "CohortSearchSummary"); var model = view.Model as CommitmentSummaryViewModel; model.Should().NotBeNull(); }
public void ShouldFilterOnEmployerIdWhenProvider() { _apprenticeships.Add(new Apprenticeship { Id = 082, FirstName = "Should find", TrainingCode = "123-00-082", EmployerAccountId = 999L, LegalEntityName = "Employer 999", LegalEntityId = "09990" }); _apprenticeships.Add(new Apprenticeship { Id = 010, FirstName = "Should not find", TrainingCode = "10", EmployerAccountId = 001L, LegalEntityName = "Employer 001", LegalEntityId = "Abba-" }); var query = new ApprenticeshipSearchQuery { EmployerOrganisationIds = new List <string> { "09990" } }; var result = _sut.Filter(_apprenticeships, query, Originator.Provider); result.PageOfResults.Count.Should().Be(1); result.PageOfResults.FirstOrDefault().LegalEntityName.Should().Be("Employer 999"); }
public void SetUp() { _data = new List <Apprenticeship>(); _userQuery = new ApprenticeshipSearchQuery(); _sut = new FacetMapper(Mock.Of <ICurrentDateTime>()); }
public void ShouldNotFilterOnEmployerIdWhenCallerIsEmployer() { _apprenticeships.Add(new Apprenticeship { Id = 082, FirstName = "Should find", TrainingCode = "123-00-082", EmployerAccountId = 999L, LegalEntityName = "Employer 999" }); _apprenticeships.Add(new Apprenticeship { Id = 010, FirstName = "Should not find", TrainingCode = "10", EmployerAccountId = 001L, LegalEntityName = "Employer 001" }); var query = new ApprenticeshipSearchQuery { EmployerOrganisationIds = new List <string> { "999" } }; var result = _sut.Filter(_apprenticeships, query, Originator.Employer); result.PageOfResults.Count.Should().Be(_apprenticeships.Count); }
public void ShouldNotFilterOnProviderIdWhenCallerIsProvider() { _apprenticeships.Add(new Apprenticeship { Id = 082, FirstName = "Should find", TrainingCode = "123-00-082", EmployerAccountId = 999L, LegalEntityName = "Employer 999", ProviderId = 008, ProviderName = "Provider 008" }); _apprenticeships.Add(new Apprenticeship { Id = 010, FirstName = "Should not find", TrainingCode = "10", EmployerAccountId = 001L, LegalEntityName = "Employer 001", ProviderId = 007, ProviderName = "Provider 007" }); var query = new ApprenticeshipSearchQuery { TrainingProviderIds = new List <long> { 007 } }; var result = _sut.Filter(_apprenticeships, query, Originator.Provider); result.PageOfResults.Count.Should().Be(_apprenticeships.Count); }
public async Task GivenValidUlnSearchShouldSetAccountIdOnViewModel() { // Arrange var query = new ApprenticeshipSearchQuery { SearchTerm = "25632323233", SearchType = ApprenticeshipSearchType.SearchByUln, HashedAccountId = "ASDNA" }; _orchestrator .Setup(x => x.GetApprenticeshipsByUln(It.IsAny <ApprenticeshipSearchQuery>())) .ReturnsAsync(new UlnSummaryViewModel()) .Verifiable(); // Act var result = await _sut.SearchRequest(query.HashedAccountId, query.SearchType, query.SearchTerm); // Assert var view = result as ViewResult; var model = view.Model as UlnSummaryViewModel; model.CurrentHashedAccountId.Should().BeEquivalentTo(query.HashedAccountId); }
public void ShouldFindNothingWhenFilterOnChangesPending(Originator caller) { var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus>(new [] { RecordStatus.ChangesPending, }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(0); }
public void ShouldNotFilterIfNoApprenticeshipStatusSelected(Originator caller) { var query = new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus>() }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(2); }
public void SetUp() { _currentDateTime = new Mock <ICurrentDateTime>(); _currentDateTime.Setup(x => x.Now).Returns(new DateTime(2018, 3, 1)); _data = new List <Apprenticeship>(); _userQuery = new ApprenticeshipSearchQuery(); _sut = new FacetMapper(_currentDateTime.Object); }
public void ShouldFilterRecordStatusOnNothing(Originator caller) { var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus>(new[] { RecordStatus.NoActionNeeded }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(1); }
private async Task <ActionResult> CohortSearch(ApprenticeshipSearchQuery searchQuery) { var cohortSearchResult = await _orchestrator.GetCommitmentSummary(searchQuery); if (cohortSearchResult.HasError) { searchQuery.ReponseMessages = cohortSearchResult.ReponseMessages; return(View("Search", searchQuery)); } return(View("CohortSearchSummary", cohortSearchResult)); }
public void ShouldReturnThePageSize(int requestedPageSize, int expectedPageSize) { var apprenticeships = CreatePaginiationApprenticeships(20); var query = new ApprenticeshipSearchQuery { PageNumber = 1, PageSize = requestedPageSize }; var result = _sut.Filter(apprenticeships, query, Originator.Provider); result.PageSize.Should().Be(expectedPageSize); }
private async Task <ActionResult> UlnSearch(ApprenticeshipSearchQuery searchQuery) { var ulnSearchResult = await _orchestrator.GetApprenticeshipsByUln(searchQuery); if (ulnSearchResult.HasError) { searchQuery.ReponseMessages = ulnSearchResult.ReponseMessages; return(View("Search", searchQuery)); } ulnSearchResult.CurrentHashedAccountId = searchQuery.HashedAccountId; return(View("UlnSearchSummary", ulnSearchResult)); }
public void TestRecordStatuses() { var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus> { RecordStatus.ChangeRequested, RecordStatus.ChangesPending } }; var queryString = _sut.GetQueryString(query); queryString.Should().Be("?RecordStatuses=ChangeRequested&RecordStatuses=ChangesPending&PageNumber=1&PageSize=25"); }
public void TestApprenticeshipStatus() { var query = new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus> { ApprenticeshipStatus.Finished, ApprenticeshipStatus.Paused } }; var queryString = _sut.GetQueryString(query); queryString.Should().Be("?ApprenticeshipStatuses=Finished&ApprenticeshipStatuses=Paused&PageNumber=1&PageSize=25"); }
public void ShouldFilterApprenticeshipStatusSelected(Originator caller) { var query = new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus>( new[] { ApprenticeshipStatus.Live }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(1); result.PageOfResults.Single().FirstName.Should().Be("Live"); }
public virtual Facets BuildFacets(IList <Apprenticeship> apprenticeships, ApprenticeshipSearchQuery apprenticeshipQuery, Originator caller) { var facets = new Facets { ApprenticeshipStatuses = ExtractApprenticeshipStatus(apprenticeships, apprenticeshipQuery), RecordStatuses = ExtractRecordStatus(apprenticeships, caller, apprenticeshipQuery), TrainingProviders = ExtractProviders(apprenticeships, apprenticeshipQuery), EmployerOrganisations = ExtractEmployers(apprenticeships, apprenticeshipQuery), TrainingCourses = ExtractTrainingCourses(apprenticeships, apprenticeshipQuery) }; return(facets); }
public void ShouldFilterRecordStatusOnIlrDataMismatch(Originator caller) { _apprenticeships.Add(new Apprenticeship { FirstName = "ILR Data Mismatch", DataLockPrice = true }); var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus>(new[] { RecordStatus.IlrDataMismatch }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(1); result.PageOfResults.FirstOrDefault().FirstName.Should().Be("ILR Data Mismatch"); }
public async Task <UlnSummaryViewModel> GetApprenticeshipsByUln(ApprenticeshipSearchQuery searchQuery) { _logger.Trace("Retrieving Apprenticeships Record"); var validationResult = _searchValidator.Validate(searchQuery); if (!validationResult.IsValid) { return(new UlnSummaryViewModel { ReponseMessages = validationResult.Errors.Select(o => o.ErrorMessage).ToList() }); } long employerAccountId; try { employerAccountId = _hashingService.DecodeValue(searchQuery.HashedAccountId); } catch (Exception ex) { _logger.Error(ex, "Unable to decode Hashed Employer Account Id"); return(new UlnSummaryViewModel { ReponseMessages = { "Unable to decode the account id" } }); } var response = await _mediator.SendAsync(new GetApprenticeshipsByUlnRequest { Uln = searchQuery.SearchTerm, EmployerAccountId = employerAccountId }); if ((response?.TotalCount ?? 0) == 0) { return(new UlnSummaryViewModel { ReponseMessages = { "No record Found" } }); } _logger.Info($"Apprenticeships Record Count: {response.TotalCount}"); return(_apprenticeshipMapper.MapToUlnResultView(response)); }
public void ShouldHandleAllEmptyLists() { var query = new ApprenticeshipSearchQuery { ApprenticeshipStatuses = new List <ApprenticeshipStatus>(), RecordStatuses = new List <RecordStatus>(), EmployerOrganisationIds = new List <string>(), TrainingCourses = new List <string>(), TrainingProviderIds = null }; var queryString = _sut.GetQueryString(query); queryString.Should().Be("?PageNumber=1&PageSize=25"); }
public void SetUp() { _data = new List <Apprenticeship> { new Apprenticeship { FirstName = "Not started", PaymentStatus = PaymentStatus.Active, StartDate = DateTime.Now.AddDays(-30), DataLockCourse = true } }; _userQuery = new ApprenticeshipSearchQuery(); _sut = new FacetMapper(Mock.Of <ICurrentDateTime>()); }
public void ShouldFilterOnlyOneInstanceOfApprenticeship(Originator caller) { _apprenticeships.Add(new Apprenticeship { FirstName = "ILR Data Mismatch", DataLockCourseTriaged = true, PendingUpdateOriginator = caller }); var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus>(new[] { RecordStatus.ChangeRequested, RecordStatus.IlrDataMismatch, }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(2); result.PageOfResults.Count(m => m.FirstName == "ILR Data Mismatch").Should().Be(1); result.PageOfResults.Count(m => m.FirstName == "WaitingToStart").Should().Be(1); }
public void ShouldFindChangesForReview(Originator caller, Originator otherPart) { _apprenticeships.Add(new Apprenticeship { Id = 009, FirstName = "ChangesForReview", PendingUpdateOriginator = otherPart }); var query = new ApprenticeshipSearchQuery { RecordStatuses = new List <RecordStatus>(new[] { RecordStatus.ChangesForReview, }) }; var result = _sut.Filter(_apprenticeships, query, caller); result.PageOfResults.Count.Should().Be(1); result.PageOfResults.Single().FirstName.Should().Be("ChangesForReview"); }
public async Task CohortFoundShouldReturnCohortCommitmentSummary() { // Arrange const string employerName = "Employer Name"; ApprenticeshipSearchQuery searchQuery = new ApprenticeshipSearchQuery { HashedAccountId = "HASH", SearchTerm = "short", SearchType = ApprenticeshipSearchType.SearchByCohort }; _mediator.Setup(x => x.SendAsync(It.IsAny <GetCommitmentRequest>())) .ReturnsAsync(new GetCommitmentResponse { Data = new Commitment() }); var validationResult = new Mock <ValidationResult>(); validationResult.SetupGet(x => x.IsValid).Returns(true); _searchValidator.Setup(x => x.Validate(searchQuery)) .Returns(validationResult.Object); var _orchestrator = new ApprenticeshipsOrchestrator(_logger.Object, _mediator.Object, _apprenticeshipMapper.Object, _searchValidator.Object, _hashingService.Object, _commitmentMapper.Object); _commitmentMapper.Setup(x => x.MapToCommitmentSummaryViewModel(It.IsAny <Commitment>())).Returns(new CommitmentSummaryViewModel { EmployerName = employerName }); // Act var result = await _orchestrator.GetCommitmentSummary(searchQuery); // Assert result.Should().NotBeNull(); result.Should().BeOfType <CommitmentSummaryViewModel>(); result.ReponseMessages.Should().BeNullOrEmpty(); result.EmployerName.Should().Be(employerName); }
public void ShouldReturnSecondPageOfApprenticeships() { const int RequestedPageNumber = 2; const int RequestedPageSize = 4; var apprenticeships = CreatePaginiationApprenticeships(20); var query = new ApprenticeshipSearchQuery { PageNumber = RequestedPageNumber, PageSize = RequestedPageSize }; var result = _sut.Filter(apprenticeships, query, Originator.Provider); result.PageOfResults.Count.Should().Be(RequestedPageSize); result.PageOfResults.Select(x => x.Id).ShouldAllBeEquivalentTo(new List <int> { 5, 6, 7, 8 }); }
public void ShouldReturnPartialPageForLastPage() { const int RequestedPageNumber = 5; const int RequestedPageSize = 4; var apprenticeships = CreatePaginiationApprenticeships(18); var query = new ApprenticeshipSearchQuery { PageNumber = RequestedPageNumber, PageSize = RequestedPageSize }; var result = _sut.Filter(apprenticeships, query, Originator.Provider); result.PageOfResults.Count.Should().Be(RequestedPageSize - 2); result.PageOfResults.Select(x => x.Id).ShouldAllBeEquivalentTo(new List <int> { 17, 18 }); }
public async Task GivenInvalidHashedAccountIdShouldReturnResponseMessage() { // Arrange ApprenticeshipSearchQuery searchQuery = new ApprenticeshipSearchQuery { HashedAccountId = "HASH", SearchTerm = "short", SearchType = ApprenticeshipSearchType.SearchByCohort }; _mediator.Setup(x => x.SendAsync(It.IsAny <GetCommitmentRequest>())) .ReturnsAsync(new GetCommitmentResponse { Data = new Commitment { } }).Verifiable(); var validationResult = new Mock <ValidationResult>(); validationResult.SetupGet(x => x.IsValid).Returns(true); _searchValidator.Setup(x => x.Validate(searchQuery)) .Returns(validationResult.Object); _hashingService.Setup(x => x.DecodeValue(It.Is <string>(s => s == searchQuery.SearchTerm))).Returns(1234); _hashingService.Setup(x => x.DecodeValue(searchQuery.HashedAccountId)).Throws <Exception>(); var _orchestrator = new ApprenticeshipsOrchestrator(_logger.Object, _mediator.Object, _apprenticeshipMapper.Object, _searchValidator.Object, _hashingService.Object, _commitmentMapper.Object); // Act var result = await _orchestrator.GetCommitmentSummary(searchQuery); // Assert result.Should().NotBeNull(); result.Should().BeOfType <CommitmentSummaryViewModel>(); result.ReponseMessages.Should().NotBeNull(); result.ReponseMessages.Should().Contain("Problem validating your account Id"); }