Skip to content

Commit 38864a6

Browse files
authored
Merge pull request #528 from LogExperts/unittestsfix
unit tests update
2 parents c458feb + 1930a55 commit 38864a6

File tree

5 files changed

+128
-29
lines changed

5 files changed

+128
-29
lines changed

src/LogExpert.Core/Config/Preferences.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public class Preferences
2626
/// Will be removed in a future version once migration period is complete.
2727
/// </summary>
2828
[Obsolete("This property exists only for backward compatibility with old settings files. Use HighlightGroupList instead.")]
29-
[Newtonsoft.Json.JsonProperty("hilightGroupList")]
30-
[System.Text.Json.Serialization.JsonPropertyName("hilightGroupList")]
29+
[Newtonsoft.Json.JsonProperty("hilightGroupList", DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
30+
[System.Text.Json.Serialization.JsonIgnore]
3131
public List<HighlightGroup> HilightGroupList
3232
{
33-
get => HighlightGroupList;
33+
get => null; // Always return null so Newtonsoft.Json won't serialize this property
3434
set => HighlightGroupList = value ?? [];
3535
}
3636

src/LogExpert.Core/Config/Settings.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public class Settings
4242
/// Will be removed in a future version once migration period is complete.
4343
/// </summary>
4444
[Obsolete("This property exists only for backward compatibility with old settings files. Data is stored in Preferences.HighlightGroupList.")]
45-
[Newtonsoft.Json.JsonProperty("hilightEntryList")]
46-
[System.Text.Json.Serialization.JsonPropertyName("hilightEntryList")]
47-
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
45+
[Newtonsoft.Json.JsonProperty("hilightEntryList", DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
46+
[System.Text.Json.Serialization.JsonIgnore]
4847
public List<HighlightEntry> HilightEntryList
4948
{
5049
get => null; // Never serialize this
@@ -61,9 +60,8 @@ public List<HighlightEntry> HilightEntryList
6160
/// Will be removed in a future version once migration period is complete.
6261
/// </summary>
6362
[Obsolete("This property exists only for backward compatibility with old settings files. Data is stored in Preferences.HighlightGroupList.")]
64-
[Newtonsoft.Json.JsonProperty("hilightGroupList")]
65-
[System.Text.Json.Serialization.JsonPropertyName("hilightGroupList")]
66-
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
63+
[Newtonsoft.Json.JsonProperty("hilightGroupList", DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
64+
[System.Text.Json.Serialization.JsonIgnore]
6765
public List<HighlightGroup> HilightGroupList
6866
{
6967
get => null; // Never serialize this

src/LogExpert.Core/Entities/HighlightGroup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public class HighlightGroup : ICloneable
2626
/// Will be removed in a future version once migration period is complete.
2727
/// </summary>
2828
[Obsolete("This property exists only for backward compatibility with old settings files. Use HighlightEntryList instead.")]
29-
[Newtonsoft.Json.JsonProperty("hilightEntryList")]
30-
[System.Text.Json.Serialization.JsonPropertyName("hilightEntryList")]
29+
[Newtonsoft.Json.JsonProperty("hilightEntryList", DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
30+
[System.Text.Json.Serialization.JsonIgnore]
3131
public List<HighlightEntry> HilightEntryList
3232
{
33-
get => HighlightEntryList;
33+
get => null; // Always return null so Newtonsoft.Json won't serialize this property
3434
set => HighlightEntryList = value ?? [];
3535
}
3636

src/LogExpert.Tests/ConfigManagerTest.cs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,4 +975,105 @@ public void BackupFile_AlwaysValid_WhenExists ()
975975
}
976976

977977
#endregion
978+
979+
#region Backward Compatibility Tests
980+
981+
[Test]
982+
[Category("BackwardCompatibility")]
983+
[Description("LoadOrCreateNew should successfully load old JSON with 'hilightGroupList' typo")]
984+
public void LoadOrCreateNew_LegacyHilightGroupList_LoadsSuccessfully ()
985+
{
986+
// Arrange - Create JSON with old "hilightGroupList" property name (with typo)
987+
string legacyJson = @"{
988+
""Preferences"": {
989+
""hilightGroupList"": [
990+
{
991+
""GroupName"": ""LegacyGroup"",
992+
""hilightEntryList"": []
993+
}
994+
],
995+
""FontName"": ""Courier New"",
996+
""FontSize"": 9
997+
},
998+
""FilterList"": [],
999+
""SearchHistoryList"": []
1000+
}";
1001+
File.WriteAllText(_testSettingsFile.FullName, legacyJson);
1002+
1003+
// Act
1004+
LoadResult loadResult = InvokePrivateInstanceMethod<LoadResult>("LoadOrCreateNew", _testSettingsFile);
1005+
1006+
// Assert
1007+
Assert.That(loadResult, Is.Not.Null);
1008+
Assert.That(loadResult.Settings, Is.Not.Null);
1009+
Assert.That(loadResult.Settings.Preferences.HighlightGroupList.Count, Is.EqualTo(1), "Should load legacy 'hilightGroupList' into HighlightGroupList");
1010+
Assert.That(loadResult.Settings.Preferences.HighlightGroupList[0].GroupName, Is.EqualTo("LegacyGroup"));
1011+
}
1012+
1013+
[Test]
1014+
[Category("BackwardCompatibility")]
1015+
[Description("SaveAsJSON should not write the obsolete 'hilightGroupList' property")]
1016+
public void SaveAsJSON_DoesNotWriteLegacyProperty ()
1017+
{
1018+
// Arrange
1019+
Settings settings = CreateTestSettings();
1020+
settings.Preferences.HighlightGroupList.Add(new HighlightGroup { GroupName = "TestGroup" });
1021+
1022+
// Act
1023+
InvokePrivateInstanceMethod("SaveAsJSON", _testSettingsFile, settings);
1024+
1025+
// Assert
1026+
string json = File.ReadAllText(_testSettingsFile.FullName);
1027+
1028+
// Should contain the new property name
1029+
Assert.That(json, Does.Contain("HighlightGroupList"),
1030+
"Should write 'HighlightGroupList' property");
1031+
1032+
// Should NOT contain the legacy property name
1033+
Assert.That(json, Does.Not.Contain("hilightGroupList"),
1034+
"Should NOT write obsolete 'hilightGroupList' property");
1035+
1036+
// Verify the content is correct
1037+
Assert.That(json, Does.Contain("TestGroup"));
1038+
}
1039+
1040+
[Test]
1041+
[Category("BackwardCompatibility")]
1042+
[Description("Old JSON with both properties should not create duplicates")]
1043+
public void LoadOrCreateNew_BothPropertiesInJSON_NoDuplicates ()
1044+
{
1045+
// Arrange - Create JSON with BOTH property names (simulating a corrupted file)
1046+
string jsonWithBoth = @"{
1047+
""Preferences"": {
1048+
""HighlightGroupList"": [
1049+
{
1050+
""GroupName"": ""Group1"",
1051+
""HighlightEntryList"": []
1052+
}
1053+
],
1054+
""hilightGroupList"": [
1055+
{
1056+
""GroupName"": ""Group1"",
1057+
""hilightEntryList"": []
1058+
}
1059+
],
1060+
""FontName"": ""Courier New"",
1061+
""FontSize"": 9
1062+
},
1063+
""FilterList"": [],
1064+
""SearchHistoryList"": []
1065+
}";
1066+
File.WriteAllText(_testSettingsFile.FullName, jsonWithBoth);
1067+
1068+
// Act
1069+
LoadResult loadResult = InvokePrivateInstanceMethod<LoadResult>("LoadOrCreateNew", _testSettingsFile);
1070+
1071+
// Assert
1072+
Assert.That(loadResult, Is.Not.Null);
1073+
Assert.That(loadResult.Settings, Is.Not.Null);
1074+
Assert.That(loadResult.Settings.Preferences.HighlightGroupList.Count, Is.EqualTo(1), "Should have exactly 1 group, not duplicates");
1075+
Assert.That(loadResult.Settings.Preferences.HighlightGroupList[0].GroupName, Is.EqualTo("Group1"));
1076+
}
1077+
1078+
#endregion
9781079
}

src/PluginRegistry/PluginHashGenerator.Generated.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ public static partial class PluginValidator
1010
{
1111
/// <summary>
1212
/// Gets pre-calculated SHA256 hashes for built-in plugins.
13-
/// Generated: 2026-01-22 15:36:59 UTC
13+
/// Generated: 2026-01-23 15:56:33 UTC
1414
/// Configuration: Release
1515
/// Plugin count: 22
1616
/// </summary>
1717
public static Dictionary<string, string> GetBuiltInPluginHashes()
1818
{
1919
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
2020
{
21-
["AutoColumnizer.dll"] = "7BC68D6CAED29AA844E0C3D0EEF354DDD4CBFC4468343F060D6E09D80DC90B95",
21+
["AutoColumnizer.dll"] = "1D07B11AE3270F10155D1D6AA54FE70ED0080415E43A1F2B2A0EF72875DA84AF",
2222
["BouncyCastle.Cryptography.dll"] = "E5EEAF6D263C493619982FD3638E6135077311D08C961E1FE128F9107D29EBC6",
2323
["BouncyCastle.Cryptography.dll (x86)"] = "E5EEAF6D263C493619982FD3638E6135077311D08C961E1FE128F9107D29EBC6",
24-
["CsvColumnizer.dll"] = "D67A6A7B0EAB65B5C352EAED26B89104BC057612279ECD7ADD34BBEE3830019E",
25-
["CsvColumnizer.dll (x86)"] = "D67A6A7B0EAB65B5C352EAED26B89104BC057612279ECD7ADD34BBEE3830019E",
26-
["DefaultPlugins.dll"] = "E0503BC7A1CE12E8F18F058C62AB84C2402733E76F9E871C163A3A7900841B5A",
27-
["FlashIconHighlighter.dll"] = "32510C6566AA4321EFD39190471F9622EED1934D4E415E73D176A150CD4963B5",
28-
["GlassfishColumnizer.dll"] = "D504BFF6EC14F54C073BF23778C8BB0513F6385B21A10363D6C4415E18ED724A",
29-
["JsonColumnizer.dll"] = "2C786E6C1E9917EDEB224720C8B4AC7F322A0F9489C07E44F5F62AB887801E79",
30-
["JsonCompactColumnizer.dll"] = "63E5AE492888DF52C0B5F4584F6CDD35FA8B2DDF8192C75A9DD662C2C4FEDD96",
31-
["Log4jXmlColumnizer.dll"] = "3E85454E4CFD2563F77B26A3BD7E1A6F85D6B7C0E96338B3FFED1B8BC472C8D7",
32-
["LogExpert.Core.dll"] = "B8977B248A9A11632B9632D2905A364F98F8625391DDCA40F76CF8CDA185EAE6",
33-
["LogExpert.Resources.dll"] = "43507497CCBECB8E9A3285A7E837A4B8C88679FC030CF4AA7B2611B203A3AB9C",
24+
["CsvColumnizer.dll"] = "4DDCDD5E767C265AE31FF09DE7C6A093DC66979CB8EC2D9A8CBCB9A79096ED51",
25+
["CsvColumnizer.dll (x86)"] = "4DDCDD5E767C265AE31FF09DE7C6A093DC66979CB8EC2D9A8CBCB9A79096ED51",
26+
["DefaultPlugins.dll"] = "9F2745A5376897CA4436C6A90B9B2BB0A29F4225F81BF95C0B868E66DFBB8D3C",
27+
["FlashIconHighlighter.dll"] = "D7D008CF7945D67C790BCC17649F01810B1B2F243483DBBAE08B653A9B62FBA4",
28+
["GlassfishColumnizer.dll"] = "E25C288D6C13B1B80A58EC25906D9BEBAC5C5B46AB98F28B6C4C9E90401F9E40",
29+
["JsonColumnizer.dll"] = "A74907FDB01478D84F89C8AEB1DD83B4A6F2FDF884760296EDCBD2BA3D46FF1B",
30+
["JsonCompactColumnizer.dll"] = "AEF65E2C43EE39EE7DC80FBD8D8F499E6E215D6839FF6BDA7CED98C6312DB5BA",
31+
["Log4jXmlColumnizer.dll"] = "F85079FDA7BB9F8837AA6F5A6449B5F222552B77886F78F3A16A125E4EDD288C",
32+
["LogExpert.Core.dll"] = "CACF8255B06CB4AF43595196419192CF8BC2CB630456F15E6BDBC7292AC8A86E",
33+
["LogExpert.Resources.dll"] = "ABA39DD2544E6F8D357008649500B8AEDC88BD233EC3ADEE9304035EB9FD1853",
3434
["Microsoft.Extensions.DependencyInjection.Abstractions.dll"] = "67FA4325000DB017DC0C35829B416F024F042D24EFB868BCF17A895EE6500A93",
3535
["Microsoft.Extensions.DependencyInjection.Abstractions.dll (x86)"] = "67FA4325000DB017DC0C35829B416F024F042D24EFB868BCF17A895EE6500A93",
3636
["Microsoft.Extensions.Logging.Abstractions.dll"] = "BB853130F5AFAF335BE7858D661F8212EC653835100F5A4E3AA2C66A4D4F685D",
3737
["Microsoft.Extensions.Logging.Abstractions.dll (x86)"] = "BB853130F5AFAF335BE7858D661F8212EC653835100F5A4E3AA2C66A4D4F685D",
38-
["RegexColumnizer.dll"] = "0E6C500586C79D0280973B5D2A69AC0DB16FCF1AB963C6016965AE6CE3DB1103",
39-
["SftpFileSystem.dll"] = "A2C0E76211A0DE50F0C9B2B9BD1B97519ED390382179ACB73AED232245F42D2B",
40-
["SftpFileSystem.dll (x86)"] = "453EA3A17F9F6CAE24C76C6368264C0FA6745DC0FC8A2E6DAD86B127227A02E5",
41-
["SftpFileSystem.Resources.dll"] = "A1185922C0FF4ED0E8CE734FDA6B238ADE7C4DD4C8DC3811C41F618FCD4D4C5E",
42-
["SftpFileSystem.Resources.dll (x86)"] = "A1185922C0FF4ED0E8CE734FDA6B238ADE7C4DD4C8DC3811C41F618FCD4D4C5E",
38+
["RegexColumnizer.dll"] = "F44BF1FFF92E4D96C66E0B518D3E276BFE92E7DDB9EB0F93479ABC8EBE072CE2",
39+
["SftpFileSystem.dll"] = "1971EE85E9CEDDD0A38E846A3EC78F42D823B1DD1CA1A02B0A132B436FC1B32D",
40+
["SftpFileSystem.dll (x86)"] = "46D0701DB009188D5FADF47FDB54A5ADC85DB39D73CCE40C7823059CF9F19872",
41+
["SftpFileSystem.Resources.dll"] = "92C1963B793F646215C33E7B3E459564E0EDB6193D305739AEB871092572F318",
42+
["SftpFileSystem.Resources.dll (x86)"] = "92C1963B793F646215C33E7B3E459564E0EDB6193D305739AEB871092572F318",
4343

4444
};
4545
}

0 commit comments

Comments
 (0)