Skip to content

Commit 9cd5c6c

Browse files
philasmarGarrettBeatty
authored andcommitted
Fix issue with HeadersCollection in ResponseMapperTests
1 parent 6212c3b commit 9cd5c6c

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

sdk/test/Services/S3/UnitTests/Custom/ResponseMapperTests.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)