From a5b36e1e66c7529db01df30597d856abe2e2a6ed Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Tue, 21 Jul 2026 17:45:34 -0500 Subject: [PATCH] Fix SDK tests --- .../IniHandlingTests_PeanutButter.cs | 207 ------------------ .../Parsers/IniParserTests.cs | 7 +- LANCommander.SDK.Tests/SaveService.cs | 4 +- 3 files changed, 9 insertions(+), 209 deletions(-) delete mode 100644 LANCommander.SDK.Tests/IniHandling/IniHandlingTests_PeanutButter.cs diff --git a/LANCommander.SDK.Tests/IniHandling/IniHandlingTests_PeanutButter.cs b/LANCommander.SDK.Tests/IniHandling/IniHandlingTests_PeanutButter.cs deleted file mode 100644 index 59e7a38c..00000000 --- a/LANCommander.SDK.Tests/IniHandling/IniHandlingTests_PeanutButter.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System.Reflection; -using PeanutButter.INI; - -namespace LANCommander.SDK.Tests.IniHandling -{ - public class IniHandlingTests_PeanutButter - { - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void Parse(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - Assert.NotNull(ini); - } - - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void CheckSections(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - - foreach (var requiredKey in configuration.RequiredSections) - { - Assert.True(ini.HasSection(requiredKey)); - } - } - - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void CheckSectionsCount(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - - foreach (var requiredSection in configuration.RequiredSectionsCount) - { - Assert.Equal(requiredSection.Value, ini.AllSections.Count(x => string.Equals(x, requiredSection.Key, StringComparison.InvariantCultureIgnoreCase))); - } - } - - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void CheckSectionKeys(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - - foreach (var requiredSection in configuration.RequiredKeys) - { - var section = ini.GetSection(requiredSection.Key); - Assert.NotNull(section); - - foreach (var requiredKey in requiredSection.Value) - { - Assert.True(section.ContainsKey(requiredKey)); - } - } - } - - - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void CheckSectionKeysCount(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - - foreach (var requiredSection in configuration.RequiredKeysCount) - { - var section = ini.GetSection(requiredSection.Key); - Assert.NotNull(section); - - foreach (var requiredKeys in requiredSection.Value) - { - Assert.Equal(requiredKeys.Value, section.Keys.Count(x => string.Equals(x, requiredKeys.Key, StringComparison.InvariantCultureIgnoreCase))); - } - } - } - - [Theory] - [InlineData(nameof(ConfigurationTests.Test_SingleSection))] - [InlineData(nameof(ConfigurationTests.Test_TwoSections))] - [InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void CheckSectionKeyValues(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - - foreach (var requiredSection in configuration.RequiredKeyValues) - { - var section = ini.GetSection(requiredSection.Section); - Assert.NotNull(section); - - foreach (var requiredKeyValue in requiredSection.KeyValues) - { - var match = section.FirstOrDefault(key => - { - return string.Equals(key.Key, requiredKeyValue.Key, StringComparison.InvariantCultureIgnoreCase) - && string.Equals(key.Value, requiredKeyValue.Value, StringComparison.InvariantCulture); - }); - - Assert.NotEqual(match, default); - } - } - } - - [Theory] - //[InlineData(nameof(ConfigurationTests.Test_SingleSection))] - //[InlineData(nameof(ConfigurationTests.Test_TwoSections))] - //[InlineData(nameof(ConfigurationTests.Test_ArrayStatic))] - [InlineData(nameof(ConfigurationTests.Test_ArrayMultiValue))] - public void UpdateSectionKeyValues(string configurationName) - { - ConfigurationTest configuration = GetConfiguration(configurationName); - var ini = INIFile.FromString(configuration.Ini); - Assert.NotNull(ini); - - foreach (var requiredSection in configuration.UpdateKeyValues) - { - var section = ini.GetSection(requiredSection.Section); - Assert.NotNull(section); - - foreach (var updateKeyValue in requiredSection.UpdateKeyValues) - { - ini.SetValue(requiredSection.Section, updateKeyValue.Key, updateKeyValue.NewValue); - var value = ini.GetValue(requiredSection.Section, updateKeyValue.Key); - Assert.True(updateKeyValue.NewValue == null || string.Equals(updateKeyValue.NewValue, value, StringComparison.InvariantCulture)); - } - - // compare newly generated INI - string iniContentNew = ini.ToString(); - var iniNew = INIFile.FromString(iniContentNew); - Assert.NotNull(iniNew); - - foreach (var checkSection in requiredSection.CheckKeyValues) - { - var sectionNew = iniNew.GetSection(checkSection.Section); - Assert.NotNull(sectionNew); - - foreach (var checkKeyValue in checkSection.KeyValues) - { - IList> searches = []; - if (checkKeyValue.Values != null) - { - foreach (var expected in checkKeyValue.Values) - { - searches.Add(new KeyValuePair(checkKeyValue.Key, expected)); - } - } - else - { - searches.Add(new KeyValuePair(checkKeyValue.Key, checkKeyValue.Value)); - } - - foreach (var search in searches) - { - var match = section.FirstOrDefault(key => - { - return string.Equals(key.Key, search.Key, StringComparison.InvariantCultureIgnoreCase) - && string.Equals(key.Value, search.Value, StringComparison.InvariantCulture); - }); - - Assert.NotEqual(match, default); - } - } - } - } - } - - public static ConfigurationTest GetConfiguration(string configurationName) - { - Type configTestsType = typeof(ConfigurationTests); - FieldInfo? field = configTestsType?.GetField(configurationName, BindingFlags.Public | BindingFlags.Static); - - if (field == null) - { - throw new Exception($"The configuration '{configurationName}' does not exist."); - } - - ConfigurationTest? configurationTest = field.GetValue(null) as ConfigurationTest; - if (configurationTest == null) - { - throw new Exception($"The configuration '{configurationName}' is not of type ConfigurationTest or is null."); - } - - return configurationTest; - } - } -} diff --git a/LANCommander.SDK.Tests/Parsers/IniParserTests.cs b/LANCommander.SDK.Tests/Parsers/IniParserTests.cs index 7d7d16c4..a388fc51 100644 --- a/LANCommander.SDK.Tests/Parsers/IniParserTests.cs +++ b/LANCommander.SDK.Tests/Parsers/IniParserTests.cs @@ -90,7 +90,12 @@ namespace LANCommander.SDK.Tests.IniHandling foreach (var requiredKeys in requiredSection.Value) { - Assert.Equal(requiredKeys.Value, section.Keys.Count(x => string.Equals(x.Name, requiredKeys.Key, StringComparison.InvariantCultureIgnoreCase))); + // An empty key name is a sentinel meaning "assert the total key count". + var count = (requiredKeys.Key == "") + ? section.Keys.Count + : section.Keys.Count(x => string.Equals(x.Name, requiredKeys.Key, StringComparison.InvariantCultureIgnoreCase)); + + Assert.Equal(requiredKeys.Value, count); } } } diff --git a/LANCommander.SDK.Tests/SaveService.cs b/LANCommander.SDK.Tests/SaveService.cs index d279d65b..be14cf23 100644 --- a/LANCommander.SDK.Tests/SaveService.cs +++ b/LANCommander.SDK.Tests/SaveService.cs @@ -109,7 +109,9 @@ namespace LANCommander.SDK.Tests var savePath = new SavePath { Id = Guid.NewGuid(), - Path = "base\\.*.cfg", + // GetFileSavePathEntries matches against relative paths normalized to + // forward slashes, so the regex must use '/' and escape the literal dot. + Path = "base/.*\\.cfg", WorkingDirectory = "{InstallDir}", Type = Enums.SavePathType.File, IsRegex = true