Fix unit test failures

This commit is contained in:
jvyden 2022-07-26 19:20:57 -04:00
commit 2dcf8dd390
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 6 additions and 3 deletions

View file

@ -1,6 +1,7 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Localization; using LBPUnion.ProjectLighthouse.Localization;
using LBPUnion.ProjectLighthouse.Localization.StringLists; using LBPUnion.ProjectLighthouse.Localization.StringLists;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles; using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
@ -47,6 +48,8 @@ public class BaseLayout : PageModel
private string getLanguage() private string getLanguage()
{ {
if (ServerStatics.IsUnitTesting) return "en-US";
IRequestCultureFeature? requestCulture = Request.HttpContext.Features.Get<IRequestCultureFeature>(); IRequestCultureFeature? requestCulture = Request.HttpContext.Features.Get<IRequestCultureFeature>();
if (requestCulture == null) return LocalizationManager.DefaultLang; if (requestCulture == null) return LocalizationManager.DefaultLang;

View file

@ -78,7 +78,7 @@ public class AuthenticationTests : LighthouseWebTest
[DatabaseFact] [DatabaseFact]
public async Task ShouldLoginWithInjectedCookie() public async Task ShouldLoginWithInjectedCookie()
{ {
const string loggedInAsUsernameTextXPath = "/html/body/div/div/div/p[1]/b"; const string loggedInAsUsernameTextXPath = "/html/body/div/div/div/p[1]";
await using Database database = new(); await using Database database = new();
Random random = new(); Random random = new();
@ -96,10 +96,10 @@ public class AuthenticationTests : LighthouseWebTest
INavigation navigation = this.Driver.Navigate(); INavigation navigation = this.Driver.Navigate();
navigation.GoToUrl(this.BaseAddress + "/"); navigation.GoToUrl(this.BaseAddress + "/");
Assert.DoesNotContain(user.Username, this.Driver.FindElement(By.XPath(loggedInAsUsernameTextXPath)).Text);
this.Driver.Manage().Cookies.AddCookie(new Cookie("LighthouseToken", webToken.UserToken)); this.Driver.Manage().Cookies.AddCookie(new Cookie("LighthouseToken", webToken.UserToken));
Assert.Throws<NoSuchElementException>(() => this.Driver.FindElement(By.XPath(loggedInAsUsernameTextXPath)));
navigation.Refresh(); navigation.Refresh();
Assert.True(this.Driver.FindElement(By.XPath(loggedInAsUsernameTextXPath)).Text == user.Username); Assert.Contains(user.Username, this.Driver.FindElement(By.XPath(loggedInAsUsernameTextXPath)).Text);
await database.RemoveUser(user); await database.RemoveUser(user);
} }