shoc-backend/Api.SeaHavenIndustries.Tests/IdentityTestHelpers.cs
2026-07-24 11:24:09 -03:00

42 lines
1.4 KiB
C#

using Data.SeaHavenIndustries;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
namespace Api.SeaHavenIndustries.Tests;
internal static class IdentityTestHelpers
{
public static (UserManager<ApplicationUser> manager, Mock<IUserRoleStore<ApplicationUser>> store, Mock<IPasswordHasher<ApplicationUser>> hasher) CreateUserManager()
{
var store = new Mock<IUserRoleStore<ApplicationUser>>();
var hasher = new Mock<IPasswordHasher<ApplicationUser>>();
store.As<IUserPasswordStore<ApplicationUser>>();
var manager = new UserManager<ApplicationUser>(
store.Object,
Options.Create(new IdentityOptions()),
hasher.Object,
new List<IUserValidator<ApplicationUser>>(),
new List<IPasswordValidator<ApplicationUser>>(),
new Mock<ILookupNormalizer>().Object,
new IdentityErrorDescriber(),
new Mock<IServiceProvider>().Object,
new Mock<ILogger<UserManager<ApplicationUser>>>().Object);
return (manager, store, hasher);
}
public static ApplicationUser User(string id = "u1", string? userName = "alice", bool? isDeleted = false) => new()
{
Id = id,
UserName = userName,
Email = userName + "@example.com",
FirstName = "Alice",
LastName = "Q",
PhoneNumber = "555",
IsDeleted = isDeleted
};
}