Split creators out of identity
This commit is contained in:
@@ -14,7 +14,7 @@ public partial class Testing
|
||||
private static ITestDatabase _database;
|
||||
private static CustomWebApplicationFactory _factory = null!;
|
||||
private static IServiceScopeFactory _scopeFactory = null!;
|
||||
private static string? _userId;
|
||||
private static Guid _userId;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task RunBeforeAnyTests()
|
||||
@@ -44,32 +44,36 @@ public partial class Testing
|
||||
await mediator.Send(request);
|
||||
}
|
||||
|
||||
public static string? GetUserId()
|
||||
public static Guid GetUserId()
|
||||
{
|
||||
return _userId;
|
||||
}
|
||||
|
||||
public static async Task<string> RunAsDefaultUserAsync()
|
||||
public static async Task<Guid> RunAsDefaultUserAsync()
|
||||
{
|
||||
return await RunAsUserAsync("test@local", "Testing1234!", Array.Empty<string>());
|
||||
return await RunAsUserAsync(
|
||||
"test@local",
|
||||
"Testing1234!",
|
||||
[]);
|
||||
}
|
||||
|
||||
public static async Task<string> RunAsAdministratorAsync()
|
||||
public static async Task<Guid> RunAsAdministratorAsync()
|
||||
{
|
||||
return await RunAsUserAsync("administrator@local", "Administrator1234!", new[] { Roles.Administrator });
|
||||
return await RunAsUserAsync(
|
||||
"administrator@local",
|
||||
"Administrator1234!",
|
||||
[Roles.Administrator]);
|
||||
}
|
||||
|
||||
public static async Task<string> RunAsUserAsync(string userName, string password, string[] roles)
|
||||
public static async Task<Guid> RunAsUserAsync(string userName, string password, string[] roles)
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
|
||||
var userManager = scope.ServiceProvider.GetRequiredService<ApplicationUserManager>();
|
||||
|
||||
var user = new ApplicationUser {
|
||||
UserName = userName,
|
||||
Email = userName,
|
||||
FirstName = "FirstName",
|
||||
LastName = "LastName"
|
||||
var user = new ApplicationUser
|
||||
{
|
||||
UserName = userName, Email = userName, FirstName = "FirstName", LastName = "LastName"
|
||||
};
|
||||
|
||||
var result = await userManager.CreateAsync(user, password);
|
||||
@@ -104,11 +108,11 @@ public partial class Testing
|
||||
{
|
||||
await _database.ResetAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
_userId = null;
|
||||
_userId = Guid.Empty;
|
||||
}
|
||||
|
||||
public static async Task<TEntity?> FindAsync<TEntity>(params object[] keyValues)
|
||||
|
||||
Reference in New Issue
Block a user