-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
Configuration.cs
(#362)
- Replace `GeneralSettings.DisableLogging` with `GeneralSettings.EnableLogging` and set it to `false` in `Configuration.cs` - Map it manually on startup to avoid dotnet/runtime#89732 This should avoid the issue of the binary crashing without `appsettings.json`. **This doesn't mean it should be used without it**, it will swallow all errors and arnings, but yeah, you can. - Add test to ensure that `appsettings.json` are `Configuration.cs` are sync'ed - Adjust `appsettings` values to Config ones
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using NUnit.Framework; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Lynx.Test; | ||
|
||
[Explicit] | ||
[Category(Categories.Configuration)] | ||
[NonParallelizable] | ||
public class ConfigurationTest | ||
{ | ||
[Test] | ||
public void SynchronizedAppSettings() | ||
{ | ||
var config = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) | ||
.Build(); | ||
|
||
var engineSettingsSection = config.GetRequiredSection(nameof(EngineSettings)); | ||
Assert.IsNotNull(engineSettingsSection); | ||
|
||
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code | ||
var serializedEngineSettingsConfig = JsonSerializer.Serialize(Configuration.EngineSettings); | ||
var jsonNode = JsonSerializer.Deserialize<JsonNode>(serializedEngineSettingsConfig); | ||
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code | ||
Assert.IsNotNull(jsonNode); | ||
|
||
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code - using sourcegenerator | ||
engineSettingsSection.Bind(Configuration.EngineSettings); | ||
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (ubuntu-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (ubuntu-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (macOS-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (macOS-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (windows-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / other-tests (windows-latest, Configuration)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / winning-at-chess (ubuntu-latest, WinningAtChess_10seconds)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / winning-at-chess (ubuntu-latest, WinningAtChess_10seconds)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (ubuntu-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (ubuntu-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, windows-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, windows-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, ubuntu-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, ubuntu-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, ubuntu-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, ubuntu-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (macOS-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (macOS-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, windows-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, windows-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, macOS-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Debug, macOS-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (windows-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / long-running-tests (windows-latest, LongRunning)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / perft-tests (ubuntu-latest, Perft)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / perft-tests (ubuntu-latest, Perft)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / perft-tests (windows-latest, Perft)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / perft-tests (windows-latest, Perft)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, macOS-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / fast-tests (Release, macOS-latest)
Check warning on line 30 in tests/Lynx.Test/ConfigurationTest.cs GitHub Actions / perft-tests (macOS-latest, Perft)
|
||
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code | ||
|
||
var reflectionProperties = Configuration.EngineSettings.GetType().GetProperties( | ||
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); | ||
Assert.GreaterOrEqual(reflectionProperties.Length, 35); | ||
|
||
var originalCulture = Thread.CurrentThread.CurrentCulture; | ||
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; | ||
|
||
Assert.Multiple(() => | ||
{ | ||
foreach (var property in reflectionProperties) | ||
{ | ||
if (property.PropertyType == typeof(int[])) | ||
{ | ||
continue; | ||
} | ||
var sourceSetting = jsonNode![property.Name]!.ToString().ToLowerInvariant(); | ||
var configSetting = property.GetValue(Configuration.EngineSettings)!.ToString()!.ToLowerInvariant(); | ||
Assert.AreEqual(sourceSetting, configSetting, $"Error in {property.Name} ({property.PropertyType}): (Configuration.cs) {sourceSetting} != {configSetting} (appSettings.json)"); | ||
} | ||
Thread.CurrentThread.CurrentCulture = originalCulture; | ||
}); | ||
} | ||
} |