public async Task SearchCostUsers_WhenPrefixMatchByLastname_ShouldMatch()
        {
            // Arrange
            var userId    = Guid.NewGuid();
            var firstname = $"Firstname - {userId}";
            var lastname  = $"Lastname - {userId}";

            await AddToIndex(new CostUserSearchItem
            {
                Id        = userId.ToString(),
                Version   = 1,
                FirstName = firstname,
                LastName  = lastname,
                FullName  = $"{firstname} {lastname}"
            }, Constants.ElasticSearchIndices.CostUsersIndexName);

            var query = new CostUserQuery
            {
                SearchText = "Last"
            };

            // Act
            var users = await _userSearchService.SearchCostUsers(query, _userIdentity);

            // Assert
            users.Count.Should().Be(1);
        }
Beispiel #2
0
        public async Task SearchWatchers_return_none()
        {
            const int expected  = 0;
            var       costQuery = new CostUserQuery();
            var       result    = await WatchersController.Search(costQuery);

            var objectResult = result.As <OkObjectResult>();

            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var costUserSearchItems = objectResult.Value as IEnumerable <CostUserSearchItem>;

            costUserSearchItems.Should().NotBeNull();
            costUserSearchItems.Count().Should().Be(expected);
        }
Beispiel #3
0
        public async Task SearchWatchers_return_one()
        {
            const int expected = 1;

            UserSearchServiceMock.Setup(a => a.SearchWatchers(It.IsAny <CostUserQuery>())).ReturnsAsync(new List <CostUserSearchItem> {
                new CostUserSearchItem()
            });
            var costQuery = new CostUserQuery();
            var result    = await WatchersController.Search(costQuery);

            var objectResult = result.As <OkObjectResult>();

            objectResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var costUserSearchItems = objectResult.Value as IEnumerable <CostUserSearchItem>;

            costUserSearchItems.Should().NotBeNull();
            costUserSearchItems.Count().Should().Be(expected);
        }
        public async Task SearchCostUsers_WhenFullNamePrefixPartiallyMatch_ShouldNotMatch()
        {
            // Arrange
            var userId   = Guid.NewGuid();
            var fullName = $"Firstname Lastname - {userId}";

            await AddToIndex(new CostUserSearchItem
            {
                Id       = userId.ToString(),
                Version  = 1,
                FullName = fullName
            }, Constants.ElasticSearchIndices.CostUsersIndexName);

            var query = new CostUserQuery
            {
                SearchText = "Firstname Lastname239487"
            };

            // Act
            var users = await _userSearchService.SearchCostUsers(query, _userIdentity);

            // Assert
            users.Count.Should().Be(0);
        }
        public async Task <List <QueryContainer> > GetQueryContainers(QueryContainerDescriptor <CostUserSearchItem> queryDescriptor, CostUserQuery query, Guid userId)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var costUser = await _efContext.CostUser
                           .Include(u => u.UserBusinessRoles)
                           .ThenInclude(ubr => ubr.BusinessRole)
                           .FirstAsync(u => u.Id == userId);

            var businessRoles = costUser.UserBusinessRoles.Select(ubr => ubr.BusinessRole).Select(br => br.Key).ToHashSet();

            var filterQueries = new List <QueryContainer>();

            if (businessRoles.Contains(Constants.BusinessRole.AgencyAdmin))
            {
                filterQueries.Add(queryDescriptor.Term(t => t.Field(c => c.Agency.Id).Value(costUser.AgencyId.ToString())));
            }
            else if (query.AgencyId != Guid.Empty)
            {
                filterQueries.Add(queryDescriptor.Term(t => t.Field(c => c.Agency.Id).Value(query.AgencyId)));
            }

            if (businessRoles.Contains(Constants.BusinessRole.GovernanceManager))
            {
                filterQueries.Add(queryDescriptor.Term(t => t.Field(c => c.IsCostModuleOwner).Value(true)));
            }

            return(filterQueries);
        }