Exemple #1
0
        public void SearchAssessmentOrganisationsWithValidUkprn()
        {
            const string searchstring = "12345678";
            var          request      = new SearchAssessmentOrganisationsRequest {
                SearchTerm = searchstring
            };

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(searchstring)).Returns(searchstring);
            _searchValidator.Setup(v => v.IsValidEpaOrganisationId(searchstring)).Returns(false);
            _searchValidator.Setup(v => v.IsValidUkprn(searchstring)).Returns(true);
            _registerQueryRepository.Setup(r => r.GetAssessmentOrganisationsByOrganisationId(searchstring))
            .Returns(Task.FromResult(new List <AssessmentOrganisationSummary>().AsEnumerable()));
            _registerQueryRepository.Setup(r => r.GetAssessmentOrganisationsByUkprn(searchstring))
            .Returns(Task.FromResult(_expectedOrganisationListOfDetails.AsEnumerable()));
            var organisations = _searchAssessmentOrganisationsHandler.Handle(request, new CancellationToken()).Result;

            _searchValidator.Verify(v => v.IsValidEpaOrganisationId(searchstring));
            _registerQueryRepository.Verify(r => r.GetAssessmentOrganisationsByOrganisationId(searchstring), Times.Never);
            _searchValidator.Verify(v => v.IsValidUkprn(It.IsAny <string>()));
            _registerQueryRepository.Verify(r => r.GetAssessmentOrganisationsByUkprn(searchstring));

            organisations.Count.Should().Be(2);
            organisations.Should().Contain(_assessmentOrganisationDetails1);
            organisations.Should().Contain(_assessmentOrganisationDetails2);
        }
Exemple #2
0
        public void SearchAssessmentOrganisationsThrowsBadRequestExceptionIfSearchStringTooShort(string search)
        {
            var request = new SearchAssessmentOrganisationsRequest {
                SearchTerm = search
            };

            _cleanserService.Setup(c => c.CleanseStringForSpecialCharacters(search.Trim())).Returns(search.Trim());
            Assert.ThrowsAsync <BadRequestException>(() => _searchAssessmentOrganisationsHandler.Handle(request, new CancellationToken()));
        }
Exemple #3
0
        public async Task <List <AssessmentOrganisationSummary> > Handle(SearchAssessmentOrganisationsRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Handling Search AssessmentOrganisations Request");

            var searchstring = _cleanser.CleanseStringForSpecialCharacters(request.SearchTerm.Trim());

            if (searchstring.Length < 2)
            {
                throw new BadRequestException("The searchstring is too short to do a valid search");
            }

            if (_validator.IsValidEpaOrganisationId(searchstring))
            {
                _logger.LogInformation($@"Searching AssessmentOrganisations based on organisationId: [{searchstring}]");
                var resultFromEpaCode = await _registerQueryRepository.GetAssessmentOrganisationsByOrganisationId(searchstring);

                return(resultFromEpaCode.ToList());
            }

            IEnumerable <AssessmentOrganisationSummary> resultFromUkprn = null;

            if (_validator.IsValidUkprn(searchstring))
            {
                _logger.LogInformation($@"Searching AssessmentOrganisations based on ukprn: [{searchstring}]");
                resultFromUkprn = await _registerQueryRepository.GetAssessmentOrganisationsByUkprn(searchstring);
            }

            _logger.LogInformation($@"Searching AssessmentOrganisations based on name or charity number or company number wildcard: [{searchstring}]");
            var resultMain = await _registerQueryRepository.GetAssessmentOrganisationsByNameOrCharityNumberOrCompanyNumber(searchstring);

            var result = resultMain.ToList();

            if (resultFromUkprn != null)
            {
                result.AddRange(resultFromUkprn);
            }

            return(result.Distinct(new AssessmentOrganisationSummaryEqualityComparer()).Where(x => x.Status != "Applying").ToList());
        }