@@ -39,46 +39,168 @@ public class ResponseMapperTests
3939 [ ClassInitialize ]
4040 public static void ClassInitialize ( TestContext context )
4141 {
42+ // DEBUG: Log initial setup information
43+ Console . WriteLine ( "=== DEBUG: ResponseMapperTests ClassInitialize ===" ) ;
44+ Console . WriteLine ( $ "Current Working Directory: { Directory . GetCurrentDirectory ( ) } ") ;
45+
4246 // Get the test assembly directory and navigate to the source directory
4347 var assemblyLocation = Assembly . GetExecutingAssembly ( ) . Location ;
48+ Console . WriteLine ( $ "Assembly Location: { assemblyLocation } ") ;
49+
4450 var testProjectDirectory = Path . GetDirectoryName ( assemblyLocation ) ;
51+ Console . WriteLine ( $ "Initial Test Project Directory: { testProjectDirectory } ") ;
52+
53+ // DEBUG: Log directory contents at starting point
54+ if ( testProjectDirectory != null && Directory . Exists ( testProjectDirectory ) )
55+ {
56+ Console . WriteLine ( $ "Contents of starting directory '{ testProjectDirectory } ':") ;
57+ try
58+ {
59+ var files = Directory . GetFiles ( testProjectDirectory ) ;
60+ var dirs = Directory . GetDirectories ( testProjectDirectory ) ;
61+ Console . WriteLine ( $ " Files: { string . Join ( ", " , files . Select ( Path . GetFileName ) ) } ") ;
62+ Console . WriteLine ( $ " Directories: { string . Join ( ", " , dirs . Select ( Path . GetFileName ) ) } ") ;
63+ }
64+ catch ( Exception ex )
65+ {
66+ Console . WriteLine ( $ " Error reading directory: { ex . Message } ") ;
67+ }
68+ }
4569
4670 // Navigate up from bin/Debug/net472 to the test project root
47- while ( testProjectDirectory != null && ! File . Exists ( Path . Combine ( testProjectDirectory , "Custom" , "TestData" , "mapping.json" ) ) )
71+ int searchDepth = 0 ;
72+ const int maxSearchDepth = 10 ; // Prevent infinite loops
73+
74+ while ( testProjectDirectory != null && searchDepth < maxSearchDepth )
4875 {
49- testProjectDirectory = Directory . GetParent ( testProjectDirectory ) ? . FullName ;
76+ var targetPath = Path . Combine ( testProjectDirectory , "Custom" , "TestData" , "mapping.json" ) ;
77+ Console . WriteLine ( $ "Search attempt { searchDepth + 1 } : Checking for file at '{ targetPath } '") ;
78+ Console . WriteLine ( $ " Directory exists: { Directory . Exists ( testProjectDirectory ) } ") ;
79+ Console . WriteLine ( $ " File exists: { File . Exists ( targetPath ) } ") ;
80+
81+ // DEBUG: Log what's in the current directory
82+ if ( Directory . Exists ( testProjectDirectory ) )
83+ {
84+ try
85+ {
86+ var subdirs = Directory . GetDirectories ( testProjectDirectory ) ;
87+ Console . WriteLine ( $ " Subdirectories: { string . Join ( ", " , subdirs . Select ( Path . GetFileName ) ) } ") ;
88+
89+ // Check if Custom directory exists
90+ var customDir = Path . Combine ( testProjectDirectory , "Custom" ) ;
91+ if ( Directory . Exists ( customDir ) )
92+ {
93+ Console . WriteLine ( $ " Custom directory found at: { customDir } ") ;
94+ var customSubdirs = Directory . GetDirectories ( customDir ) ;
95+ Console . WriteLine ( $ " Custom subdirectories: { string . Join ( ", " , customSubdirs . Select ( Path . GetFileName ) ) } ") ;
96+
97+ // Check if TestData directory exists
98+ var testDataDir = Path . Combine ( customDir , "TestData" ) ;
99+ if ( Directory . Exists ( testDataDir ) )
100+ {
101+ Console . WriteLine ( $ " TestData directory found at: { testDataDir } ") ;
102+ var testDataFiles = Directory . GetFiles ( testDataDir ) ;
103+ Console . WriteLine ( $ " TestData files: { string . Join ( ", " , testDataFiles . Select ( Path . GetFileName ) ) } ") ;
104+ }
105+ else
106+ {
107+ Console . WriteLine ( $ " TestData directory NOT found at: { testDataDir } ") ;
108+ }
109+ }
110+ else
111+ {
112+ Console . WriteLine ( $ " Custom directory NOT found at: { customDir } ") ;
113+ }
114+ }
115+ catch ( Exception ex )
116+ {
117+ Console . WriteLine ( $ " Error examining directory: { ex . Message } ") ;
118+ }
119+ }
120+
121+ if ( File . Exists ( targetPath ) )
122+ {
123+ Console . WriteLine ( $ "SUCCESS: Found mapping.json at '{ targetPath } '") ;
124+ break ;
125+ }
126+
127+ var parentDir = Directory . GetParent ( testProjectDirectory ) ;
128+ testProjectDirectory = parentDir ? . FullName ;
129+ Console . WriteLine ( $ " Moving up to parent: { testProjectDirectory ?? "null" } ") ;
130+ searchDepth ++ ;
50131 }
51132
52133 if ( testProjectDirectory == null )
53134 {
54- throw new FileNotFoundException ( "Could not locate mapping.json file in test project directory structure" ) ;
135+ Console . WriteLine ( "ERROR: Exhausted directory search - testProjectDirectory is null" ) ;
136+ Console . WriteLine ( $ "Searched { searchDepth } levels up from assembly location: { assemblyLocation } ") ;
137+ throw new FileNotFoundException (
138+ $ "Could not locate mapping.json file in test project directory structure. " +
139+ $ "Started from: { assemblyLocation } , searched { searchDepth } levels up.") ;
140+ }
141+
142+ if ( searchDepth >= maxSearchDepth )
143+ {
144+ Console . WriteLine ( $ "ERROR: Reached maximum search depth of { maxSearchDepth } ") ;
145+ throw new FileNotFoundException (
146+ $ "Could not locate mapping.json file within { maxSearchDepth } directory levels. " +
147+ $ "Started from: { assemblyLocation } ") ;
55148 }
56149
57150 var testDataPath = Path . Combine ( testProjectDirectory , "Custom" , "TestData" , "mapping.json" ) ;
58151 var aliasesPath = Path . Combine ( testProjectDirectory , "Custom" , "TestData" , "property-aliases.json" ) ;
59152
153+ Console . WriteLine ( $ "Final resolved paths:") ;
154+ Console . WriteLine ( $ " Mapping file: { testDataPath } ") ;
155+ Console . WriteLine ( $ " Aliases file: { aliasesPath } ") ;
156+ Console . WriteLine ( $ " Mapping file exists: { File . Exists ( testDataPath ) } ") ;
157+ Console . WriteLine ( $ " Aliases file exists: { File . Exists ( aliasesPath ) } ") ;
158+
60159 // Load the mapping configuration
61- var jsonContent = File . ReadAllText ( testDataPath ) ;
62- _mappingJson = JsonDocument . Parse ( jsonContent ) ;
160+ try
161+ {
162+ var jsonContent = File . ReadAllText ( testDataPath ) ;
163+ Console . WriteLine ( $ "Successfully read mapping.json ({ jsonContent . Length } characters)") ;
164+ _mappingJson = JsonDocument . Parse ( jsonContent ) ;
165+ Console . WriteLine ( "Successfully parsed mapping.json" ) ;
166+ }
167+ catch ( Exception ex )
168+ {
169+ Console . WriteLine ( $ "ERROR reading or parsing mapping.json: { ex . Message } ") ;
170+ throw ;
171+ }
63172
64173 // Load property aliases if the file exists
65174 if ( File . Exists ( aliasesPath ) )
66175 {
67- var aliasContent = File . ReadAllText ( aliasesPath ) ;
68- _propertyAliasesJson = JsonDocument . Parse ( aliasContent ) ;
69-
70- // Convert to dictionary for fast lookup
71- _propertyAliases = new Dictionary < string , string > ( ) ;
72- var aliasesElement = _propertyAliasesJson . RootElement . GetProperty ( "PropertyAliases" ) ;
73- foreach ( var alias in aliasesElement . EnumerateObject ( ) )
176+ try
74177 {
75- _propertyAliases [ alias . Name ] = alias . Value . GetString ( ) ;
178+ var aliasContent = File . ReadAllText ( aliasesPath ) ;
179+ Console . WriteLine ( $ "Successfully read property-aliases.json ({ aliasContent . Length } characters)") ;
180+ _propertyAliasesJson = JsonDocument . Parse ( aliasContent ) ;
181+
182+ // Convert to dictionary for fast lookup
183+ _propertyAliases = new Dictionary < string , string > ( ) ;
184+ var aliasesElement = _propertyAliasesJson . RootElement . GetProperty ( "PropertyAliases" ) ;
185+ foreach ( var alias in aliasesElement . EnumerateObject ( ) )
186+ {
187+ _propertyAliases [ alias . Name ] = alias . Value . GetString ( ) ;
188+ }
189+ Console . WriteLine ( $ "Loaded { _propertyAliases . Count } property aliases") ;
190+ }
191+ catch ( Exception ex )
192+ {
193+ Console . WriteLine ( $ "ERROR reading or parsing property-aliases.json: { ex . Message } ") ;
194+ throw ;
76195 }
77196 }
78197 else
79198 {
199+ Console . WriteLine ( "property-aliases.json not found, using empty aliases dictionary" ) ;
80200 _propertyAliases = new Dictionary < string , string > ( ) ;
81201 }
202+
203+ Console . WriteLine ( "=== END DEBUG: ClassInitialize completed successfully ===" ) ;
82204 }
83205
84206 [ ClassCleanup ]
0 commit comments