24 lines
1.0 KiB
C#
24 lines
1.0 KiB
C#
using JobTrackerApi.Models;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
|
|
namespace JobTrackerApi.MariaDb.Tests;
|
|
|
|
internal static class TestHostFactory
|
|
{
|
|
public static Mock<UserManager<ApplicationUser>> CreateUserManager(ApplicationUser? lookupUser = null)
|
|
{
|
|
var manager = new Mock<UserManager<ApplicationUser>>(
|
|
Mock.Of<IUserStore<ApplicationUser>>(), Options.Create(new IdentityOptions()),
|
|
new PasswordHasher<ApplicationUser>(), Array.Empty<IUserValidator<ApplicationUser>>(),
|
|
Array.Empty<IPasswordValidator<ApplicationUser>>(), new UpperInvariantLookupNormalizer(),
|
|
new IdentityErrorDescriber(), null!, NullLogger<UserManager<ApplicationUser>>.Instance);
|
|
if (lookupUser is not null)
|
|
manager.Setup(x => x.FindByIdAsync(It.IsAny<string>()))
|
|
.ReturnsAsync((string id) => lookupUser.Id == id ? lookupUser : null);
|
|
return manager;
|
|
}
|
|
}
|