public async Task <IEnumerable <UserDto> > HandleAsync(GetUsersByIds query) { var documents = _repository.Collection.AsQueryable(); var users = await documents.Where(u => query.UserIds.Contains(u.Id)).ToListAsync(); return(users.Select(p => p.AsDto())); }
public async Task get_users_by_ids_query_should_return_empty_when_no_users_exist() { var id = Guid.NewGuid(); var query = new GetUsersByIds(new Guid[] { id }); // Check if exception is thrown var requestResult = _queryHandler .Awaiting(c => c.HandleAsync(query)); requestResult.Should().NotThrow(); var result = await requestResult(); result.Should().BeEmpty(); }
public async Task get_users_by_ids_query_can_filter_based_on_ids_when_a_user_exists() { var id = Guid.NewGuid(); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var email = "*****@*****.**"; var email1 = "*****@*****.**"; var email2 = "*****@*****.**"; var fullname = "fullname"; var filterFullname = "filter"; var password = "******"; var pic = "test.nl/image"; var role = Role.User; var securityStamp = new Guid().ToString(); // Add users var user = new User(id, email, fullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); var user1 = new User(id1, email1, filterFullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); var user2 = new User(id2, email2, filterFullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); await _mongoDbFixture.InsertAsync(user.AsDocument()); await _mongoDbFixture.InsertAsync(user1.AsDocument()); await _mongoDbFixture.InsertAsync(user2.AsDocument()); var query = new GetUsersByIds(new Guid[] { user.Id, user2.Id }); // Check if exception is thrown var requestResult = _queryHandler .Awaiting(c => c.HandleAsync(query)); requestResult.Should().NotThrow(); var result = await requestResult(); var userDtos = result as UserDto[] ?? result.ToArray(); userDtos.Should().Contain(c => c.Id == user.Id); userDtos.Should().Contain(c => c.Id == user2.Id); }
public async Task get_users_by_ids_query_should_return_empty_when_no_users_with_specified_ids_exist() { var id = Guid.NewGuid(); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var email = "*****@*****.**"; var email1 = "*****@*****.**"; var email2 = "*****@*****.**"; var fullname = "fullname"; var filterFullname = "filter"; var password = "******"; var pic = "test.nl/image"; var role = Role.User; var securityStamp = new Guid().ToString(); // Add users var user = new User(id, email, fullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); var user1 = new User(id1, email1, filterFullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); var user2 = new User(id2, email2, filterFullname, pic, password, role, securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { }); await _mongoDbFixture.InsertAsync(user.AsDocument()); await _mongoDbFixture.InsertAsync(user1.AsDocument()); await _mongoDbFixture.InsertAsync(user2.AsDocument()); var query = new GetUsersByIds(new Guid[] { Guid.NewGuid() }); // Check if exception is thrown var requestResult = _queryHandler .Awaiting(c => c.HandleAsync(query)); requestResult.Should().NotThrow(); var result = await requestResult(); result.Should().BeEmpty(); }