-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test get-users in identity service
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
} | ||
} |