public async Task Handle_ReturnsOnlyUser2() { // Arrange var expectedRole = UserRoles.MedicalExaminerOfficer; var expectedLocations = new[] { "location1", "location2", "location3" }; var query = new UsersRetrievalByRoleLocationQuery(expectedLocations, expectedRole); // Act var results = (await Service.Handle(query)).ToList(); // Assert results.Should().NotBeNull(); results.Count.Should().Be(1); results.ElementAt(0).UserId.Should().Be("user2"); }
/// <inheritdoc/> public override Task <IEnumerable <MeUser> > Handle(UsersRetrievalByRoleLocationQuery param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } Expression <Func <MeUser, bool> > predicate; if (param.Roles != null) { predicate = mu => mu.Permissions.Any(p => param.Roles.Contains(p.UserRole) && param.Locations.Contains(p.LocationId)); } else { predicate = mu => mu.Permissions.Any(p => param.Locations.Contains(p.LocationId)); } return(GetItemsAsync(predicate)); }