@@ -315,11 +315,36 @@ private void ValidateMappingTransferUtilityAndSdkRequests<TSourceRequest, TTarge
315315 // Resolve alias to actual property name
316316 var resolvedPropertyName = ResolvePropertyName ( propertyName , sourceType . Name ) ;
317317 var sourceProperty = sourceType . GetProperty ( resolvedPropertyName ) ;
318- if ( sourceProperty ? . CanWrite == true )
318+
319+ if ( usesHeadersCollection && sourceProperty is null )
319320 {
320- var testValue = GenerateTestValue ( sourceProperty . PropertyType , propertyName ) ;
321- sourceProperty . SetValue ( sourceRequest , testValue ) ;
322- testDataValues [ propertyName ] = testValue ;
321+ // Check if source type has a Headers property of type HeadersCollection
322+ var sourceHeadersProperty = sourceType . GetProperty ( "Headers" ) ;
323+ if ( sourceHeadersProperty != null && typeof ( HeadersCollection ) . IsAssignableFrom ( sourceHeadersProperty . PropertyType ) )
324+ {
325+ var sourceHeadersCollection = sourceHeadersProperty . GetValue ( sourceRequest ) as HeadersCollection ;
326+ var sourceHeadersCollectionProperty = typeof ( HeadersCollection ) . GetProperty ( resolvedPropertyName ) ;
327+
328+ Assert . IsNotNull ( sourceHeadersCollectionProperty , $ "Source property '{ resolvedPropertyName } ' in '{ nameof ( HeadersCollection ) } ' should not be null") ;
329+
330+ if ( sourceHeadersCollectionProperty . CanWrite == true )
331+ {
332+ var testValue = GenerateTestValue ( sourceHeadersCollectionProperty . PropertyType , propertyName ) ;
333+ sourceHeadersCollectionProperty . SetValue ( sourceHeadersCollection , testValue ) ;
334+ testDataValues [ propertyName ] = testValue ;
335+ }
336+ }
337+ }
338+ else
339+ {
340+ Assert . IsNotNull ( sourceProperty , $ "Source property '{ propertyName } ' should not be null") ;
341+
342+ if ( sourceProperty . CanWrite == true )
343+ {
344+ var testValue = GenerateTestValue ( sourceProperty . PropertyType , propertyName ) ;
345+ sourceProperty . SetValue ( sourceRequest , testValue ) ;
346+ testDataValues [ propertyName ] = testValue ;
347+ }
323348 }
324349 }
325350
0 commit comments