@@ -70,6 +70,23 @@ public LandedTitlesTests() {
7070 cultures = new CultureCollection ( colorFactory , pillars , ck3ModFlags ) ;
7171 }
7272
73+ private static void WithTemporaryHeritageEmpireMap ( Action action , string fileContents = "" ) {
74+ const string heritageMapPath = "configurables/heritage_empires_map.txt" ;
75+ var originalHeritageMap = File . Exists ( heritageMapPath ) ? File . ReadAllText ( heritageMapPath ) : null ;
76+ Directory . CreateDirectory ( "configurables" ) ;
77+ File . WriteAllText ( heritageMapPath , fileContents ) ;
78+
79+ try {
80+ action ( ) ;
81+ } finally {
82+ if ( originalHeritageMap is null ) {
83+ File . Delete ( heritageMapPath ) ;
84+ } else {
85+ File . WriteAllText ( heritageMapPath , originalHeritageMap ) ;
86+ }
87+ }
88+ }
89+
7390 [ Fact ]
7491 public void TitlesDefaultToEmpty ( ) {
7592 var reader = new BufferedReader ( string . Empty ) ;
@@ -664,7 +681,7 @@ public void KingdomUsesNextDominantHeritageWhenMostDominantOneCannotProvideEmpir
664681 titles [ "c_county3" ] . SetHolder ( mongolHolder , date ) ;
665682 titles [ "c_xia_county" ] . SetHolder ( mongolHolder , date ) ;
666683
667- var heritageMapPath = Path . Combine ( "configurables" , " heritage_empires_map.txt") ;
684+ string heritageMapPath = "configurables/ heritage_empires_map.txt" ;
668685 var originalHeritageMap = File . Exists ( heritageMapPath ) ? File . ReadAllText ( heritageMapPath ) : null ;
669686 Directory . CreateDirectory ( "configurables" ) ;
670687 File . WriteAllText ( heritageMapPath ,
@@ -709,7 +726,9 @@ public void KingdomMostlyOutsideImperatorMapKeepsExistingDeJureSetup() {
709726 var provinceMapper = new ProvinceMapper ( ) ;
710727 provinceMapper . LoadMappings ( provinceMappingsPath ) ;
711728
712- titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper ) ;
729+ WithTemporaryHeritageEmpireMap ( ( ) =>
730+ titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper )
731+ ) ;
713732
714733 Assert . Equal ( "k_protected" , titles [ "d_protected" ] . DeJureLiege ? . Id ) ;
715734 Assert . Equal ( "e_old" , titles [ "k_protected" ] . DeJureLiege ? . Id ) ;
@@ -738,7 +757,9 @@ public void KingdomAtFiftyPercentOutsideImperatorMapStillUsesDynamicDeJureSetup(
738757 var provinceMapper = new ProvinceMapper ( ) ;
739758 provinceMapper . LoadMappings ( provinceMappingsPath ) ;
740759
741- titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper ) ;
760+ WithTemporaryHeritageEmpireMap ( ( ) =>
761+ titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper )
762+ ) ;
742763
743764 Assert . Equal ( "k_target" , titles [ "d_test" ] . DeJureLiege ? . Id ) ;
744765 }
@@ -766,7 +787,9 @@ public void ProtectedKingdomIsNotExcludedFromDisconnectedEmpireSplitting() {
766787 var provinceMapper = new ProvinceMapper ( ) ;
767788 provinceMapper . LoadMappings ( provinceMappingsPath ) ;
768789
769- titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper ) ;
790+ WithTemporaryHeritageEmpireMap ( ( ) =>
791+ titles . SetDeJureKingdomsAndAbove ( date , new TestCK3CultureCollection ( ) , characters , new MapData ( ck3ModFS ) , new CK3RegionMapper ( ) , new TestCK3LocDB ( ) , provinceMapper )
792+ ) ;
770793
771794 Assert . Equal ( "e_IRTOCK3_from_c_protected1" , titles [ "k_protected" ] . DeJureLiege ? . Id ) ;
772795 Assert . True ( titles . ContainsKey ( "e_IRTOCK3_from_c_protected1" ) ) ;
0 commit comments