Skip to content

Commit

Permalink
test: test get-users in identity service
Browse files Browse the repository at this point in the history
  • Loading branch information
mobinbr committed Aug 20, 2024
1 parent 845907f commit 6c282e0
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,43 @@ public async Task ChangeRole_WhenOperationSucceeds_ReturnsSuccessResult()
// Assert
Assert.True(result.Succeed);
}

// GetUsers Tests
[Fact]
public async Task GetUsersAsync_ReturnsUserListWithRoles()
{
// Arrange
var users = new List<AppUser>
{
new AppUser { UserName = "User1", Email = "[email protected]" },
new AppUser { UserName = "User2", Email = "[email protected]" }
};

var roles = new List<string> { "Admin", "User" };

var userResponses = new List<GetUserResponse>
{
new GetUserResponse { UserName = "User1", Email = "[email protected]", Role = "Admin" },
new GetUserResponse { UserName = "User2", Email = "[email protected]", Role = "User" }
};

// Mock the repository methods
_userManagerRepository.GetUsersAsync()
.Returns(Task.FromResult(users));

_userManagerRepository.GetRoleAsync(users[0])
.Returns(Task.FromResult(roles[0]));

_userManagerRepository.GetRoleAsync(users[1])
.Returns(Task.FromResult(roles[1]));

// Act
var result = await _identityService.GetUsersAsync();

// Assert
Assert.NotNull(result);
Assert.Equal(2, result.Count);
Assert.Contains(result, r => r.UserName == "User1" && r.Role == "Admin");
Assert.Contains(result, r => r.UserName == "User2" && r.Role == "User");
}
}

0 comments on commit 6c282e0

Please sign in to comment.