public async Task HandleAsync_Should_Return_CollectionOutputQuery_With_UserOutputQuery_When_InputQuery_Is_Not_Null() { var inputQuery = new GetUsersInputQuery(1, 1, "email", "*****@*****.**", true); var user = User.Builder() .SetId(Guid.NewGuid()) .SetEmail("*****@*****.**") .SetServiceActive(DefaultUserSettings.ServiceActive) .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit) .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency) .Build(); var users = new List <User> { user }; var userOutputQueries = users.Select(x => new UserOutputQuery(user.Id, user.Email, user.Picture, user.ServiceActive, user.AnnouncementPreferenceLimit, user.AnnouncementSendingFrequency, new List <RoomForRentAnnouncementPreferenceOutputQuery>(), new List <FlatForRentAnnouncementPreferenceOutputQuery>())).ToList(); var expectedResult = new CollectionOutputQuery <UserOutputQuery>(userOutputQueries.Count(), userOutputQueries); _userRepositoryMock.Setup(x => x.FindAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())).ReturnsAsync(users); _userRepositoryMock.Setup(x => x.CountAsync(It.IsAny <string>(), It.IsAny <bool>())) .ReturnsAsync(users.Count); _mapperMock.Setup(x => x.Map <List <User>, IEnumerable <UserOutputQuery> >(It.IsAny <List <User> >())) .Returns(userOutputQueries); var result = await _queryHandler.HandleAsync(inputQuery); result.Should().BeEquivalentTo(expectedResult); }
public async Task <CollectionOutputQuery <UserOutputQuery> > HandleAsync(GetUsersInputQuery inputQuery, CancellationToken cancellationToken = default) { List <User> users; long totalCount; if (inputQuery != null) { users = await _userRepository.FindAsync(inputQuery.Page, inputQuery.PageSize, inputQuery.Sort, inputQuery.Email, inputQuery.ServiceActive); totalCount = await _userRepository.CountAsync(inputQuery.Email, inputQuery.ServiceActive); } else { users = await _userRepository.GetAllAsync(); totalCount = await _userRepository.CountAsync(); } var results = _mapper.Map <List <User>, IEnumerable <UserOutputQuery> >(users); return(new CollectionOutputQuery <UserOutputQuery>(totalCount, results)); }