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

Update to adapt to new default rules in SDK #85

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol, options) is var signature => singleGeneric.Type switch
{
SingleGeneric.SupportedType.Nullable => signature
.CreateScope($"return {Value} is not null and {{ NULL: false }} ? {InvokeUnmarshallMethod(singleGeneric.T, Value, DataMember, options)} : null;")
.CreateScope($"return {Value} is not null ? {InvokeUnmarshallMethod(singleGeneric.T, Value, DataMember, options)} : null;")
.ToConversion(singleGeneric.T),
SingleGeneric.SupportedType.List or SingleGeneric.SupportedType.ICollection => signature
.CreateScope($"return {Value} is {{ L: {{ }} x }} ? {AttributeValueUtilityFactory.ToList}(x, {MarshallerOptions.ParamReference}, {DataMember}, static (a, o, d) => {InvokeUnmarshallMethod(singleGeneric.T, "a", "d", options, "o")}) : {Else(singleGeneric.TypeSymbol)};")
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoDBGenerator/DynamoDBGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.405.26" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0-preview.7" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon;
using Amazon.DynamoDBv2.Model;
using DynamoDBGenerator.Attributes;

Expand Down Expand Up @@ -120,8 +121,7 @@ public void Deserialize_GrandChildClassField_NotIncluded()
result.Id.Should().Be("I am the root");
result.CustomClass.Should().NotBeNull();
result.CustomClass!.PropertyId.Should().Be("I am the property");
result.CustomClass.GrandChild.Should().NotBeNull();
result.CustomClass.GrandChild!.GrandChildId.Should().BeNull();
result.CustomClass.GrandChild.Should().BeNull();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon;
using Amazon.DynamoDBv2.Model;
using DynamoDBGenerator.Attributes;
using DynamoDBGenerator.Exceptions;
Expand Down Expand Up @@ -26,12 +27,13 @@ public void Deserialize_NoValueProvided_ShouldNotThrow()
[Fact]
public void Deserialize_KeyValueProvided_ShouldNotThrow()
{
OptionalIntegerClassMarshaller
var result = OptionalIntegerClassMarshaller
.Unmarshall(new Dictionary<string, AttributeValue>
{ { "OptionalProperty", new AttributeValue { N = "2" } } })
.OptionalProperty
.Should()
.Be(2);
{
{ nameof(OptionalIntegerClass.OptionalProperty), new AttributeValue { N = "2" } }
}
);
result.OptionalProperty.Should().Be(2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public abstract class MarshalAsserter<T>
protected abstract T UnmarshallImplementation(Dictionary<string, AttributeValue> attributeValues);
protected abstract Dictionary<string, AttributeValue> MarshallImplementation(T element);


[Fact]
public void Marshall()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,36 @@ private static ((string FirstName, int Age,
static AttributeValue BuildPhoneAndMail(
((string Address, string? ZipCode) Address, (string Email, string Phone)? Mediums) valueTuple)
{
var attributeValue = new AttributeValue();

attributeValue.M.Add(nameof(valueTuple.Address), new AttributeValue
var attributeValue = new AttributeValue
{
M = valueTuple.Address.ZipCode is null
? new Dictionary<string, AttributeValue>
{
{ nameof(valueTuple.Address.Address), new AttributeValue { S = valueTuple.Address.Address } }
}
: new Dictionary<string, AttributeValue>
M = new Dictionary<string, AttributeValue>
{
{
{ nameof(valueTuple.Address.Address), new AttributeValue { S = valueTuple.Address.Address } },
{ nameof(valueTuple.Address.ZipCode), new AttributeValue { S = valueTuple.Address.ZipCode } }
nameof(valueTuple.Address), new AttributeValue
{
M = valueTuple.Address.ZipCode is null
? new Dictionary<string, AttributeValue>
{
{
nameof(valueTuple.Address.Address),
new AttributeValue { S = valueTuple.Address.Address }
}
}
: new Dictionary<string, AttributeValue>
{
{
nameof(valueTuple.Address.Address),
new AttributeValue { S = valueTuple.Address.Address }
},
{
nameof(valueTuple.Address.ZipCode),
new AttributeValue { S = valueTuple.Address.ZipCode }
}
}
}
}
});
}
};

if (valueTuple.Mediums is { } mediums)
attributeValue.M.Add(nameof(valueTuple.Mediums), new AttributeValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public void Serialize_DictionaryWithValues_IsIncluded()
x.Value.M.Should().SatisfyRespectively(y =>
{
y.Key.Should().Be("two");
((string)y.Value.N).Should().Be("2");
y.Value.N.Should().Be("2");
}, y =>
{
((string)y.Key).Should().Be("one");
((string)y.Value.N).Should().Be("1");
y.Key.Should().Be("one");
y.Value.N.Should().Be("1");
});
});
}
Expand All @@ -46,14 +46,15 @@ public void Serialize_EmptyDictionary_IsIncluded()
DictionaryImplementation = new Dictionary<string, int>()
};

DictionaryClassMarshaller
.Marshall(@class)
var result = DictionaryClassMarshaller.Marshall(@class);
result
.Should()
.NotBeEmpty()
.And
.ContainKey(nameof(DictionaryClass.DictionaryImplementation))
.And
.ContainSingle(x => x.Value.L.Count == 0);
.ContainKey(nameof(DictionaryClass.DictionaryImplementation));

result[nameof(DictionaryClass.DictionaryImplementation)].M.Should().BeEmpty();

}
}

Expand Down