From 56965c219d2beae78cb682e8b338f48826f51964 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Sat, 28 Jun 2025 17:24:00 +0200 Subject: [PATCH 1/2] Use MarshalHelper when Unmarshalling & Marshalling sets --- .../Constants.cs | 6 +- .../Generations/Marshalling/Marshaller.cs | 4 +- .../Generations/UnMarshaller.cs | 2 +- .../Types/TypeIdentifier.cs | 13 +- .../DynamoDBGenerator.csproj | 1 - .../Internal/MarshallHelper.cs | 226 +++++++++++++++++- .../Marshaller/Asserters/MarshalAsserter.cs | 7 +- .../Generics/Sets/DecimalHashSetTests.cs | 22 ++ .../Generics/Sets/DecimalIReadOnlySetTests.cs | 21 ++ .../Generics/Sets/DecimalISetTests.cs | 21 ++ .../Generics/Sets/DecimalSortedSetTests.cs | 21 ++ .../Generics/Sets/IntHashSetTests.cs | 35 --- .../Generics/Sets/IntIReadOnlySetTests.cs | 21 ++ .../Marshaller/Generics/Sets/IntISetTests.cs | 21 ++ .../Generics/Sets/IntSortedSetTests.cs | 21 ++ .../Sets/NullableDecimalHashSetTests.cs | 22 ++ .../Sets/NullableDecimalIReadOnlySetTests.cs | 20 ++ .../Generics/Sets/NullableDecimalISetTests.cs | 20 ++ .../Sets/NullableDecimalSortedSetTests.cs | 22 ++ .../Generics/Sets/NullableIntHashSetTests.cs | 22 ++ .../Sets/NullableIntIReadOnlyTests.cs | 22 ++ .../Generics/Sets/NullableIntISetTests.cs | 22 ++ .../Generics/Sets/NullableIntSortedSet.cs | 22 ++ ...Tests.cs => NullableStringHashSetTests.cs} | 2 +- ....cs => NullableStringIReadOnlySetTests.cs} | 2 +- ...SetTests.cs => NullableStringISetTests.cs} | 2 +- ...sts.cs => NullableStringSortedSetTests.cs} | 2 +- ...tedSetTests.cs => SortedStringSetTests.cs} | 2 +- ...{HashSetTests.cs => StringHashSetTests.cs} | 2 +- ...SetTests.cs => StringIReadOnlySetTests.cs} | 2 +- .../Sets/{ISetTests.cs => StringISetTests.cs} | 2 +- 31 files changed, 568 insertions(+), 62 deletions(-) create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalHashSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalIReadOnlySetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalISetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalSortedSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntIReadOnlySetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntISetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntSortedSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalHashSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalIReadOnlySetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalISetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalSortedSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntHashSetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntIReadOnlyTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntISetTests.cs create mode 100644 tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntSortedSet.cs rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{NullableHashSetTests.cs => NullableStringHashSetTests.cs} (85%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{NullableIReadOnlySetTests.cs => NullableStringIReadOnlySetTests.cs} (87%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{NullableISetTests.cs => NullableStringISetTests.cs} (88%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{NullableSortedSetTests.cs => NullableStringSortedSetTests.cs} (84%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{SortedSetTests.cs => SortedStringSetTests.cs} (88%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{HashSetTests.cs => StringHashSetTests.cs} (95%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{IReadOnlySetTests.cs => StringIReadOnlySetTests.cs} (96%) rename tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/{ISetTests.cs => StringISetTests.cs} (88%) diff --git a/src/DynamoDBGenerator.SourceGenerator/Constants.cs b/src/DynamoDBGenerator.SourceGenerator/Constants.cs index d50bf8fa..69e49865 100644 --- a/src/DynamoDBGenerator.SourceGenerator/Constants.cs +++ b/src/DynamoDBGenerator.SourceGenerator/Constants.cs @@ -80,7 +80,7 @@ public static class Marshaller public static class AttributeValueUtilityFactory { - private const string ClassName = "MarshallHelper"; + public const string ClassName = "MarshallHelper"; public const string ToAttributeValue = $"{ClassName}.ToAttributeValue"; public const string Null = $"{ClassName}.Null"; public const string ToList = $"{ClassName}.ToList"; @@ -93,6 +93,10 @@ public static class AttributeValueUtilityFactory public const string ToDictionary = $"{ClassName}.ToDictionary"; public const string ToLookup = $"{ClassName}.ToLookup"; public const string FromLookup = $"{ClassName}.FromLookup"; + public const string FromStringSet = $"{ClassName}.FromStringSet"; + public const string FromNullableStringSet = $"{ClassName}.FromNullableStringSet"; + public const string FromNumberSet = $"{ClassName}.FromNumberSet"; + public const string FromNullableNumberSet = $"{ClassName}.FromNullableNumberSet"; } public static class ExceptionHelper { diff --git a/src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs b/src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs index 9b2310e7..1afa35f7 100644 --- a/src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs +++ b/src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs @@ -125,7 +125,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.TypeSymbol.SpecialType is S .CreateScope( $"if ({ParamReference} is null)" .CreateScope(singleGeneric.ReturnNullOrThrow(DataMember)) - .Append($"return new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ SS = new List<{(singleGeneric.T.IsSupposedToBeNull ? "string?" : "string")}>({(singleGeneric.T.IsSupposedToBeNull ? ParamReference : $"{ParamReference}.Select((y,i) => y ?? throw {ExceptionHelper.NullExceptionMethod}($\"{{{DataMember}}}[UNKNOWN]\"))")})}};") + .Append($"return {(singleGeneric.T.IsSupposedToBeNull ? AttributeValueUtilityFactory.FromNullableStringSet : AttributeValueUtilityFactory.FromStringSet)}({ParamReference}, {DataMember});") ) .ToConversion(singleGeneric.T), SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric @@ -133,7 +133,7 @@ SingleGeneric.SupportedType.Set when singleGeneric.T.IsNumeric .CreateScope( $"if ({ParamReference} is null)" .CreateScope(singleGeneric.ReturnNullOrThrow(DataMember)) - .Append($"return new {Constants.AWSSDK_DynamoDBv2.AttributeValue} {{ NS = new List({ParamReference}.Select(y => y.ToString())) }};") + .Append($"return {(singleGeneric.T.IsSupposedToBeNull ? AttributeValueUtilityFactory.FromNullableNumberSet : AttributeValueUtilityFactory.FromNumberSet)}({ParamReference}, {DataMember});") ) .ToConversion(singleGeneric.T), SingleGeneric.SupportedType.Set => throw new ArgumentException("Only string and integers are supported for sets", UncoveredConversionException(singleGeneric, nameof(CreateMethod))), diff --git a/src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs b/src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs index 31b23162..ec40362e 100644 --- a/src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs +++ b/src/DynamoDBGenerator.SourceGenerator/Generations/UnMarshaller.cs @@ -139,7 +139,7 @@ private static CodeFactory CreateMethod(TypeIdentifier typeIdentifier, Func" : null)}({Value}.NS.Select(y => {singleGeneric.T.UnannotatedString}.Parse(y)));") + .Append($"return {AttributeValueUtilityFactory.ClassName}.{(singleGeneric.T.IsSupposedToBeNull ? $"ToNullableNumber{typeIdentifier.TypeSymbol.Name}" : $"ToNumber{typeIdentifier.TypeSymbol.Name}")}<{singleGeneric.T.UnannotatedString}>({Value}.NS, {DataMember});") ) .ToConversion(singleGeneric), SingleGeneric.SupportedType.Set => throw new ArgumentException("Only string and integers are supported for sets", UncoveredConversionException(singleGeneric, nameof(CreateMethod))), diff --git a/src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs b/src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs index f90a2986..58437227 100644 --- a/src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs +++ b/src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs @@ -31,8 +31,8 @@ protected TypeIdentifier(ITypeSymbol typeSymbol) var (annotated, original) = Representation(typeSymbol); UnannotatedString = original; AnnotatedString = annotated; - IsNumeric = IsNumericMethod(typeSymbol); CanBeNull = typeSymbol is { IsReferenceType: true } or { IsValueType: true, OriginalDefinition.SpecialType: SpecialType.System_Nullable_T }; + IsNumeric = IsNumericMethod(typeSymbol); } /// @@ -54,7 +54,12 @@ private static (string annotated, string original) Representation(ITypeSymbol ty return RepresentationDictionary.GetOrAdd(typeSymbol, x => { var displayString = x.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - return RepresentationDictionary[typeSymbol] = (ToString(typeSymbol, displayString), displayString); + + var unAnnotated = x.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T + ? displayString.Substring(0, displayString.Length - 1) + : displayString; + + return RepresentationDictionary[typeSymbol] = (ToString(typeSymbol, displayString), unAnnotated); }); static string ToString(ITypeSymbol x, string displayString) @@ -118,6 +123,9 @@ static string ExceptionMessage(ISymbol typeSymbol) private static bool IsNumericMethod(ITypeSymbol typeSymbol) { + if (typeSymbol.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) + typeSymbol = ((INamedTypeSymbol)typeSymbol).TypeArguments[0]; + return typeSymbol.SpecialType is SpecialType.System_Int16 or SpecialType.System_Byte @@ -130,6 +138,7 @@ or SpecialType.System_UInt64 or SpecialType.System_Decimal or SpecialType.System_Double or SpecialType.System_Single; + } public string ReturnNullOrThrow(string dataMember) diff --git a/src/DynamoDBGenerator/DynamoDBGenerator.csproj b/src/DynamoDBGenerator/DynamoDBGenerator.csproj index 03fe0451..55e0489b 100644 --- a/src/DynamoDBGenerator/DynamoDBGenerator.csproj +++ b/src/DynamoDBGenerator/DynamoDBGenerator.csproj @@ -4,7 +4,6 @@ net8.0 enable true - 10.0 0.0.0 DynamoDBGenerator Robert Andersson diff --git a/src/DynamoDBGenerator/Internal/MarshallHelper.cs b/src/DynamoDBGenerator/Internal/MarshallHelper.cs index 9e686375..cbb88c45 100644 --- a/src/DynamoDBGenerator/Internal/MarshallHelper.cs +++ b/src/DynamoDBGenerator/Internal/MarshallHelper.cs @@ -1,8 +1,9 @@ using System; -using System.Buffers; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Numerics; +using System.Runtime.CompilerServices; using Amazon.DynamoDBv2.Model; using static System.Runtime.InteropServices.CollectionsMarshal; @@ -22,9 +23,12 @@ public static class MarshallHelper [return: NotNullIfNotNull(nameof(dict))] public static AttributeValue? ToAttributeValue( [NotNullIfNotNull(nameof(dict))] Dictionary? dict - ) => dict is null - ? null - : new AttributeValue { M = dict }; + ) + { + return dict is null + ? null + : new AttributeValue { M = dict }; + } public static AttributeValue FromDictionary( IEnumerable> dictionary, @@ -45,6 +49,203 @@ public static AttributeValue FromDictionary( return new AttributeValue { M = elements }; } + public static AttributeValue FromNullableNumberSet(IEnumerable numbers, string? _) + where T : struct, INumber + { + if (numbers.TryGetNonEnumeratedCount(out var count) is false) + return new AttributeValue + { + NS = numbers.Select(number => number?.ToString()).ToList() + }; + + if (count is 0) + return new AttributeValue { NS = [] }; + + var list = new List(count); + list.AddRange(numbers.Select(number => number?.ToString())); + + return new AttributeValue { NS = list }; + } + + public static AttributeValue FromNumberSet(IEnumerable numbers, string? dataMember) + where T : struct, INumber + { + if (numbers.TryGetNonEnumeratedCount(out var count) is false) + { + var noCapacity = new List(); + + foreach (var number in numbers) + { + var @string = number.ToString(); + if (string.IsNullOrEmpty(@string)) + throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]"); + + noCapacity.Add(@string); + } + + return new AttributeValue { NS = noCapacity }; + } + + if (count is 0) + return new AttributeValue { NS = [] }; + + var list = new List(count); + + foreach (var number in numbers) + { + var @string = number.ToString(); + if (string.IsNullOrEmpty(@string)) + throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]"); + + list.Add(@string); + } + + return new AttributeValue { NS = list }; + } + + public static AttributeValue FromNullableStringSet(IEnumerable strings, string? _) + { + if (strings.TryGetNonEnumeratedCount(out var count) is false) + return new AttributeValue { SS = strings.ToList() }; + + if (count is 0) + return new AttributeValue { SS = [] }; + + var list = new List(count); + list.AddRange(strings); + + return new AttributeValue { SS = list }; + } + + public static AttributeValue FromStringSet(IEnumerable strings, string? dataMember) + { + if (strings.TryGetNonEnumeratedCount(out var count) is false) + { + var list = new List(); + foreach (var @string in strings) + { + if (@string is null) + throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]"); + list.Add(@string); + } + + return new AttributeValue { SS = list }; + } + else + { + if (count is 0) + return new AttributeValue { SS = [] }; + + var list = new List(count); + + foreach (var @string in strings) + list.Add(@string ?? throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]")); + + return new AttributeValue { SS = list }; + } + } + + private static TSet ToNumberSet( + List numbers, + Func factory, + string? dataMember + ) + where TSet : ICollection + where TNumber : struct, INumber + { + var span = AsSpan(numbers); + var set = factory(span.Length); + + foreach (var number in span) + { + if (number is null) + throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]"); + + set.Add(TNumber.Parse(number, null)); + } + + return set; + } + + private static TSet ToNullableNumberSet( + List numbers, + Func factory, + string? _ + ) + where TSet : ICollection + where TNumber : struct, INumber + { + var span = AsSpan(numbers); + var set = factory(span.Length); + + foreach (var number in span) + { + if (number is null) + set.Add(null); + else + set.Add(TNumber.Parse(number, null)); + } + + return set; + } + + public static ISet ToNumberISet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static IReadOnlySet ToNumberIReadOnlySet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static HashSet ToNumberHashSet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static SortedSet ToNumberSortedSet(List ns, string? dataMember) + where TNumber : struct, INumber + { + var span = AsSpan(ns); + var set = new SortedSet(); + foreach (var se in span) + { + if (se is null) + throw ExceptionHelper.NotNull($"{dataMember}[UNKNOWN]"); + + set.Add(TNumber.Parse(se, null)); + } + + return set; + } + + public static ISet ToNullableNumberISet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNullableNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static IReadOnlySet ToNullableNumberIReadOnlySet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNullableNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static HashSet ToNullableNumberHashSet(List ns, string? dataMember) + where TNumber : struct, INumber + { + return ToNullableNumberSet>(ns, i => new HashSet(i), dataMember); + } + + public static SortedSet ToNullableNumberSortedSet(List ns, string? _) + where TNumber : struct, INumber + { + return new SortedSet(ns.Select(x => x is null ? (TNumber?)null : TNumber.Parse(x, null))); + } public static ILookup ToLookup( Dictionary dictionary, @@ -134,15 +335,20 @@ public static AttributeValue FromEnumerable( string? dataMember, Func resultSelector) { - var attributeValues = enumerable.TryGetNonEnumeratedCount(out var count) - ? new List(count) - : new List(); + if (enumerable.TryGetNonEnumeratedCount(out var count) is false) + return new AttributeValue + { + L = [..enumerable.Select((element, i) => resultSelector(element, argument, $"{dataMember}[{i}]"))] + }; + if (count == 0) + return new AttributeValue { L = [] }; + + var list = new List(count); foreach (var (element, i) in enumerable.Select((x, y) => (x, y))) - attributeValues.Add(resultSelector(element, argument, $"{dataMember}[{i}]")); + list.Add(resultSelector(element, argument, $"{dataMember}[{i}]")); - - return new AttributeValue { L = attributeValues }; + return new AttributeValue { L = list }; } public static List ToList( diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Asserters/MarshalAsserter.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Asserters/MarshalAsserter.cs index 97d27102..da98e388 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Asserters/MarshalAsserter.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Asserters/MarshalAsserter.cs @@ -33,8 +33,11 @@ public void Marshall_IsEquivalentTo_UnmarshallResult() public void UnMarshall_IsEquivalentTo_MarshallResult() { Arguments().Should().AllSatisfy(x => - MarshallImplementation(UnmarshallImplementation(x.attributeValues)).Should() - .BeEquivalentTo(x.attributeValues)); + { + var unmarshallImplementation = UnmarshallImplementation(x.attributeValues); + var marshallImplementation = MarshallImplementation(unmarshallImplementation); + marshallImplementation.Should().BeEquivalentTo(x.attributeValues); + }); } [Fact] diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalHashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalHashSetTests.cs new file mode 100644 index 00000000..0ff291b4 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalHashSetTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class DecimalHashSetTests() + : SetAsserter, decimal>([2032m, 0.323232932m, 0.9329392m], x => new HashSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalIReadOnlySetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalIReadOnlySetTests.cs new file mode 100644 index 00000000..66b7294d --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalIReadOnlySetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class DecimalIReadOnlySetTests() : SetAsserter, decimal>([2032m, 0.323232932m, 0.9329392m], x => new HashSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalISetTests.cs new file mode 100644 index 00000000..fce0ea98 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalISetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class DecimalISetTests() : SetAsserter, decimal>([2032m, 0.323232932m, 0.9329392m], x => new HashSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalSortedSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalSortedSetTests.cs new file mode 100644 index 00000000..1f81991d --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/DecimalSortedSetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class DecimalSortedSetTests() : SetAsserter, decimal>([2032m, 0.323232932m, 0.9329392m], x => new SortedSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntHashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntHashSetTests.cs index 9a7d6871..c8b9f0cd 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntHashSetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntHashSetTests.cs @@ -18,39 +18,4 @@ protected override Container> UnmarshallImplementation( { return ContainerMarshaller.Unmarshall(attributeValues); } -} - -// TODO Support -//[DynamoDBMarshaller(EntityType = typeof(Container>))] -//public partial class NUllableIntHashSetTests() : SetAsserter, int?>([2, 3, 4, 5], x => new HashSet(x)) -//{ -// protected override Container> UnmarshallImplementation( -// Dictionary attributeValues) -// { -// return ContainerMarshaller.Unmarshall(attributeValues); -// } -// -// protected override Dictionary MarshallImplementation(Container> element) -// { -// return ContainerMarshaller.Marshall(element); -// } -//} - -[DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class DecimalHashSetTests : SetAsserter, decimal> -{ - public DecimalHashSetTests() : base(new[] { 2032m, 0.323232932m, 0.9329392m }, x => new HashSet(x)) - { - } - - protected override Dictionary MarshallImplementation(Container> element) - { - return ContainerMarshaller.Marshall(element); - } - - protected override Container> UnmarshallImplementation( - Dictionary attributeValues) - { - return ContainerMarshaller.Unmarshall(attributeValues); - } } \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntIReadOnlySetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntIReadOnlySetTests.cs new file mode 100644 index 00000000..5913f026 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntIReadOnlySetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class IntIReadOnlySetTests() : SetAsserter, int>([2, 3, 4, 5], x => new HashSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntISetTests.cs new file mode 100644 index 00000000..26b4c3ed --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntISetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class IntISetTests() : SetAsserter, int>([2, 3, 4, 5], x => new HashSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntSortedSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntSortedSetTests.cs new file mode 100644 index 00000000..ea9bd50e --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IntSortedSetTests.cs @@ -0,0 +1,21 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class IntSortedSetTests() : SetAsserter, int>([2, 3, 4, 5], x => new SortedSet(x)) +{ + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } + + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalHashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalHashSetTests.cs new file mode 100644 index 00000000..d9dd2789 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalHashSetTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableDecimalHashSetTests() + : SetAsserter, decimal?>([2032m, 0.323232932m, 0.9329392m, null], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalIReadOnlySetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalIReadOnlySetTests.cs new file mode 100644 index 00000000..b3f143f5 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalIReadOnlySetTests.cs @@ -0,0 +1,20 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableDecimalIReadOnlySetTests() : SetAsserter, decimal?>([2032m, 0.323232932m, 0.9329392m, null], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation(Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalISetTests.cs new file mode 100644 index 00000000..a95f3a49 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalISetTests.cs @@ -0,0 +1,20 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableDecimalISetTests() : SetAsserter, decimal?>([2032m, 0.323232932m, 0.9329392m, null], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation(Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalSortedSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalSortedSetTests.cs new file mode 100644 index 00000000..e656c0f1 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableDecimalSortedSetTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableDecimalSortedSetTests() : SetAsserter, decimal?>([2032m, 0.323232932m, 0.9329392m, null], + x => new SortedSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntHashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntHashSetTests.cs new file mode 100644 index 00000000..ae08ab77 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntHashSetTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableIntHashSetTests() + : SetAsserter, int?>([2, 3, null, 4, 5], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntIReadOnlyTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntIReadOnlyTests.cs new file mode 100644 index 00000000..c7557fa0 --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntIReadOnlyTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableIntIReadOnlyTests() : SetAsserter, int?>([2, 3, null, 4, 5], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues + ) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntISetTests.cs new file mode 100644 index 00000000..5a09943d --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntISetTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableIntISetTests() : SetAsserter, int?>([2, 3, null, 4, 5], x => new HashSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues + ) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntSortedSet.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntSortedSet.cs new file mode 100644 index 00000000..e9f67b1e --- /dev/null +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIntSortedSet.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.Model; +using DynamoDBGenerator.Attributes; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Asserters; +using DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets.Asserters; + +namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; + +[DynamoDBMarshaller(EntityType = typeof(Container>))] +public partial class NullableIntSortedSet() : SetAsserter, int?>([2, 3, null, 4, 5], x => new SortedSet(x)) +{ + protected override Container> UnmarshallImplementation( + Dictionary attributeValues + ) + { + return ContainerMarshaller.Unmarshall(attributeValues); + } + + protected override Dictionary MarshallImplementation(Container> element) + { + return ContainerMarshaller.Marshall(element); + } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableHashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringHashSetTests.cs similarity index 85% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableHashSetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringHashSetTests.cs index d0d2bc69..59bd5ef9 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableHashSetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringHashSetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class NullableHashSetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) +public partial class NullableStringHashSetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) { protected override Container> UnmarshallImplementation(Dictionary attributeValues) { diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIReadOnlySetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringIReadOnlySetTests.cs similarity index 87% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIReadOnlySetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringIReadOnlySetTests.cs index 2c630913..99d50198 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableIReadOnlySetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringIReadOnlySetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class NullableIReadOnlySetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) +public partial class NullableStringIReadOnlySetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) { protected override Dictionary MarshallImplementation(Container> element) { diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringISetTests.cs similarity index 88% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableISetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringISetTests.cs index fa0da1e8..dcc13831 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableISetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringISetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class NullableISetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) +public partial class NullableStringISetTests() : NullableElementAsserter, string>(Strings(), x => new HashSet(x)) { protected override Dictionary MarshallImplementation(Container> element) { diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableSortedSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringSortedSetTests.cs similarity index 84% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableSortedSetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringSortedSetTests.cs index a364122e..6fd82c9b 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableSortedSetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/NullableStringSortedSetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class NullableSortedSetTests() : NullableElementAsserter, string>(Strings(), x => new SortedSet(x)) +public partial class NullableStringSortedSetTests() : NullableElementAsserter, string>(Strings(), x => new SortedSet(x)) { protected override Container> UnmarshallImplementation( Dictionary attributeValues) diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedStringSetTests.cs similarity index 88% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedSetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedStringSetTests.cs index 9bb2d913..a521925e 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedSetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/SortedStringSetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class SortedSetTests() : NoneNullableElementAsserter, string>(Strings(), x => new SortedSet(x)) +public partial class SortedStringSetTests() : NoneNullableElementAsserter, string>(Strings(), x => new SortedSet(x)) { protected override Dictionary MarshallImplementation(Container> element) { diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/HashSetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringHashSetTests.cs similarity index 95% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/HashSetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringHashSetTests.cs index 5e82a6a7..e81678ea 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/HashSetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringHashSetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class HashSetTests() +public partial class StringHashSetTests() : NoneNullableElementAsserter, string>(Strings(), x => new HashSet(x)) { protected override Dictionary MarshallImplementation(Container> element) diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IReadOnlySetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringIReadOnlySetTests.cs similarity index 96% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IReadOnlySetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringIReadOnlySetTests.cs index b85fa939..5b7c8ebb 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/IReadOnlySetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringIReadOnlySetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class IReadOnlySetTests() +public partial class StringIReadOnlySetTests() : NoneNullableElementAsserter, string>(Strings(), x => new SortedSet(x)) { protected override Dictionary MarshallImplementation( diff --git a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/ISetTests.cs b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringISetTests.cs similarity index 88% rename from tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/ISetTests.cs rename to tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringISetTests.cs index aa6e0533..cebc1975 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/ISetTests.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Tests/DynamoDBDocumentTests/Marshaller/Generics/Sets/StringISetTests.cs @@ -6,7 +6,7 @@ namespace DynamoDBGenerator.SourceGenerator.Tests.DynamoDBDocumentTests.Marshaller.Generics.Sets; [DynamoDBMarshaller(EntityType = typeof(Container>))] -public partial class ISetTests() : NoneNullableElementAsserter, string>(Strings(), x => new HashSet(x)) +public partial class StringISetTests() : NoneNullableElementAsserter, string>(Strings(), x => new HashSet(x)) { protected override Dictionary MarshallImplementation(Container> element) { From 566ce93dafa5190dd978d71f4ba61a62c156c68e Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Sun, 29 Jun 2025 01:31:07 +0200 Subject: [PATCH 2/2] Update benchmarks --- README.md | 8 +++---- .../MarshallBenchmark.cs | 3 ++- .../Models/PersonEntity.cs | 10 ++++++-- .../Program.cs | 2 +- .../README.md | 23 ++++++++++--------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e26b6eb6..a8266097 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ Here's a quick summary about how this library performs with a quick example of m | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |---------------------------- |-----------:|---------:|---------:|-------:|-------:|----------:| -| Marshall_AWS_Reflection | 2,467.8 ns | 48.87 ns | 68.51 ns | 0.5112 | 0.0038 | 6450 B | -| Marshall_Source_Generated | 234.0 ns | 2.92 ns | 2.73 ns | 0.1421 | 0.0010 | 1784 B | -| Unmarshall_AWS_Reflection | 2,397.0 ns | 36.13 ns | 30.17 ns | 0.5188 | 0.0038 | 6544 B | -| Unmarshall_Source_Generated | 131.6 ns | 0.82 ns | 0.77 ns | 0.0126 | - | 160 B | +| Marshall_AWS_Reflection | 5,351.9 ns | 74.57 ns | 69.75 ns | 0.8545 | - | 10875 B | +| Marshall_Source_Generated | 488.9 ns | 8.21 ns | 7.68 ns | 0.2375 | 0.0019 | 2984 B | +| Unmarshall_AWS_Reflection | 5,447.3 ns | 68.30 ns | 63.89 ns | 0.8545 | - | 10922 B | +| Unmarshall_Source_Generated | 923.6 ns | 10.92 ns | 10.21 ns | 0.0610 | - | 768 B | ## Features: diff --git a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/MarshallBenchmark.cs b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/MarshallBenchmark.cs index 1bb7c755..4df1dc5e 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/MarshallBenchmark.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/MarshallBenchmark.cs @@ -19,6 +19,7 @@ public class MarshallBenchmark private readonly PersonEntity _singleElement; private readonly Dictionary _attributeValues; + public MarshallBenchmark() { var fixture = new Fixture(); @@ -62,4 +63,4 @@ public PersonEntity Unmarshall_Source_Generated() { return PersonEntity.PersonEntityMarshaller.Unmarshall(_attributeValues); } -} +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PersonEntity.cs b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PersonEntity.cs index 053ff94d..c8cb0928 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PersonEntity.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Models/PersonEntity.cs @@ -1,7 +1,7 @@ using Amazon.DynamoDBv2.DataModel; using DynamoDBGenerator.Attributes; -namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Models; +namespace DynamoDBGenerator.SourceGenerator.Benchmarks.Models; [DynamoDBMarshaller(EntityType = typeof(PersonEntity))] public partial record PersonEntity @@ -11,5 +11,11 @@ public partial record PersonEntity public string Firstname { get; set; } = null!; public string Lastname { get; set; } = null!; + public DateTime BirthDate { get; set; } + public DateTime UpdatedAt { get; set; } + public DateTime InsertedAt { get; set; } + public DateTime? DeletedAt { get; set; } public Address Address { get; set; } = null!; -} + public HashSet StringSet { get; set; } + public HashSet IntSet { get; set; } +} \ No newline at end of file diff --git a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Program.cs b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Program.cs index a475b17d..3501597e 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Program.cs +++ b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/Program.cs @@ -4,4 +4,4 @@ using BenchmarkDotNet.Running; using DynamoDBGenerator.SourceGenerator.Benchmarks; -BenchmarkRunner.Run(); \ No newline at end of file +BenchmarkRunner.Run(); diff --git a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/README.md b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/README.md index af8f2878..08e58e03 100644 --- a/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/README.md +++ b/tests/DynamoDBGenerator.SourceGenerator.Benchmarks/README.md @@ -1,17 +1,18 @@ ``` -BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4541/23H2/2023Update/SunValley3) +BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.4484) Intel Core Ultra 9 185H, 1 CPU, 22 logical and 16 physical cores -.NET SDK 8.0.307 - [Host] : .NET 8.0.11 (8.0.1124.51707), X64 RyuJIT AVX2 - .NET 8.0 : .NET 8.0.11 (8.0.1124.51707), X64 RyuJIT AVX2 +.NET SDK 9.0.107 + [Host] : .NET 8.0.17 (8.0.1725.26602), X64 RyuJIT AVX2 + .NET 8.0 : .NET 8.0.17 (8.0.1725.26602), X64 RyuJIT AVX2 -Job=.NET 8.0 Runtime=.NET 8.0 +Job=.NET 8.0 Runtime=.NET 8.0 ``` -| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | -|--------------- |-----------:|---------:|---------:|-------:|-------:|----------:| -| Marshall_AWS | 2,478.4 ns | 18.54 ns | 28.31 ns | 0.6676 | 0.0076 | 8386 B | -| Marshall_SG | 428.6 ns | 5.97 ns | 10.76 ns | 0.3076 | 0.0038 | 3864 B | -| Unmarshall_AWS | 2,271.2 ns | 17.33 ns | 16.21 ns | 0.5150 | 0.0038 | 6504 B | -| Unmarshall_SG | 126.4 ns | 0.65 ns | 0.58 ns | 0.0126 | - | 160 B | + +| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | +|---------------------------- |-----------:|---------:|---------:|-------:|-------:|----------:| +| Marshall_AWS_Reflection | 5,351.9 ns | 74.57 ns | 69.75 ns | 0.8545 | - | 10875 B | +| Marshall_Source_Generated | 488.9 ns | 8.21 ns | 7.68 ns | 0.2375 | 0.0019 | 2984 B | +| Unmarshall_AWS_Reflection | 5,447.3 ns | 68.30 ns | 63.89 ns | 0.8545 | - | 10922 B | +| Unmarshall_Source_Generated | 923.6 ns | 10.92 ns | 10.21 ns | 0.0610 | - | 768 B |