Skip to content

Commit 7a57220

Browse files
philasmarGarrettBeatty
authored andcommitted
Fix issue with HeadersCollection in ResponseMapperTests
1 parent df0a432 commit 7a57220

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
@@ -265,11 +265,36 @@ private void ValidateMappingTransferUtilityAndSdkRequests<TSourceRequest, TTarge
265265
// Resolve alias to actual property name
266266
var resolvedPropertyName = ResolvePropertyName(propertyName, sourceType.Name);
267267
var sourceProperty = sourceType.GetProperty(resolvedPropertyName);
268-
if (sourceProperty?.CanWrite == true)
268+
269+
if (usesHeadersCollection && sourceProperty is null)
269270
{
270-
var testValue = GenerateTestValue(sourceProperty.PropertyType, propertyName);
271-
sourceProperty.SetValue(sourceRequest, testValue);
272-
testDataValues[propertyName] = testValue;
271+
// Check if source type has a Headers property of type HeadersCollection
272+
var sourceHeadersProperty = sourceType.GetProperty("Headers");
273+
if (sourceHeadersProperty != null && typeof(HeadersCollection).IsAssignableFrom(sourceHeadersProperty.PropertyType))
274+
{
275+
var sourceHeadersCollection = sourceHeadersProperty.GetValue(sourceRequest) as HeadersCollection;
276+
var sourceHeadersCollectionProperty = typeof(HeadersCollection).GetProperty(resolvedPropertyName);
277+
278+
Assert.IsNotNull(sourceHeadersCollectionProperty, $"Source property '{resolvedPropertyName}' in '{nameof(HeadersCollection)}' should not be null");
279+
280+
if (sourceHeadersCollectionProperty.CanWrite == true)
281+
{
282+
var testValue = GenerateTestValue(sourceHeadersCollectionProperty.PropertyType, propertyName);
283+
sourceHeadersCollectionProperty.SetValue(sourceHeadersCollection, testValue);
284+
testDataValues[propertyName] = testValue;
285+
}
286+
}
287+
}
288+
else
289+
{
290+
Assert.IsNotNull(sourceProperty, $"Source property '{propertyName}' should not be null");
291+
292+
if (sourceProperty.CanWrite == true)
293+
{
294+
var testValue = GenerateTestValue(sourceProperty.PropertyType, propertyName);
295+
sourceProperty.SetValue(sourceRequest, testValue);
296+
testDataValues[propertyName] = testValue;
297+
}
273298
}
274299
}
275300

0 commit comments

Comments
 (0)