re testing
This commit is contained in:
@ -33,7 +33,6 @@ namespace isnd.tests
|
||||
|
||||
public IDataProtector DataProtector { get; private set; }
|
||||
|
||||
public ApplicationDbContext dbContext { get; private set; }
|
||||
|
||||
public string TestingUserName { get; private set; }
|
||||
public string ProtectedTestingApiKey { get; internal set; }
|
||||
@ -80,15 +79,18 @@ namespace isnd.tests
|
||||
|
||||
DataProtector = Host.Services.GetRequiredService<IDataProtectionProvider>()
|
||||
.CreateProtector(siteSettings.ProtectionTitle);
|
||||
using IServiceScope scope = Host.Services.CreateScope();
|
||||
ApplicationDbContext dbContext =
|
||||
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
|
||||
dbContext = Host.Services.GetRequiredService<ApplicationDbContext>();
|
||||
|
||||
TestingUserName = "Tester";
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
|
||||
EnsureUser(TestingUserName);
|
||||
var testKey = dbContext.ApiKeys.FirstOrDefault(k => k.UserId == TestingUser.Id);
|
||||
if (testKey == null)
|
||||
{
|
||||
var keyProvider = Host.Services.GetService<IApiKeyProvider>();
|
||||
var keyProvider = scope.ServiceProvider.GetService<IApiKeyProvider>();
|
||||
var apiKeyQuery = new Data.ApiKeys.CreateModel
|
||||
{
|
||||
Name = "Testing Key",
|
||||
@ -111,7 +113,12 @@ namespace isnd.tests
|
||||
{
|
||||
if (TestingUser == null)
|
||||
{
|
||||
var userManager = Host.Services.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
using IServiceScope scope = Host.Services.CreateScope();
|
||||
|
||||
var userManager =
|
||||
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
|
||||
|
||||
TestingUser = new ApplicationUser
|
||||
{
|
||||
UserName = testingUserName
|
||||
@ -120,6 +127,9 @@ namespace isnd.tests
|
||||
var result = userManager.CreateAsync(TestingUser).Result;
|
||||
|
||||
Assert.True(result.Succeeded);
|
||||
|
||||
ApplicationDbContext dbContext =
|
||||
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == testingUserName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user