Refactor Database class (#616)

Refactor Database into DatabaseContext
Moved into separate folder so it actually has a namespace instead sitting in the root
This commit is contained in:
Josh 2023-02-15 23:54:30 -06:00 committed by GitHub
commit 64b95e807d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
246 changed files with 1211 additions and 965 deletions

View file

@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Tests;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -18,7 +18,7 @@ public class AdminTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldShowAdminPanelButtonWhenAdmin()
{
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash("i'm an engineering failure"));
@ -44,7 +44,7 @@ public class AdminTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldNotShowAdminPanelButtonWhenNotAdmin()
{
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash("i'm an engineering failure"));

View file

@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Tests;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -17,7 +17,7 @@ public class AuthenticationTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldLoginWithPassword()
{
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
@ -39,7 +39,7 @@ public class AuthenticationTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldNotLoginWithNoPassword()
{
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash("just like the hindenberg,"));
@ -58,7 +58,7 @@ public class AuthenticationTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldNotLoginWithWrongPassword()
{
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash("i'm an engineering failure"));
@ -80,7 +80,7 @@ public class AuthenticationTests : LighthouseWebTest
{
const string loggedInAsUsernameTextXPath = "/html/body/div/div/div/div/p[1]";
await using Database database = new();
await using DatabaseContext database = new();
Random random = new();
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash("i'm an engineering failure"));

View file

@ -1,7 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Tests;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -16,7 +16,7 @@ public class RegisterTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldRegister()
{
await using Database database = new();
await using DatabaseContext database = new();
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
@ -41,7 +41,7 @@ public class RegisterTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldNotRegisterWithMismatchingPasswords()
{
await using Database database = new();
await using DatabaseContext database = new();
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
@ -64,7 +64,7 @@ public class RegisterTests : LighthouseWebTest
[DatabaseFact]
public async Task ShouldNotRegisterWithTakenUsername()
{
await using Database database = new();
await using DatabaseContext database = new();
string username = ("unitTestUser" + new Random().Next())[..16];
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());