public async Task OrderQueryableAsync_ReturnsDisplayNameMatchingRegionalUsers()
        {
            // Arrange
            var searchStrings  = SearchStringHelper.GetSearchKeywords("Leslie");
            var expectedResult = CreateRegionalUser("RegionalAdGroup", "Leslie Knope");
            var regionalUsers  = new List <User>
            {
                CreateRegionalUser("RegionalAdGroup", "Ben Wyatt"), expectedResult
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs())
            .ReturnsAsync(new List <PHEC> {
                new PHEC {
                    AdGroup = "RegionalAdGroup", Name = "Pawnee"
                }
            });
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(regionalUsers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Equal(1, results.Count);
            Assert.Equal(expectedResult, results[0]);
        }
예제 #2
0
        public void ApplyFreeTextSearchTags()
        {
            var text = _searchQuery.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var textTermClause = new MandatoryTagClause();

            foreach (var term in FilterTerms(SearchStringHelper.ExtractTerms(text)))
            {
                var textClause = new OptionalTagClause();

                textClause.Tags.Add(new Tag(Foundation.Search.Constants.TagNames.Body, term)
                {
                    AllowFuzzy = true
                });
                textClause.Tags.Add(new Tag(Foundation.Search.Constants.TagNames.Body, term + "*"));
                textClause.Tags.Add(new Tag(Foundation.Search.Constants.TagNames.Body, "*" + term));
                textClause.Tags.Add(new Tag(Foundation.Search.Constants.TagNames.Body, term));

                if (textClause.TagsExist)
                {
                    textTermClause.Tags.Add(textClause);
                }
            }

            if (textTermClause.TagsExist)
            {
                _request.QueryTags.Add(textTermClause);
            }
        }
        public async Task SearchWithTwoKeywords_ReturnsUsersContainingBothInEitherName()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("Test User");
            var caseManagers  = new List <User>
            {
                CreateDefaultCaseManager(givenName: "Test", familyName: "User"),
                CreateDefaultCaseManager(givenName: "Tester", familyName: "User"),
                CreateDefaultCaseManager(givenName: "Test", familyName: "Userer"),
                CreateDefaultCaseManager(givenName: "Test", familyName: "Bob"),
                CreateDefaultCaseManager(givenName: "Bob", familyName: "User"),
                CreateDefaultCaseManager(givenName: "Foo", familyName: "Bar")
            };
            var expectedResults = new List <User> {
                caseManagers[0], caseManagers[1], caseManagers[2]
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(caseManagers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Equal(expectedResults, results);
        }
        [Fact] public async Task OrderQueryableAsync_DoesNotReturnRegionMatchingCaseManagersAndUsers()
        {
            // Arrange
            var    searchStrings         = SearchStringHelper.GetSearchKeywords("Region1");
            string regionAdGroup         = DefaultRegionalUsers[0].AdGroups;
            var    caseManagerWithRegion = CreateDefaultCaseManager("Thomas Haverford");

            caseManagerWithRegion.AdGroups = regionAdGroup;
            var usersToReturn = DefaultRegionalUsers;

            usersToReturn.Add(caseManagerWithRegion);

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs())
            .ReturnsAsync(new List <PHEC> {
                new PHEC {
                    AdGroup = regionAdGroup, Name = searchStrings[0]
                }
            });
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(usersToReturn);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public void CorrectlyHandles_EmptyString()
        {
            //Arrange
            const string searchKeyword = "";

            //Act
            var searchKeywords = SearchStringHelper.GetSearchKeywords(searchKeyword);

            //Assert
            Assert.Empty(searchKeywords);
        }
        public void CorrectlySanitises_EmptySpaces()
        {
            //Arrange
            const string searchKeyword = " test   ";

            //Act
            var searchKeywords = SearchStringHelper.GetSearchKeywords(searchKeyword);

            //Assert
            Assert.Single(searchKeywords);
            Assert.Equal("test", searchKeywords[0]);
        }
        public void MakesSearchKeywords_LowerCase()
        {
            //Arrange
            const string searchKeyword = "AbcDEF GHiJ";

            //Act
            var searchKeywords = SearchStringHelper.GetSearchKeywords(searchKeyword);

            //Assert
            Assert.Equal(2, searchKeywords.Count);
            Assert.Equal("abcdef", searchKeywords[0]);
            Assert.Equal("ghij", searchKeywords[1]);
        }
        public async Task OrderQueryableAsync_ReturnsEmptyList()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("");

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(new List <User>());

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public void CorrectlySplits_SearchKeywordWithSpaces()
        {
            //Arrange
            const string searchKeyword = "abc def g";

            //Act
            var searchKeywords = SearchStringHelper.GetSearchKeywords(searchKeyword);

            //Assert
            Assert.Equal(3, searchKeywords.Count);
            Assert.Equal("abc", searchKeywords[0]);
            Assert.Equal("def", searchKeywords[1]);
            Assert.Equal("g", searchKeywords[2]);
        }
        public async Task OrderQueryableAsync_ReturnsEmptyListWhenThereAreNoGivenNameMatches()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("abcdefg");

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(DefaultGivenNameCaseManagers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public async Task OrderQueryableAsync_ReturnsFamilyNameMatchingUsers()
        {
            // Arrange
            var searchStrings   = SearchStringHelper.GetSearchKeywords("UserT");
            var expectedResults = new List <User> {
                DefaultFamilyNameCaseManagers[1], DefaultFamilyNameCaseManagers[2]
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(DefaultFamilyNameCaseManagers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Equal(2, results.Count);
            Assert.Equal(expectedResults, results);
        }
        public async Task OrderQueryableAsync_DoesNotFindNonCaseManagerOrRegionalUsers()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("Frank");

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(new List <User>
            {
                new User {
                    DisplayName = "Frank Ma"
                },
                CreateDefaultCaseManager("Rufus Hound", "Rufus", "Hound", new List <CaseManagerTbService>())
            });

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public async Task SearchWithTwoKeywords_DoesNotReturnRegionalUsersWhereBothKeywordsInRegion()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("North West");
            var southWest     = new PHEC {
                Code = "P1", Name = "South West", AdGroup = "SW"
            };
            var northWest = new PHEC {
                Code = "P2", Name = "North West", AdGroup = "NW"
            };
            var burnley = new TBService {
                Code = "TB2", Name = "Burnley", PHEC = northWest, PHECCode = northWest.Code
            };
            var caseManagers = new List <User>
            {
                CreateDefaultCaseManager(
                    displayName: "Bar Foo",
                    caseManagerTbServices: new List <CaseManagerTbService>
                {
                    new CaseManagerTbService {
                        TbService = burnley, TbServiceCode = burnley.Code
                    }
                }),
                CreateRegionalUser(northWest.AdGroup, "Foo Bar"),
                CreateRegionalUser(southWest.AdGroup, "Boo Far")
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs())
            .ReturnsAsync(new List <PHEC> {
                southWest, northWest
            });
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(caseManagers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public async Task SearchWithTwoKeywords_DoesNotReturnUsersContainingBothInTbService()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("South West");
            var southWest     = new TBService {
                Code = "TB1", Name = "South West service"
            };
            var northWest = new TBService {
                Code = "TB2", Name = "North West service"
            };
            var caseManagers = new List <User>
            {
                CreateDefaultCaseManager(
                    displayName: "Foo Bar",
                    caseManagerTbServices: new List <CaseManagerTbService>
                {
                    new CaseManagerTbService {
                        TbService = southWest, TbServiceCode = southWest.Code
                    }
                }),
                CreateDefaultCaseManager(
                    displayName: "Bar Foo",
                    caseManagerTbServices: new List <CaseManagerTbService>
                {
                    new CaseManagerTbService {
                        TbService = northWest, TbServiceCode = northWest.Code
                    }
                })
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(caseManagers);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
        public async Task OrderQueryableAsync_DoesNotReturnInactiveFamilyNameMatchingUsers()
        {
            // Arrange
            var searchStrings       = SearchStringHelper.GetSearchKeywords("Glasper");
            var activeCaseManager   = CreateDefaultCaseManager(givenName: "Robert", familyName: "Glasper");
            var inactiveCaseManager = CreateDefaultCaseManager(givenName: "Robin", familyName: "Glasper");

            inactiveCaseManager.IsActive = false;
            var usersToReturn = new List <User> {
                activeCaseManager, inactiveCaseManager
            };

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs()).ReturnsAsync(new List <PHEC>());
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(usersToReturn);

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Equal(1, results.Count);
            Assert.Equal(activeCaseManager, results.Single());
        }
        public async Task OrderQueryableAsync_DoesNotReturnInactiveDisplayNameMatchingRegionalUsers()
        {
            // Arrange
            var searchStrings = SearchStringHelper.GetSearchKeywords("Leslie");
            var regionalUser  = CreateRegionalUser("RegionalAdGroup", "Leslie Knope");

            regionalUser.IsActive = false;

            _mockReferenceDataRepository.Setup(r => r.GetAllPhecs())
            .ReturnsAsync(new List <PHEC> {
                new PHEC {
                    AdGroup = "RegionalAdGroup", Name = "Pawnee"
                }
            });
            _mockUserRepository.Setup(u => u.GetOrderedUsers()).ReturnsAsync(new List <User> {
                regionalUser
            });

            // Act
            var results = await _service.OrderQueryableAsync(searchStrings);

            // Assert
            Assert.Empty(results);
        }
예제 #17
0
        public async Task <IActionResult> OnGetAsync(int?pageIndex = null, int?offset = null)
        {
            if (!ModelState.IsValid || SearchKeyword.IsNullOrEmpty())
            {
                return(Page());
            }

            _paginationParameters = new PaginationParametersBase
            {
                PageSize  = 20,
                PageIndex = pageIndex ?? 1,
                Offset    = offset ?? 0
            };

            var searchKeywords = SearchStringHelper.GetSearchKeywords(SearchKeyword);

            var usersToDisplay = await _userSearchService.OrderQueryableAsync(searchKeywords);

            var regionsToDisplay = await _referenceDataRepository.GetPhecsBySearchKeywords(searchKeywords);

            var tbServicesToDisplay = await _referenceDataRepository.GetActiveTBServicesBySearchKeywords(searchKeywords);

            var hospitalsToDisplay = await _referenceDataRepository.GetActiveHospitalsBySearchKeywords(searchKeywords);

            var(paginatedResults, count) =
                _serviceDirectoryService.GetPaginatedItems(
                    regionsToDisplay,
                    usersToDisplay,
                    tbServicesToDisplay,
                    hospitalsToDisplay,
                    _paginationParameters);

            DirectorySearchResults = new PaginatedList <ServiceDirectoryItemWrapper>(paginatedResults, count, _paginationParameters);

            AllPhecs = await _referenceDataRepository.GetAllPhecs();

            if (DirectorySearchResults.HasNextPage)
            {
                NextPageUrl = QueryHelpers.AddQueryString("/ServiceDirectory/SearchResults",
                                                          new Dictionary <string, string>
                {
                    { "SearchKeyword", SearchKeyword },
                    { "pageIndex", (_paginationParameters.PageIndex + 1).ToString() },
                    { "offset", (_paginationParameters.Offset + paginatedResults.Count).ToString() }
                });
            }

            if (DirectorySearchResults.HasPreviousPage)
            {
                PreviousPageUrl = QueryHelpers.AddQueryString("/ServiceDirectory/SearchResults",
                                                              new Dictionary <string, string>
                {
                    { "SearchKeyword", SearchKeyword },
                    { "pageIndex", (_paginationParameters.PageIndex - 1).ToString() },
                    { "offset", (_paginationParameters.Offset - _paginationParameters.PageSize).ToString() }
                });
            }

            PrepareBreadcrumbs();

            return(Page());
        }