mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
43 lines
1.5 KiB
C#
43 lines
1.5 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,
|
||
|
|
Microsoft.Extensions.Options.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
|
||
|
|
};
|
||
|
|
}
|