diff --git a/ProjectLighthouse.Tests/DatabaseFact.cs b/ProjectLighthouse.Tests/DatabaseFact.cs index df9a357c..a62ecd5a 100644 --- a/ProjectLighthouse.Tests/DatabaseFact.cs +++ b/ProjectLighthouse.Tests/DatabaseFact.cs @@ -8,6 +8,7 @@ namespace LBPUnion.ProjectLighthouse.Tests { public DatabaseFact() { + ServerSettings.Instance = new ServerSettings(); ServerSettings.Instance.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse"; if (!ServerStatics.DbConnected) { diff --git a/ProjectLighthouse/Types/Settings/ServerSettings.cs b/ProjectLighthouse/Types/Settings/ServerSettings.cs index ae80e28e..7b9b8c04 100644 --- a/ProjectLighthouse/Types/Settings/ServerSettings.cs +++ b/ProjectLighthouse/Types/Settings/ServerSettings.cs @@ -13,6 +13,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings { static ServerSettings() { + if (ServerStatics.IsUnitTesting) return; // Unit testing, we don't want to read configurations here since the tests will provide their own + if (File.Exists(ConfigFileName)) { string configFile = File.ReadAllText(ConfigFileName); diff --git a/ProjectLighthouse/Types/Settings/ServerStatics.cs b/ProjectLighthouse/Types/Settings/ServerStatics.cs index 24be656f..a6b29548 100644 --- a/ProjectLighthouse/Types/Settings/ServerStatics.cs +++ b/ProjectLighthouse/Types/Settings/ServerStatics.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Linq; using Kettu; using LBPUnion.ProjectLighthouse.Logging; @@ -29,5 +30,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings } } } + + public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit")); } } \ No newline at end of file