@@ -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}
0 commit comments