Example #1
0
        public void Given_request_When_Search_Then_returns_correct_results()
        {
            // Given
            var target = GetTarget();
            var request = new SearchRiskAssessorRequest
                          {
                              SearchTerm = "search term",
                              CompanyId = 17L,
                              SiteId = 888L,
                              MaximumResults = 10
                          };

            // When
            var result = target.Search(request);

            // Then
            Assert.That(result.Count(), Is.EqualTo(_riskAssessors.Count()));
            _riskAssessorRepository.Verify(x => x.Search(
                It.Is<string>(y => y == request.SearchTerm),
                It.IsAny<long[]>(),
                It.Is<long>(y => y == request.CompanyId),
                It.Is<int>(y => y == request.MaximumResults),
                It.Is<bool>(y => y == request.IncludeDeleted),
                It.Is<bool>(y => y == request.ExcludeActive),
                false
            ));
        }
        public IEnumerable<RiskAssessorDto> Search(SearchRiskAssessorRequest request)
        {
            var parentSitesIds = new long[]{};
            if (request.SiteId > 0)
            {
                var site = _siteStructureElementRepository.GetByIdAndCompanyId(request.SiteId, request.CompanyId);
                parentSitesIds = site.GetThisAndAllAncestors().Select(x => x.Id).ToArray();
            }

            var riskAssessors = _riskAssessorRepository.Search(
                request.SearchTerm,
                parentSitesIds,
                request.CompanyId,
                request.MaximumResults,
                request.IncludeDeleted,
                request.ExcludeActive,
                false
            );

            return new RiskAssessorDtoMapper().MapWithEmployeeAndSite(riskAssessors);
        }