Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing collection related tests for v4 dev #3312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
#>
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
{
if (response.<#=member.PropertyName#> == null)
normj marked this conversation as resolved.
Show resolved Hide resolved
{
response.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
}
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
response.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,13 @@ public List<I> Unmarshall(JsonUnmarshallerContext context)
{
context.Read(); // Read [ or null
if (context.CurrentTokenType == JsonToken.Null)
normj marked this conversation as resolved.
Show resolved Hide resolved
return new List<I>();
{
if (AWSConfigs.InitializeCollections)
return new List<I>();
else
return null;
}


// If a list is present in the response, use AlwaysSendList,
// so if the response was empty, reusing the object in the request we will
Expand Down Expand Up @@ -975,7 +981,13 @@ public Dictionary<TKey, TValue> Unmarshall(JsonUnmarshallerContext context)
{
context.Read(); // Read { or null
if (context.CurrentTokenType == JsonToken.Null)
normj marked this conversation as resolved.
Show resolved Hide resolved
return new Dictionary<TKey,TValue>();
{
if (AWSConfigs.InitializeCollections)
return new Dictionary<TKey, TValue>();
else
return null;
}


// If a dictionary is present in the response, use AlwaysSendDictionary,
// so if the response was empty, reusing the object in the request we will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private static void UnmarshallResult(XmlUnmarshallerContext context, FlattenedXm
{
if (context.TestExpression("myMap", targetDepth))
{
if (response.MyMap == null)
{
response.MyMap = new Dictionary<string, string>();
}
var unmarshaller = new KeyValueUnmarshaller<string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
response.MyMap.Add(unmarshaller.Unmarshall(context));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private static void UnmarshallResult(XmlUnmarshallerContext context, FlattenedXm
{
if (context.TestExpression("KVP", targetDepth))
{
if (response.MyMap == null)
{
response.MyMap = new Dictionary<string, string>();
}
var unmarshaller = new KeyValueUnmarshaller<string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
response.MyMap.Add(unmarshaller.Unmarshall(context));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private static void UnmarshallResult(XmlUnmarshallerContext context, FlattenedXm
{
if (context.TestExpression("KVP", targetDepth))
{
if (response.MyMap == null)
{
response.MyMap = new Dictionary<string, string>();
}
var unmarshaller = new KeyValueUnmarshaller<string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance);
response.MyMap.Add(unmarshaller.Unmarshall(context));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ private static void UnmarshallResult(XmlUnmarshallerContext context, NestedXmlMa
{
if (context.TestExpression("flatNestedMap", targetDepth))
{
if (response.FlatNestedMap == null)
{
response.FlatNestedMap = new Dictionary<string, Dictionary<string, string>>();
}
var unmarshaller = new KeyValueUnmarshaller<string, Dictionary<string, string>, StringUnmarshaller, DictionaryUnmarshaller<string, string, StringUnmarshaller, StringUnmarshaller>>(StringUnmarshaller.Instance, new DictionaryUnmarshaller<string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance));
response.FlatNestedMap.Add(unmarshaller.Unmarshall(context));
continue;
Expand Down
12 changes: 11 additions & 1 deletion sdk/test/UnitTests/Custom/TestTools/Comparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Amazon.Runtime.Internal.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ServiceClientGenerator;
using System.Collections.ObjectModel;
using Amazon;

namespace AWSSDK_DotNet.UnitTests.TestTools
{
Expand Down Expand Up @@ -51,7 +53,15 @@ private static void Compare(object x, object y, Type type)
if (x == null && y == null)
return;

if ((x == null && y != null) || (x != null && y == null))
if (!AWSConfigs.InitializeCollections && x != null && type.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>)))
{
var expectedCollection = (ICollection)x;
var actualCollection = (ICollection)y;
if (expectedCollection.Count == 0 && actualCollection == null)
return;
}

if (x == null ^ y == null)
Assert.Fail("Either x or y is null. x={0} y={1}", x, y);


Expand Down