Skip to content

Commit 3602e7d

Browse files
committed
Update to adapt to new default rules in SDK
1 parent 80f77ff commit 3602e7d

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static CodeFactory CreateMethod(ITypeSymbol type, Func<ITypeSymbol, Dyna
9090
SingleGeneric singleGeneric when CreateSignature(singleGeneric.TypeSymbol, options) is var signature => singleGeneric.Type switch
9191
{
9292
SingleGeneric.SupportedType.Nullable => signature
93-
.CreateScope($"return {Value} is not null and {{ NULL: false }} ? {InvokeUnmarshallMethod(singleGeneric.T, Value, DataMember, options)} : null;")
93+
.CreateScope($"return {Value} is not null ? {InvokeUnmarshallMethod(singleGeneric.T, Value, DataMember, options)} : null;")
9494
.ToConversion(singleGeneric.T),
9595
SingleGeneric.SupportedType.List or SingleGeneric.SupportedType.ICollection => signature
9696
.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)};")

src/DynamoDBGenerator/DynamoDBGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.405.26" />
22+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0-preview.7" />
2323
</ItemGroup>
2424
</Project>

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Deserialize/CustomObjects/ChildClassTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Amazon;
12
using Amazon.DynamoDBv2.Model;
23
using DynamoDBGenerator.Attributes;
34

@@ -120,8 +121,7 @@ public void Deserialize_GrandChildClassField_NotIncluded()
120121
result.Id.Should().Be("I am the root");
121122
result.CustomClass.Should().NotBeNull();
122123
result.CustomClass!.PropertyId.Should().Be("I am the property");
123-
result.CustomClass.GrandChild.Should().NotBeNull();
124-
result.CustomClass.GrandChild!.GrandChildId.Should().BeNull();
124+
result.CustomClass.GrandChild.Should().BeNull();
125125
}
126126
}
127127

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Deserialize/Generics/NullableTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Amazon;
12
using Amazon.DynamoDBv2.Model;
23
using DynamoDBGenerator.Attributes;
34
using DynamoDBGenerator.Exceptions;
@@ -26,12 +27,13 @@ public void Deserialize_NoValueProvided_ShouldNotThrow()
2627
[Fact]
2728
public void Deserialize_KeyValueProvided_ShouldNotThrow()
2829
{
29-
OptionalIntegerClassMarshaller
30+
var result = OptionalIntegerClassMarshaller
3031
.Unmarshall(new Dictionary<string, AttributeValue>
31-
{ { "OptionalProperty", new AttributeValue { N = "2" } } })
32-
.OptionalProperty
33-
.Should()
34-
.Be(2);
32+
{
33+
{ nameof(OptionalIntegerClass.OptionalProperty), new AttributeValue { N = "2" } }
34+
}
35+
);
36+
result.OptionalProperty.Should().Be(2);
3537
}
3638
}
3739

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Asserters/MarshalAsserter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public abstract class MarshalAsserter<T>
88
protected abstract T UnmarshallImplementation(Dictionary<string, AttributeValue> attributeValues);
99
protected abstract Dictionary<string, AttributeValue> MarshallImplementation(T element);
1010

11-
1211
[Fact]
1312
public void Marshall()
1413
{

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Tuples/ComplexTupleTests.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,36 @@ private static ((string FirstName, int Age,
108108
static AttributeValue BuildPhoneAndMail(
109109
((string Address, string? ZipCode) Address, (string Email, string Phone)? Mediums) valueTuple)
110110
{
111-
var attributeValue = new AttributeValue();
112-
113-
attributeValue.M.Add(nameof(valueTuple.Address), new AttributeValue
111+
var attributeValue = new AttributeValue
114112
{
115-
M = valueTuple.Address.ZipCode is null
116-
? new Dictionary<string, AttributeValue>
117-
{
118-
{ nameof(valueTuple.Address.Address), new AttributeValue { S = valueTuple.Address.Address } }
119-
}
120-
: new Dictionary<string, AttributeValue>
113+
M = new Dictionary<string, AttributeValue>
114+
{
121115
{
122-
{ nameof(valueTuple.Address.Address), new AttributeValue { S = valueTuple.Address.Address } },
123-
{ nameof(valueTuple.Address.ZipCode), new AttributeValue { S = valueTuple.Address.ZipCode } }
116+
nameof(valueTuple.Address), new AttributeValue
117+
{
118+
M = valueTuple.Address.ZipCode is null
119+
? new Dictionary<string, AttributeValue>
120+
{
121+
{
122+
nameof(valueTuple.Address.Address),
123+
new AttributeValue { S = valueTuple.Address.Address }
124+
}
125+
}
126+
: new Dictionary<string, AttributeValue>
127+
{
128+
{
129+
nameof(valueTuple.Address.Address),
130+
new AttributeValue { S = valueTuple.Address.Address }
131+
},
132+
{
133+
nameof(valueTuple.Address.ZipCode),
134+
new AttributeValue { S = valueTuple.Address.ZipCode }
135+
}
136+
}
137+
}
124138
}
125-
});
139+
}
140+
};
126141

127142
if (valueTuple.Mediums is { } mediums)
128143
attributeValue.M.Add(nameof(valueTuple.Mediums), new AttributeValue

tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Serialize/Generics/DictionaryTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public void Serialize_DictionaryWithValues_IsIncluded()
2929
x.Value.M.Should().SatisfyRespectively(y =>
3030
{
3131
y.Key.Should().Be("two");
32-
((string)y.Value.N).Should().Be("2");
32+
y.Value.N.Should().Be("2");
3333
}, y =>
3434
{
35-
((string)y.Key).Should().Be("one");
36-
((string)y.Value.N).Should().Be("1");
35+
y.Key.Should().Be("one");
36+
y.Value.N.Should().Be("1");
3737
});
3838
});
3939
}
@@ -46,14 +46,15 @@ public void Serialize_EmptyDictionary_IsIncluded()
4646
DictionaryImplementation = new Dictionary<string, int>()
4747
};
4848

49-
DictionaryClassMarshaller
50-
.Marshall(@class)
49+
var result = DictionaryClassMarshaller.Marshall(@class);
50+
result
5151
.Should()
5252
.NotBeEmpty()
5353
.And
54-
.ContainKey(nameof(DictionaryClass.DictionaryImplementation))
55-
.And
56-
.ContainSingle(x => x.Value.L.Count == 0);
54+
.ContainKey(nameof(DictionaryClass.DictionaryImplementation));
55+
56+
result[nameof(DictionaryClass.DictionaryImplementation)].M.Should().BeEmpty();
57+
5758
}
5859
}
5960

0 commit comments

Comments
 (0)