diff --git a/.claude/commands/pr.md b/.claude/commands/pr.md index 2604542..f2fe7b1 100644 --- a/.claude/commands/pr.md +++ b/.claude/commands/pr.md @@ -1,6 +1,7 @@ # Open PR for current branch - $ARGUMENTS - PR title must follow the format: `(): ` +- If this PR is resolving an issue, mention the issue in the PR. If it closes an issue, use `closes #` in the PR body. - Use this template for the PR: --- @@ -27,6 +28,8 @@ Closes #... +> Related issues or PRs. If this PR closes an issue, mention it here. + --- ## 💬 Notes for Reviewers diff --git a/src/LayeredCraft.DynamoMapper.Generators/Options/MapperOptions.cs b/src/LayeredCraft.DynamoMapper.Generators/Options/MapperOptions.cs index 3805300..3e4de64 100644 --- a/src/LayeredCraft.DynamoMapper.Generators/Options/MapperOptions.cs +++ b/src/LayeredCraft.DynamoMapper.Generators/Options/MapperOptions.cs @@ -10,6 +10,7 @@ internal class MapperOptions internal string TimeSpanFormat { get; set; } = "c"; internal Requiredness DefaultRequiredness { get; set; } = Requiredness.InferFromNullability; internal string EnumFormat { get; set; } = "G"; + internal string GuidFormat { get; set; } = "D"; internal bool OmitEmptyStrings { get; set; } = false; internal bool OmitNullStrings { get; set; } = true; diff --git a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/PropertyMappingSpecBuilder.cs b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/PropertyMappingSpecBuilder.cs index f7da357..d8f6dec 100644 --- a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/PropertyMappingSpecBuilder.cs +++ b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/PropertyMappingSpecBuilder.cs @@ -163,20 +163,11 @@ GeneratorContext context }; // Arguments 3+: Type-specific arguments (format strings) - // Format strings should use named parameters to avoid ambiguity args.AddRange( - strategy.ToTypeSpecificArgs.Select( - (typeArg, index) => - new ArgumentSpec( - // First arg that's a quoted string is typically a format parameter - use - // named parameter - index == 0 - && typeArg.StartsWith("\"") - ? $"format: {typeArg}" - : typeArg, - ArgumentSource.TypeSpecific - ) - ) + strategy.ToTypeSpecificArgs.Select(typeArg => new ArgumentSpec( + typeArg, + ArgumentSource.TypeSpecific + )) ); // Omit flags: field override > global default diff --git a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs index 83ed38c..e6d67ff 100644 --- a/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs +++ b/src/LayeredCraft.DynamoMapper.Generators/PropertyMapping/TypeMappingStrategyResolver.cs @@ -120,7 +120,9 @@ when t.IsAssignableTo(WellKnownType.System_DateTimeOffset, context) => ) ), INamedTypeSymbol t when t.IsAssignableTo(WellKnownType.System_Guid, context) => - CreateStrategy("Guid", analysis.Nullability), + $"\"{context.MapperOptions.GuidFormat}\"".Map(guidFmt => + CreateStrategy("Guid", analysis.Nullability, fromArg: guidFmt, toArg: guidFmt) + ), INamedTypeSymbol t when t.IsAssignableTo(WellKnownType.System_TimeSpan, context) => $"\"{context.MapperOptions.TimeSpanFormat}\"".Map(timeFmt => CreateStrategy( @@ -282,7 +284,7 @@ GeneratorContext context }; // Build strategy - collections are nullable at collection level, not element level - var strategy = CreateStrategy(typeName, analysis.Nullability, genericArg: genericArg); + var strategy = CreateStrategy(typeName, analysis.Nullability, genericArg); // Apply Kind override if present (or use inferred kind) return strategy with diff --git a/src/LayeredCraft.DynamoMapper.Runtime/AttributeValueExtensions/GuidAttributeValueExtensions.cs b/src/LayeredCraft.DynamoMapper.Runtime/AttributeValueExtensions/GuidAttributeValueExtensions.cs index 3f53a8e..1f240fa 100644 --- a/src/LayeredCraft.DynamoMapper.Runtime/AttributeValueExtensions/GuidAttributeValueExtensions.cs +++ b/src/LayeredCraft.DynamoMapper.Runtime/AttributeValueExtensions/GuidAttributeValueExtensions.cs @@ -10,103 +10,16 @@ public static class GuidAttributeValueExtensions { extension(Dictionary attributes) { - /// Tries to get a value from the attribute dictionary. - /// The attribute key to retrieve. - /// The value when found. - /// - /// Specifies whether the attribute is required. Default is - /// . - /// - /// The DynamoDB attribute kind to interpret as a string. - /// true when the key exists and the value is retrieved; otherwise false. - public bool TryGetGuid( - string key, - out Guid value, - Requiredness requiredness = Requiredness.InferFromNullability, - DynamoKind kind = DynamoKind.S - ) - { - value = Guid.Empty; - if (!attributes.TryGetValue(key, requiredness, out var attribute)) - return false; - - var stringValue = attribute!.GetString(kind); - value = stringValue.Length == 0 ? Guid.Empty : Guid.Parse(stringValue); - return true; - } - - /// Gets a value from the attribute dictionary. - /// The attribute key to retrieve. - /// - /// Specifies whether the attribute is required. Default is - /// . - /// - /// The DynamoDB attribute kind to interpret as a string. - /// - /// The value if the key exists and is valid; otherwise - /// if the key is missing or the attribute has a DynamoDB NULL value. - /// - public Guid GetGuid( - string key, - Requiredness requiredness = Requiredness.InferFromNullability, - DynamoKind kind = DynamoKind.S - ) => attributes.TryGetGuid(key, out var value, requiredness, kind) ? value : Guid.Empty; - - /// Tries to get a nullable value from the attribute dictionary. - /// The attribute key to retrieve. - /// The nullable value when found. - /// - /// Specifies whether the attribute is required. Default is - /// . - /// - /// The DynamoDB attribute kind to interpret as a string. - /// true when the key exists and the value is retrieved; otherwise false. - public bool TryGetNullableGuid( - string key, - out Guid? value, - Requiredness requiredness = Requiredness.InferFromNullability, - DynamoKind kind = DynamoKind.S - ) - { - value = null; - if (!attributes.TryGetNullableValue(key, requiredness, out var attribute)) - return false; - - if (attribute.IsNull) - return true; - - var stringValue = attribute!.GetNullableString(kind); - value = stringValue is null ? null : Guid.Parse(stringValue); - return true; - } - - /// Gets a nullable value from the attribute dictionary. - /// The attribute key to retrieve. - /// - /// Specifies whether the attribute is required. Default is - /// . - /// - /// The DynamoDB attribute kind to interpret as a string. - /// - /// The value if the key exists and is valid; otherwise null if the - /// key is missing or the attribute has a DynamoDB NULL value. - /// - public Guid? GetNullableGuid( - string key, - Requiredness requiredness = Requiredness.InferFromNullability, - DynamoKind kind = DynamoKind.S - ) => attributes.TryGetNullableGuid(key, out var value, requiredness, kind) ? value : null; - /// /// Tries to get a value from the attribute dictionary using an exact /// format string. /// /// The attribute key to retrieve. + /// The value when found. /// /// The exact format string to use for parsing. Valid formats: "N" (32 digits), - /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). + /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). Default is "D". /// - /// The value when found. /// /// Specifies whether the attribute is required. Default is /// . @@ -115,8 +28,8 @@ public bool TryGetNullableGuid( /// true when the key exists and the value is retrieved; otherwise false. public bool TryGetGuid( string key, - string format, out Guid value, + string format = "D", Requiredness requiredness = Requiredness.InferFromNullability, DynamoKind kind = DynamoKind.S ) @@ -137,7 +50,7 @@ public bool TryGetGuid( /// The attribute key to retrieve. /// /// The exact format string to use for parsing. Valid formats: "N" (32 digits), - /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). + /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). Default is "D". /// /// /// Specifies whether the attribute is required. Default is @@ -150,11 +63,11 @@ public bool TryGetGuid( /// public Guid GetGuid( string key, - string format, + string format = "D", Requiredness requiredness = Requiredness.InferFromNullability, DynamoKind kind = DynamoKind.S ) => - attributes.TryGetGuid(key, format, out var value, requiredness, kind) + attributes.TryGetGuid(key, out var value, format, requiredness, kind) ? value : Guid.Empty; @@ -163,11 +76,11 @@ public Guid GetGuid( /// exact format string. /// /// The attribute key to retrieve. + /// The nullable value when found. /// /// The exact format string to use for parsing. Valid formats: "N" (32 digits), - /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). + /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). Default is "D". /// - /// The nullable value when found. /// /// Specifies whether the attribute is required. Default is /// . @@ -176,8 +89,8 @@ public Guid GetGuid( /// true when the key exists and the value is retrieved; otherwise false. public bool TryGetNullableGuid( string key, - string format, out Guid? value, + string format = "D", Requiredness requiredness = Requiredness.InferFromNullability, DynamoKind kind = DynamoKind.S ) @@ -201,7 +114,7 @@ public bool TryGetNullableGuid( /// The attribute key to retrieve. /// /// The exact format string to use for parsing. Valid formats: "N" (32 digits), - /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). + /// "D" (hyphens), "B" (braces), "P" (parentheses), "X" (hexadecimal). Default is "D". /// /// /// Specifies whether the attribute is required. Default is @@ -214,11 +127,11 @@ public bool TryGetNullableGuid( /// public Guid? GetNullableGuid( string key, - string format, + string format = "D", Requiredness requiredness = Requiredness.InferFromNullability, DynamoKind kind = DynamoKind.S ) => - attributes.TryGetNullableGuid(key, format, out var value, requiredness, kind) + attributes.TryGetNullableGuid(key, out var value, format, requiredness, kind) ? value : null; diff --git a/src/LayeredCraft.DynamoMapper.Runtime/DynamoMapperAttribute.cs b/src/LayeredCraft.DynamoMapper.Runtime/DynamoMapperAttribute.cs index b569fa7..5b01267 100644 --- a/src/LayeredCraft.DynamoMapper.Runtime/DynamoMapperAttribute.cs +++ b/src/LayeredCraft.DynamoMapper.Runtime/DynamoMapperAttribute.cs @@ -52,4 +52,23 @@ public sealed class DynamoMapperAttribute : Attribute /// /// public string EnumFormat { get; set; } = "G"; + + /// Gets or sets the default Guid format string. + /// + /// The default is "D" (standard format with hyphens): 00000000-0000-0000-0000-000000000000 + /// Valid format strings: + /// + /// "N" - 32 digits: 00000000000000000000000000000000 + /// "D" - 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000 + /// + /// "B" - 32 digits separated by hyphens, enclosed in braces: + /// {00000000-0000-0000-0000-000000000000} + /// + /// + /// "P" - 32 digits separated by hyphens, enclosed in parentheses: + /// (00000000-0000-0000-0000-000000000000) + /// + /// + /// + public string GuidFormat { get; set; } = "D"; } diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes#ExampleEntityMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes#ExampleEntityMapper.g.verified.cs index dd2c67d..c9adc65 100644 --- a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes#ExampleEntityMapper.g.verified.cs +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes#ExampleEntityMapper.g.verified.cs @@ -23,26 +23,26 @@ public static partial class ExampleEntityMapper new Dictionary(22) .SetBool("bool", source.Bool, false, true) .SetBool("nullableBool", source.NullableBool, false, true) - .SetDateTime("dateTime", source.DateTime, format: "O", false, true) - .SetDateTime("nullableDateTime", source.NullableDateTime, format: "O", false, true) - .SetDateTimeOffset("dateTimeOffset", source.DateTimeOffset, format: "O", false, true) - .SetDateTimeOffset("nullableDateTimeOffset", source.NullableDateTimeOffset, format: "O", false, true) + .SetDateTime("dateTime", source.DateTime, "O", false, true) + .SetDateTime("nullableDateTime", source.NullableDateTime, "O", false, true) + .SetDateTimeOffset("dateTimeOffset", source.DateTimeOffset, "O", false, true) + .SetDateTimeOffset("nullableDateTimeOffset", source.NullableDateTimeOffset, "O", false, true) .SetDecimal("decimal", source.Decimal, false, true) .SetDecimal("nullableDecimal", source.NullableDecimal, false, true) .SetDouble("double", source.Double, false, true) .SetDouble("nullableDouble", source.NullableDouble, false, true) - .SetGuid("guid", source.Guid, false, true) - .SetGuid("nullableGuid", source.NullableGuid, false, true) + .SetGuid("guid", source.Guid, "D", false, true) + .SetGuid("nullableGuid", source.NullableGuid, "D", false, true) .SetInt("int", source.Int, false, true) .SetInt("nullableInt", source.NullableInt, false, true) .SetLong("long", source.Long, false, true) .SetLong("nullableLong", source.NullableLong, false, true) .SetString("string", source.String, false, true) .SetString("nullableString", source.NullableString, false, true) - .SetTimeSpan("timeSpan", source.TimeSpan, format: "c", false, true) - .SetTimeSpan("nullableTimeSpan", source.NullableTimeSpan, format: "c", false, true) - .SetEnum("enum", source.Enum, format: "G", false, true) - .SetEnum("nullableEnum", source.NullableEnum, format: "G", false, true); + .SetTimeSpan("timeSpan", source.TimeSpan, "c", false, true) + .SetTimeSpan("nullableTimeSpan", source.NullableTimeSpan, "c", false, true) + .SetEnum("enum", source.Enum, "G", false, true) + .SetEnum("nullableEnum", source.NullableEnum, "G", false, true); [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] public static partial global::MyNamespace.ExampleEntity FromItem(global::System.Collections.Generic.Dictionary x) @@ -59,8 +59,8 @@ public static partial class ExampleEntityMapper NullableDecimal = x.GetNullableDecimal("nullableDecimal", Requiredness.InferFromNullability), Double = x.GetDouble("double", Requiredness.InferFromNullability), NullableDouble = x.GetNullableDouble("nullableDouble", Requiredness.InferFromNullability), - Guid = x.GetGuid("guid", Requiredness.InferFromNullability), - NullableGuid = x.GetNullableGuid("nullableGuid", Requiredness.InferFromNullability), + Guid = x.GetGuid("guid", format: "D", Requiredness.InferFromNullability), + NullableGuid = x.GetNullableGuid("nullableGuid", format: "D", Requiredness.InferFromNullability), Int = x.GetInt("int", Requiredness.InferFromNullability), NullableInt = x.GetNullableInt("nullableInt", Requiredness.InferFromNullability), Long = x.GetLong("long", Requiredness.InferFromNullability), diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes_Optional#ExampleEntityMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes_Optional#ExampleEntityMapper.g.verified.cs index 8ef3e3c..ddc7fb9 100644 --- a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes_Optional#ExampleEntityMapper.g.verified.cs +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllHelperTypes_Optional#ExampleEntityMapper.g.verified.cs @@ -23,26 +23,26 @@ public static partial class ExampleEntityMapper new Dictionary(22) .SetBool("bool", source.Bool, false, true) .SetBool("nullableBool", source.NullableBool, false, true) - .SetDateTime("dateTime", source.DateTime, format: "O", false, true) - .SetDateTime("nullableDateTime", source.NullableDateTime, format: "O", false, true) - .SetDateTimeOffset("dateTimeOffset", source.DateTimeOffset, format: "O", false, true) - .SetDateTimeOffset("nullableDateTimeOffset", source.NullableDateTimeOffset, format: "O", false, true) + .SetDateTime("dateTime", source.DateTime, "O", false, true) + .SetDateTime("nullableDateTime", source.NullableDateTime, "O", false, true) + .SetDateTimeOffset("dateTimeOffset", source.DateTimeOffset, "O", false, true) + .SetDateTimeOffset("nullableDateTimeOffset", source.NullableDateTimeOffset, "O", false, true) .SetDecimal("decimal", source.Decimal, false, true) .SetDecimal("nullableDecimal", source.NullableDecimal, false, true) .SetDouble("double", source.Double, false, true) .SetDouble("nullableDouble", source.NullableDouble, false, true) - .SetGuid("guid", source.Guid, false, true) - .SetGuid("nullableGuid", source.NullableGuid, false, true) + .SetGuid("guid", source.Guid, "D", false, true) + .SetGuid("nullableGuid", source.NullableGuid, "D", false, true) .SetInt("int", source.Int, false, true) .SetInt("nullableInt", source.NullableInt, false, true) .SetLong("long", source.Long, false, true) .SetLong("nullableLong", source.NullableLong, false, true) .SetString("string", source.String, false, true) .SetString("nullableString", source.NullableString, false, true) - .SetTimeSpan("timeSpan", source.TimeSpan, format: "c", false, true) - .SetTimeSpan("nullableTimeSpan", source.NullableTimeSpan, format: "c", false, true) - .SetEnum("enum", source.Enum, format: "G", false, true) - .SetEnum("nullableEnum", source.NullableEnum, format: "G", false, true); + .SetTimeSpan("timeSpan", source.TimeSpan, "c", false, true) + .SetTimeSpan("nullableTimeSpan", source.NullableTimeSpan, "c", false, true) + .SetEnum("enum", source.Enum, "G", false, true) + .SetEnum("nullableEnum", source.NullableEnum, "G", false, true); [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] public static partial global::MyNamespace.ExampleEntity FromItem(global::System.Collections.Generic.Dictionary x) @@ -58,8 +58,8 @@ public static partial class ExampleEntityMapper if (x.TryGetNullableDecimal("nullableDecimal", out var var7, Requiredness.InferFromNullability)) exampleEntity.NullableDecimal = var7!; if (x.TryGetDouble("double", out var var8, Requiredness.InferFromNullability)) exampleEntity.Double = var8!; if (x.TryGetNullableDouble("nullableDouble", out var var9, Requiredness.InferFromNullability)) exampleEntity.NullableDouble = var9!; - if (x.TryGetGuid("guid", out var var10, Requiredness.InferFromNullability)) exampleEntity.Guid = var10!; - if (x.TryGetNullableGuid("nullableGuid", out var var11, Requiredness.InferFromNullability)) exampleEntity.NullableGuid = var11!; + if (x.TryGetGuid("guid", out var var10, format: "D", Requiredness.InferFromNullability)) exampleEntity.Guid = var10!; + if (x.TryGetNullableGuid("nullableGuid", out var var11, format: "D", Requiredness.InferFromNullability)) exampleEntity.NullableGuid = var11!; if (x.TryGetInt("int", out var var12, Requiredness.InferFromNullability)) exampleEntity.Int = var12!; if (x.TryGetNullableInt("nullableInt", out var var13, Requiredness.InferFromNullability)) exampleEntity.NullableInt = var13!; if (x.TryGetLong("long", out var var14, Requiredness.InferFromNullability)) exampleEntity.Long = var14!; diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllOptionsSetToNonDefaultValues#ExampleEntityMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllOptionsSetToNonDefaultValues#ExampleEntityMapper.g.verified.cs index d9ce3a6..125a9b7 100644 --- a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllOptionsSetToNonDefaultValues#ExampleEntityMapper.g.verified.cs +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_AllOptionsSetToNonDefaultValues#ExampleEntityMapper.g.verified.cs @@ -23,26 +23,26 @@ public static partial class ExampleEntityMapper new Dictionary(22) .SetBool("bool", source.Bool, true, false) .SetBool("nullable_bool", source.NullableBool, true, false) - .SetDateTime("date_time", source.DateTime, format: "I", true, false) - .SetDateTime("nullable_date_time", source.NullableDateTime, format: "I", true, false) - .SetDateTimeOffset("date_time_offset", source.DateTimeOffset, format: "I", true, false) - .SetDateTimeOffset("nullable_date_time_offset", source.NullableDateTimeOffset, format: "I", true, false) + .SetDateTime("date_time", source.DateTime, "I", true, false) + .SetDateTime("nullable_date_time", source.NullableDateTime, "I", true, false) + .SetDateTimeOffset("date_time_offset", source.DateTimeOffset, "I", true, false) + .SetDateTimeOffset("nullable_date_time_offset", source.NullableDateTimeOffset, "I", true, false) .SetDecimal("decimal", source.Decimal, true, false) .SetDecimal("nullable_decimal", source.NullableDecimal, true, false) .SetDouble("double", source.Double, true, false) .SetDouble("nullable_double", source.NullableDouble, true, false) - .SetGuid("guid", source.Guid, true, false) - .SetGuid("nullable_guid", source.NullableGuid, true, false) + .SetGuid("guid", source.Guid, "D", true, false) + .SetGuid("nullable_guid", source.NullableGuid, "D", true, false) .SetInt("int", source.Int, true, false) .SetInt("nullable_int", source.NullableInt, true, false) .SetLong("long", source.Long, true, false) .SetLong("nullable_long", source.NullableLong, true, false) .SetString("string", source.String, true, false) .SetString("nullable_string", source.NullableString, true, false) - .SetTimeSpan("time_span", source.TimeSpan, format: "c", true, false) - .SetTimeSpan("nullable_time_span", source.NullableTimeSpan, format: "c", true, false) - .SetEnum("enum", source.Enum, format: "G", true, false) - .SetEnum("nullable_enum", source.NullableEnum, format: "G", true, false); + .SetTimeSpan("time_span", source.TimeSpan, "c", true, false) + .SetTimeSpan("nullable_time_span", source.NullableTimeSpan, "c", true, false) + .SetEnum("enum", source.Enum, "G", true, false) + .SetEnum("nullable_enum", source.NullableEnum, "G", true, false); [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] public static partial global::MyNamespace.ExampleEntity FromItem(global::System.Collections.Generic.Dictionary x) @@ -59,8 +59,8 @@ public static partial class ExampleEntityMapper NullableDecimal = x.GetNullableDecimal("nullable_decimal", Requiredness.Required), Double = x.GetDouble("double", Requiredness.Required), NullableDouble = x.GetNullableDouble("nullable_double", Requiredness.Required), - Guid = x.GetGuid("guid", Requiredness.Required), - NullableGuid = x.GetNullableGuid("nullable_guid", Requiredness.Required), + Guid = x.GetGuid("guid", format: "D", Requiredness.Required), + NullableGuid = x.GetNullableGuid("nullable_guid", format: "D", Requiredness.Required), Int = x.GetInt("int", Requiredness.Required), NullableInt = x.GetNullableInt("nullable_int", Requiredness.Required), Long = x.GetLong("long", Requiredness.Required), diff --git a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_DefaultValues#UserMapper.g.verified.cs b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_DefaultValues#UserMapper.g.verified.cs index f4797a7..ab2752f 100644 --- a/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_DefaultValues#UserMapper.g.verified.cs +++ b/test/LayeredCraft.DynamoMapper.Generators.Tests/Snapshots/SimpleVerifyTests.Simple_DefaultValues#UserMapper.g.verified.cs @@ -25,7 +25,7 @@ internal static partial class UserMapper .SetString("middleName", user.MiddleName, false, true) .SetString("lastName", user.LastName, false, true) .SetInt("age", user.Age, false, true) - .SetDateTimeOffset("dateCreated", user.DateCreated, format: "O", false, true) + .SetDateTimeOffset("dateCreated", user.DateCreated, "O", false, true) .SetString("fullName", user.FullName, false, true); [global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")] diff --git a/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.CollectionTests.cs b/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.CollectionTests.cs index e5cd440..d62c8b8 100644 --- a/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.CollectionTests.cs +++ b/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.CollectionTests.cs @@ -1,7 +1,5 @@ -using System.IO; using Amazon.DynamoDBv2.Model; using DynamoMapper.Runtime; -using LayeredCraft.DynamoMapper.TestKit.Attributes; namespace LayeredCraft.DynamoMapper.Runtime.Tests; @@ -29,7 +27,7 @@ public void GetList_ReturnsEmptyList_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["tags"] = new() { NULL = true } + ["tags"] = new() { NULL = true }, }; // Act @@ -46,7 +44,7 @@ public void GetList_ReturnsEmptyList_WhenListIsEmpty() // Arrange var attributes = new Dictionary { - ["tags"] = new() { L = new List() } + ["tags"] = new() { L = new List() }, }; // Act @@ -69,9 +67,9 @@ public void GetList_ReturnsListOfStrings_WhenListContainsValues() { new() { S = "tag1" }, new() { S = "tag2" }, - new() { S = "tag3" } - } - } + new() { S = "tag3" }, + }, + }, }; // Act @@ -96,9 +94,9 @@ public void GetList_ReturnsListOfInts_WhenListContainsNumbers() { new() { N = "100" }, new() { N = "200" }, - new() { N = "300" } - } - } + new() { N = "300" }, + }, + }, }; // Act @@ -122,9 +120,9 @@ public void GetList_ReturnsListOfBinary_WhenListContainsBinaryValues() L = new List { new() { B = new MemoryStream(new byte[] { 1, 2, 3 }) }, - new() { B = new MemoryStream(new byte[] { 4, 5, 6 }) } - } - } + new() { B = new MemoryStream(new byte[] { 4, 5, 6 }) }, + }, + }, }; // Act @@ -148,9 +146,9 @@ public void GetList_HandlesNullableElements_WithNullValues() { new() { N = "100" }, new() { NULL = true }, - new() { N = "300" } - } - } + new() { N = "300" }, + }, + }, }; // Act @@ -182,7 +180,7 @@ public void GetNullableList_ReturnsNull_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["tags"] = new() { NULL = true } + ["tags"] = new() { NULL = true }, }; // Act @@ -321,11 +319,7 @@ public void List_RoundTrip_WithBinary() { // Arrange var attributes = new Dictionary(); - var original = new List - { - new byte[] { 0, 1, 2 }, - new byte[] { 3, 4, 5 } - }; + var original = new List { new byte[] { 0, 1, 2 }, new byte[] { 3, 4, 5 } }; // Act attributes.SetList("payloads", original); @@ -359,7 +353,7 @@ public void GetMap_ReturnsEmptyDictionary_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["metadata"] = new() { NULL = true } + ["metadata"] = new() { NULL = true }, }; // Act @@ -381,9 +375,9 @@ public void GetMap_ReturnsDictionary_WhenMapContainsValues() M = new Dictionary { ["count"] = new() { N = "42" }, - ["version"] = new() { N = "2" } - } - } + ["version"] = new() { N = "2" }, + }, + }, }; // Act @@ -461,7 +455,12 @@ public void Map_RoundTrip_WithInts() { // Arrange var attributes = new Dictionary(); - var original = new Dictionary { ["count"] = 42, ["version"] = 2, ["retries"] = 3 }; + var original = new Dictionary + { + ["count"] = 42, + ["version"] = 2, + ["retries"] = 3, + }; // Act attributes.SetMap("metadata", original); @@ -480,7 +479,7 @@ public void Map_RoundTrip_WithStrings() { ["name"] = "John", ["city"] = "Seattle", - ["country"] = "USA" + ["country"] = "USA", }; // Act @@ -491,7 +490,6 @@ public void Map_RoundTrip_WithStrings() Assert.Equal(original, result); } - // ==================== STRING SET TESTS ==================== [Fact] @@ -514,7 +512,7 @@ public void GetStringSet_ReturnsEmptySet_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["categories"] = new() { NULL = true } + ["categories"] = new() { NULL = true }, }; // Act @@ -533,8 +531,8 @@ public void GetStringSet_ReturnsHashSet_WhenSetContainsValues() { ["categories"] = new() { - SS = new List { "electronics", "computers", "laptops" } - } + SS = new List { "electronics", "computers", "laptops" }, + }, }; // Act @@ -661,8 +659,8 @@ public void GetNumberSet_ReturnsHashSet_WhenSetContainsInts() { ["numbers"] = new() { - NS = new List { "1", "2", "3", "5", "8" } - } + NS = new List { "1", "2", "3", "5", "8" }, + }, }; // Act @@ -685,8 +683,8 @@ public void GetNumberSet_ReturnsHashSet_WhenSetContainsDoubles() { ["prices"] = new() { - NS = new List { "19.99", "29.99", "39.99" } - } + NS = new List { "19.99", "29.99", "39.99" }, + }, }; // Act @@ -796,7 +794,7 @@ public void GetBinarySet_ReturnsEmptySet_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["payloads"] = new() { NULL = true } + ["payloads"] = new() { NULL = true }, }; // Act @@ -818,9 +816,9 @@ public void GetBinarySet_ReturnsHashSet_WhenSetContainsValues() BS = new List { new(new byte[] { 1, 2, 3 }), - new(new byte[] { 4, 5, 6 }) - } - } + new(new byte[] { 4, 5, 6 }), + }, + }, }; // Act @@ -838,7 +836,7 @@ public void GetNullableBinarySet_ReturnsNull_WhenValueIsNull() // Arrange var attributes = new Dictionary { - ["payloads"] = new() { NULL = true } + ["payloads"] = new() { NULL = true }, }; // Act @@ -853,11 +851,7 @@ public void SetBinarySet_SetsBinarySet_WhenNonNullSet() { // Arrange var attributes = new Dictionary(); - var payloads = new List - { - new byte[] { 1, 2, 3 }, - new byte[] { 4, 5, 6 } - }; + var payloads = new List { new byte[] { 1, 2, 3 }, new byte[] { 4, 5, 6 } }; // Act attributes.SetBinarySet("payloads", payloads); @@ -873,18 +867,14 @@ public void SetBinarySet_DeduplicatesValues() { // Arrange var attributes = new Dictionary(); - var payloads = new List - { - new byte[] { 1, 2, 3 }, - new byte[] { 1, 2, 3 } - }; + var payloads = new List { new byte[] { 1, 2, 3 }, new byte[] { 1, 2, 3 } }; // Act attributes.SetBinarySet("payloads", payloads); // Assert Assert.True(attributes.ContainsKey("payloads")); - Assert.Equal(1, attributes["payloads"].BS.Count); + Assert.Single(attributes["payloads"].BS); } [Fact] @@ -906,11 +896,7 @@ public void BinarySet_RoundTrip() { // Arrange var attributes = new Dictionary(); - var original = new List - { - new byte[] { 7, 8, 9 }, - new byte[] { 10, 11, 12 } - }; + var original = new List { new byte[] { 7, 8, 9 }, new byte[] { 10, 11, 12 } }; var expected = original .Select(bytes => string.Join(",", bytes)) .ToHashSet(StringComparer.Ordinal); diff --git a/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.GuidTests.cs b/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.GuidTests.cs index e4ba71b..35daf60 100644 --- a/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.GuidTests.cs +++ b/test/LayeredCraft.DynamoMapper.Runtime.Tests/AttributeValueExtensions.GuidTests.cs @@ -30,7 +30,7 @@ public void GetGuid_ReturnsEmpty_WhenKeyDoesNotExist() var attributes = new Dictionary(); // Act - var result = attributes.GetGuid("id", Requiredness.Optional); + var result = attributes.GetGuid("id", requiredness: Requiredness.Optional); // Assert Assert.Equal(Guid.Empty, result); @@ -43,7 +43,7 @@ public void GetGuid_ReturnsEmpty_WhenValueIsNull() var attributes = new Dictionary { ["id"] = new() { NULL = true } }; // Act - var result = attributes.GetGuid("id", Requiredness.Optional); + var result = attributes.GetGuid("id", requiredness: Requiredness.Optional); // Assert Assert.Equal(Guid.Empty, result);