LANCommander/LANCommander.Server.Tests/Services/UserServiceTests.cs

37 lines
1.4 KiB
C#
Raw Permalink Normal View History

2025-03-15 23:13:31 -05:00
using LANCommander.Server.Services;
using Shouldly;
namespace LANCommander.Server.Tests.Services;
[Collection("Application")]
public class UserServiceTests(ApplicationFixture fixture) : BaseTest(fixture)
{
[Fact]
public async Task CreateAdminUserShouldWork()
{
var user = await EnsureAdminUserCreatedAsync();
2025-03-15 23:13:31 -05:00
user.UserName.ShouldBe(TestConstants.AdminUserName);
user.NormalizedUserName.ShouldBe(TestConstants.AdminUserName.ToUpper());
2025-03-15 23:13:31 -05:00
user.Roles.ShouldContain(r => r.Name == RoleService.AdministratorRoleName);
}
[Fact]
public async Task ChangePasswordShouldWork()
{
var user = await EnsureAdminUserCreatedAsync();
var userService = GetService<UserService>();
var result = await userService.ChangePassword(TestConstants.AdminUserName, TestConstants.AdminInitialPassword, TestConstants.AdminPassword);
2026-06-28 14:09:34 -05:00
result.Succeeded.ShouldBeTrue();
2026-06-28 14:09:34 -05:00
var validPassword = await userService.CheckPassword(TestConstants.AdminUserName, TestConstants.AdminPassword);
2026-06-28 14:09:34 -05:00
validPassword.ShouldBeTrue();
2026-06-28 14:09:34 -05:00
// The admin account is shared across the in-memory test database, so restore the original
// password to avoid breaking other tests that authenticate with AdminInitialPassword.
await userService.ChangePassword(TestConstants.AdminUserName, TestConstants.AdminPassword, TestConstants.AdminInitialPassword);
}
2025-03-15 23:13:31 -05:00
}