From fd7ca999c3923eefb87da17b3336c9e553a89b0e Mon Sep 17 00:00:00 2001 From: Jonas Ha Date: Fri, 16 Jan 2026 18:47:06 -0500 Subject: [PATCH] feat(dynamo-mapper): add generator tests for various custom field formats - Introduced tests to validate mapping with custom formats including DateTime, Guid, and Enum. - Covered multiple formats like "N", "D", and "yyyy-MM-ddTHH:mm:ssK". - Verified behavior for nullable types and conflicting format settings. - Ensured non-formattable types gracefully ignore invalid formatting. --- .../Options/DynamoFieldOptions.cs | 1 + .../TypeMappingStrategyResolver.cs | 52 +-- .../DynamoFieldAttribute.cs | 38 ++ .../DynamoFieldFormatVerifyTests.cs | 374 ++++++++++++++++++ ...s_SingleMapper#ProductMapper.g.verified.cs | 45 +++ ...thCustomFormat#ProductMapper.g.verified.cs | 37 ++ ...thCustomFormat#ProductMapper.g.verified.cs | 37 ++ ...hDecimalFormat#ProductMapper.g.verified.cs | 37 ++ ...MapperDefaults#ProductMapper.g.verified.cs | 43 ++ ...id_WithNFormat#ProductMapper.g.verified.cs | 37 ++ ...fferentFormats#ProductMapper.g.verified.cs | 43 ++ ...rmat_IsIgnored#ProductMapper.g.verified.cs | 37 ++ ...ypesWithFormat#ProductMapper.g.verified.cs | 43 ++ ...eralLongFormat#ProductMapper.g.verified.cs | 37 ++ 14 files changed, 835 insertions(+), 26 deletions(-) create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/DynamoFieldFormatVerifyTests.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.AllFormattableTypes_SingleMapper#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTimeOffset_WithCustomFormat#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTime_WithCustomFormat#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Enum_WithDecimalFormat#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.FormatOverrideWithMapperDefaults#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Guid_WithNFormat#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.MultiplePropertiesWithDifferentFormats#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NonFormattableTypeWithFormat_IsIgnored#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NullableTypesWithFormat#ProductMapper.g.verified.cs create mode 100644 test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.TimeSpan_WithGeneralLongFormat#ProductMapper.g.verified.cs diff --git a/src/LayeredCraft.DynamoMapper.Generators/Options/DynamoFieldOptions.cs b/src/LayeredCraft.DynamoMapper.Generators/Options/DynamoFieldOptions.cs index a22cac3..7bc542f 100644 --- a/src/LayeredCraft.DynamoMapper.Generators/Options/DynamoFieldOptions.cs +++ b/src/LayeredCraft.DynamoMapper.Generators/Options/DynamoFieldOptions.cs @@ -12,4 +12,5 @@ internal class DynamoFieldOptions public bool? OmitIfEmptyString { get; set; } public string? ToMethod { get; set; } public string? FromMethod { get; set; } + public string? Format { get; set; } } diff --git a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs index e6d67ff..4df6e3b 100644 --- a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs +++ b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs @@ -100,37 +100,33 @@ GeneratorContext context "Decimal", analysis.Nullability ), - { SpecialType: SpecialType.System_DateTime } => - $"\"{context.MapperOptions.DateTimeFormat}\"".Map(dateFmt => - CreateStrategy( - "DateTime", - analysis.Nullability, - fromArg: dateFmt, - toArg: dateFmt - ) - ), + { SpecialType: SpecialType.System_DateTime } => CreateStrategy( + "DateTime", + analysis.Nullability, + fromArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.DateTimeFormat}\"", + toArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.DateTimeFormat}\"" + ), INamedTypeSymbol t when t.IsAssignableTo(WellKnownType.System_DateTimeOffset, context) => - $"\"{context.MapperOptions.DateTimeFormat}\"".Map(dateFmt => - CreateStrategy( - "DateTimeOffset", - analysis.Nullability, - fromArg: dateFmt, - toArg: dateFmt - ) + CreateStrategy( + "DateTimeOffset", + analysis.Nullability, + fromArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.DateTimeFormat}\"", + toArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.DateTimeFormat}\"" ), INamedTypeSymbol t when t.IsAssignableTo(WellKnownType.System_Guid, context) => - $"\"{context.MapperOptions.GuidFormat}\"".Map(guidFmt => - CreateStrategy("Guid", analysis.Nullability, fromArg: guidFmt, toArg: guidFmt) + CreateStrategy( + "Guid", + analysis.Nullability, + fromArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.GuidFormat}\"", + toArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.GuidFormat}\"" ), INamedTypeSymbol t when t.IsAssignableTo(WellKnownType.System_TimeSpan, context) => - $"\"{context.MapperOptions.TimeSpanFormat}\"".Map(timeFmt => - CreateStrategy( - "TimeSpan", - analysis.Nullability, - fromArg: timeFmt, - toArg: timeFmt - ) + CreateStrategy( + "TimeSpan", + analysis.Nullability, + fromArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.TimeSpanFormat}\"", + toArg: $"\"{analysis.FieldOptions?.Format ?? context.MapperOptions.TimeSpanFormat}\"" ), INamedTypeSymbol { TypeKind: TypeKind.Enum } enumType => CreateEnumStrategy( enumType, @@ -189,7 +185,11 @@ GeneratorContext context ) { var enumName = enumType.QualifiedName; - var enumFormat = $"\"{context.MapperOptions.EnumFormat}\""; + + // Field-level format override > mapper-level default + var format = analysis.FieldOptions?.Format ?? context.MapperOptions.EnumFormat; + var enumFormat = $"\"{format}\""; + var nullableModifier = analysis.Nullability.IsNullableType ? "Nullable" : ""; // Non-nullable enums need a default value in FromItem diff --git a/src/LayeredCraft.DynamoMapper.Runtime/DynamoFieldAttribute.cs b/src/LayeredCraft.DynamoMapper.Runtime/DynamoFieldAttribute.cs index 9b4b2cb..89f52a1 100644 --- a/src/LayeredCraft.DynamoMapper.Runtime/DynamoFieldAttribute.cs +++ b/src/LayeredCraft.DynamoMapper.Runtime/DynamoFieldAttribute.cs @@ -50,4 +50,42 @@ public DynamoFieldAttribute(string memberName) => /// Method must have signature: static T MethodName(AttributeValue value). /// public string FromMethod { get; set; } = null!; + + /// Gets or sets the format string for types that support formatting. + /// + /// Supported types and their format strings: + /// + /// + /// DateTime / DateTimeOffset + /// Standard or custom format strings (e.g., "O", "yyyy-MM-dd", "MM/dd/yyyy") + /// + /// + /// TimeSpan + /// + /// "c" (constant), "g" (general short), "G" (general long), or custom + /// patterns + /// + /// + /// + /// Guid + /// + /// "N" (32 digits), "D" (hyphens), "B" (braces), "P" (parentheses), "X" + /// (hexadecimal) + /// + /// + /// + /// Enum + /// "G" (general), "F" (flags), "D" (decimal), "X" (hexadecimal) + /// + /// + /// + /// When set, this format overrides the mapper-level format (DateTimeFormat, TimeSpanFormat, + /// GuidFormat, EnumFormat). + /// + /// + /// For types that don't support formatting (string, bool, numeric types), this property is + /// ignored. + /// + /// + public string Format { get; set; } = null!; } diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/DynamoFieldFormatVerifyTests.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/DynamoFieldFormatVerifyTests.cs new file mode 100644 index 0000000..071758d --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/DynamoFieldFormatVerifyTests.cs @@ -0,0 +1,374 @@ +namespace LayeredCraft.DynamoMapper.Generators.Tests; + +public class DynamoFieldFormatVerifyTests +{ + [Fact] + public async Task DateTime_WithCustomFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-dd")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal required DateTime CreatedAt { get; set; } + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task DateTimeOffset_WithCustomFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-ddTHH:mm:ssK")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal required DateTimeOffset CreatedAt { get; set; } + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task Guid_WithNFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Id), Format = "N")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required Guid Id { get; set; } + internal required string Name { get; set; } + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task TimeSpan_WithGeneralLongFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Duration), Format = "G")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal required TimeSpan Duration { get; set; } + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task Enum_WithDecimalFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Status), Format = "D")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal required ProductStatus Status { get; set; } + } + + internal enum ProductStatus + { + Active, + Inactive, + Archived + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task MultiplePropertiesWithDifferentFormats() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Id), Format = "N")] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-dd")] + [DynamoField(nameof(Product.Duration), Format = "G")] + [DynamoField(nameof(Product.Status), Format = "D")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required Guid Id { get; set; } + internal required string Name { get; set; } + internal required DateTime CreatedAt { get; set; } + internal required TimeSpan Duration { get; set; } + internal required ProductStatus Status { get; set; } + } + + internal enum ProductStatus + { + Active, + Inactive, + Archived + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task FormatOverrideWithMapperDefaults() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper(DateTimeFormat = "O", GuidFormat = "D", TimeSpanFormat = "c", EnumFormat = "G")] + [DynamoField(nameof(Product.Id), Format = "N")] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-dd")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required Guid Id { get; set; } + internal required string Name { get; set; } + internal required DateTime CreatedAt { get; set; } + internal required TimeSpan Duration { get; set; } + internal required ProductStatus Status { get; set; } + } + + internal enum ProductStatus + { + Active, + Inactive, + Archived + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task NonFormattableTypeWithFormat_IsIgnored() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Name), Format = "custom-format")] + [DynamoField(nameof(Product.Price), Format = "N2")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal required decimal Price { get; set; } + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task NullableTypesWithFormat() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Id), Format = "N")] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-dd")] + [DynamoField(nameof(Product.Duration), Format = "G")] + [DynamoField(nameof(Product.Status), Format = "D")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required string Name { get; set; } + internal Guid? Id { get; set; } + internal DateTime? CreatedAt { get; set; } + internal TimeSpan? Duration { get; set; } + internal ProductStatus? Status { get; set; } + } + + internal enum ProductStatus + { + Active, + Inactive, + Archived + } + """, + }, + TestContext.Current.CancellationToken + ); + + [Fact] + public async Task AllFormattableTypes_SingleMapper() => + await GeneratorTestHelpers.Verify( + new VerifyTestOptions + { + SourceCode = """ + using System; + using System.Collections.Generic; + using Amazon.DynamoDBv2.Model; + using DynamoMapper.Runtime; + + namespace MyNamespace; + + [DynamoMapper] + [DynamoField(nameof(Product.Id), Format = "N")] + [DynamoField(nameof(Product.CreatedAt), Format = "yyyy-MM-dd")] + [DynamoField(nameof(Product.UpdatedAt), Format = "yyyy-MM-ddTHH:mm:ssK")] + [DynamoField(nameof(Product.Duration), Format = "G")] + [DynamoField(nameof(Product.Status), Format = "D")] + internal static partial class ProductMapper + { + internal static partial Dictionary ToItem(Product source); + internal static partial Product FromItem(Dictionary item); + } + + internal class Product + { + internal required Guid Id { get; set; } + internal required string Name { get; set; } + internal required DateTime CreatedAt { get; set; } + internal required DateTimeOffset UpdatedAt { get; set; } + internal required TimeSpan Duration { get; set; } + internal required ProductStatus Status { get; set; } + } + + internal enum ProductStatus + { + Active, + Inactive, + Archived + } + """, + }, + TestContext.Current.CancellationToken + ); +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.AllFormattableTypes_SingleMapper#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.AllFormattableTypes_SingleMapper#ProductMapper.g.verified.cs new file mode 100644 index 0000000..d00cc10 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.AllFormattableTypes_SingleMapper#ProductMapper.g.verified.cs @@ -0,0 +1,45 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(6) + .SetGuid("id", source.Id, "N", false, true) + .SetString("name", source.Name, false, true) + .SetDateTime("createdAt", source.CreatedAt, "yyyy-MM-dd", false, true) + .SetDateTimeOffset("updatedAt", source.UpdatedAt, "yyyy-MM-ddTHH:mm:ssK", false, true) + .SetTimeSpan("duration", source.Duration, "G", false, true) + .SetEnum("status", source.Status, "D", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Id = item.GetGuid("id", format: "N", Requiredness.InferFromNullability), + Name = item.GetString("name", Requiredness.InferFromNullability), + CreatedAt = item.GetDateTime("createdAt", format: "yyyy-MM-dd", Requiredness.InferFromNullability), + UpdatedAt = item.GetDateTimeOffset("updatedAt", format: "yyyy-MM-ddTHH:mm:ssK", Requiredness.InferFromNullability), + Duration = item.GetTimeSpan("duration", format: "G", Requiredness.InferFromNullability), + Status = item.GetEnum("status", global::MyNamespace.ProductStatus.Active, format: "D", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTimeOffset_WithCustomFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTimeOffset_WithCustomFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..136bffa --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTimeOffset_WithCustomFormat#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetString("name", source.Name, false, true) + .SetDateTimeOffset("createdAt", source.CreatedAt, "yyyy-MM-ddTHH:mm:ssK", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + CreatedAt = item.GetDateTimeOffset("createdAt", format: "yyyy-MM-ddTHH:mm:ssK", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTime_WithCustomFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTime_WithCustomFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..3648bb5 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.DateTime_WithCustomFormat#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetString("name", source.Name, false, true) + .SetDateTime("createdAt", source.CreatedAt, "yyyy-MM-dd", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + CreatedAt = item.GetDateTime("createdAt", format: "yyyy-MM-dd", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Enum_WithDecimalFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Enum_WithDecimalFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..dc378b7 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Enum_WithDecimalFormat#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetString("name", source.Name, false, true) + .SetEnum("status", source.Status, "D", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + Status = item.GetEnum("status", global::MyNamespace.ProductStatus.Active, format: "D", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.FormatOverrideWithMapperDefaults#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.FormatOverrideWithMapperDefaults#ProductMapper.g.verified.cs new file mode 100644 index 0000000..f3e8580 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.FormatOverrideWithMapperDefaults#ProductMapper.g.verified.cs @@ -0,0 +1,43 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(5) + .SetGuid("id", source.Id, "N", false, true) + .SetString("name", source.Name, false, true) + .SetDateTime("createdAt", source.CreatedAt, "yyyy-MM-dd", false, true) + .SetTimeSpan("duration", source.Duration, "c", false, true) + .SetEnum("status", source.Status, "G", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Id = item.GetGuid("id", format: "N", Requiredness.InferFromNullability), + Name = item.GetString("name", Requiredness.InferFromNullability), + CreatedAt = item.GetDateTime("createdAt", format: "yyyy-MM-dd", Requiredness.InferFromNullability), + Duration = item.GetTimeSpan("duration", format: "c", Requiredness.InferFromNullability), + Status = item.GetEnum("status", global::MyNamespace.ProductStatus.Active, format: "G", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Guid_WithNFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Guid_WithNFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..f146987 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.Guid_WithNFormat#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetGuid("id", source.Id, "N", false, true) + .SetString("name", source.Name, false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Id = item.GetGuid("id", format: "N", Requiredness.InferFromNullability), + Name = item.GetString("name", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.MultiplePropertiesWithDifferentFormats#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.MultiplePropertiesWithDifferentFormats#ProductMapper.g.verified.cs new file mode 100644 index 0000000..cb061b3 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.MultiplePropertiesWithDifferentFormats#ProductMapper.g.verified.cs @@ -0,0 +1,43 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(5) + .SetGuid("id", source.Id, "N", false, true) + .SetString("name", source.Name, false, true) + .SetDateTime("createdAt", source.CreatedAt, "yyyy-MM-dd", false, true) + .SetTimeSpan("duration", source.Duration, "G", false, true) + .SetEnum("status", source.Status, "D", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Id = item.GetGuid("id", format: "N", Requiredness.InferFromNullability), + Name = item.GetString("name", Requiredness.InferFromNullability), + CreatedAt = item.GetDateTime("createdAt", format: "yyyy-MM-dd", Requiredness.InferFromNullability), + Duration = item.GetTimeSpan("duration", format: "G", Requiredness.InferFromNullability), + Status = item.GetEnum("status", global::MyNamespace.ProductStatus.Active, format: "D", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NonFormattableTypeWithFormat_IsIgnored#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NonFormattableTypeWithFormat_IsIgnored#ProductMapper.g.verified.cs new file mode 100644 index 0000000..b35d07a --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NonFormattableTypeWithFormat_IsIgnored#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetString("name", source.Name, false, true) + .SetDecimal("price", source.Price, false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + Price = item.GetDecimal("price", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NullableTypesWithFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NullableTypesWithFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..12ba0e6 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.NullableTypesWithFormat#ProductMapper.g.verified.cs @@ -0,0 +1,43 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(5) + .SetString("name", source.Name, false, true) + .SetGuid("id", source.Id, "N", false, true) + .SetDateTime("createdAt", source.CreatedAt, "yyyy-MM-dd", false, true) + .SetTimeSpan("duration", source.Duration, "G", false, true) + .SetEnum("status", source.Status, "D", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + Id = item.GetNullableGuid("id", format: "N", Requiredness.InferFromNullability), + CreatedAt = item.GetNullableDateTime("createdAt", format: "yyyy-MM-dd", Requiredness.InferFromNullability), + Duration = item.GetNullableTimeSpan("duration", format: "G", Requiredness.InferFromNullability), + Status = item.GetNullableEnum("status", format: "D", Requiredness.InferFromNullability), + }; + return product; + } +} diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.TimeSpan_WithGeneralLongFormat#ProductMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.TimeSpan_WithGeneralLongFormat#ProductMapper.g.verified.cs new file mode 100644 index 0000000..19eaeb5 --- /dev/null +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/DynamoFieldFormatVerifyTests.TimeSpan_WithGeneralLongFormat#ProductMapper.g.verified.cs @@ -0,0 +1,37 @@ +//HintName: ProductMapper.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +#nullable enable + +using DynamoMapper.Runtime; +using System.Collections.Generic; +using Amazon.DynamoDBv2.Model; + +namespace MyNamespace; + +internal static partial class ProductMapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::System.Collections.Generic.Dictionary ToItem(global::MyNamespace.Product source) => + new Dictionary(2) + .SetString("name", source.Name, false, true) + .SetTimeSpan("duration", source.Duration, "G", false, true); + + [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] + internal static partial global::MyNamespace.Product FromItem(global::System.Collections.Generic.Dictionary item) + { + var product = new global::MyNamespace.Product + { + Name = item.GetString("name", Requiredness.InferFromNullability), + Duration = item.GetTimeSpan("duration", format: "G", Requiredness.InferFromNullability), + }; + return product; + } +}