diff --git a/ObjectSemantics.NET.Tests/CognitiveMapTests.cs b/ObjectSemantics.NET.Tests/CognitiveMapTests.cs index 5dea7e9..4fd05a2 100644 --- a/ObjectSemantics.NET.Tests/CognitiveMapTests.cs +++ b/ObjectSemantics.NET.Tests/CognitiveMapTests.cs @@ -48,9 +48,9 @@ public void Additional_Headers_Should_Also_Be_Mapped() { "DateOfBirth", new DateTime(1995, 01, 01) } }; - string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth }}".Map(person, additionalParams); - - Assert.Equal($"Name: {person.Name} | Occupation: {additionalParams["Occupation"]} | DOB: {additionalParams["DateOfBirth"]}", generatedTemplate); + string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth:yyyy }}".Map(person, additionalParams); + string expected = "Name: John Doe | Occupation: Developer | DOB: 1995"; + Assert.Equal(expected, generatedTemplate); } diff --git a/ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs b/ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs index 730a68a..2e6b11e 100644 --- a/ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs +++ b/ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs @@ -9,13 +9,14 @@ public class PropertyDateTimeMapTests [Fact] public void Should_Map_From_Date() { - DateTime date = new DateTime(2022, 11, 27, 18, 13, 59); + DateTime date = new DateTime(2022, 2, 27, 18, 13, 59); Car car = new Car() { ManufactureDate = date }; string result = car.Map("{{ ManufactureDate:yyyy }}|{{ ManufactureDate:yyyy-MM-dd HH:mm tt }}"); - Assert.Equal($"{car.ManufactureDate:yyyy}|{car.ManufactureDate:yyyy-MM-dd HH:mm tt}", result, false, true, true); + string expected = "2022|2022-02-27 18:13 PM"; + Assert.Equal(expected, result, false, true, true); } [Fact] @@ -25,8 +26,9 @@ public void Should_Map_From_Null_Date() { LastServiceDate = null }; - string result = car.Map("Last serviced: {{ LastServiceDate }}"); - Assert.Equal($"Last serviced: {car.LastServiceDate}", result, false, true, true); + string result = car.Map("Last serviced: {{ LastServiceDate:yyyy-MM-dd hh:mm tt }}"); + string expected = "Last serviced: "; + Assert.Equal(expected, result, false, true, true); } [Fact] @@ -36,8 +38,9 @@ public void Should_Map_From_Nullable_Date() { LastServiceDate = new DateTime(2025, 1, 1) }; - string result = car.Map("Last serviced: {{ LastServiceDate }}"); - Assert.Equal($"Last serviced: {car.LastServiceDate}", result, false, true, true); + string result = car.Map("Last serviced: {{ LastServiceDate:yyyy-MM-dd hh:mm tt }}"); + string expected = $"Last serviced: 2025-01-01 12:00 AM"; + Assert.Equal(expected, result, false, true, true); } } } diff --git a/ObjectSemantics.NET/Engine/Extensions/ExtractedObjPropertyExtensions.cs b/ObjectSemantics.NET/Engine/Extensions/ExtractedObjPropertyExtensions.cs index e596c41..3ef9242 100644 --- a/ObjectSemantics.NET/Engine/Extensions/ExtractedObjPropertyExtensions.cs +++ b/ObjectSemantics.NET/Engine/Extensions/ExtractedObjPropertyExtensions.cs @@ -31,8 +31,6 @@ private static string GetAppliedPropertyFormatting(this ExtractedObjProperty p, // avoid repeated ToLower calls string fmt = customFormat.Trim(); - string fmtLower = fmt.ToLowerInvariant(); - // handle numeric and datetime formats first try { @@ -55,7 +53,7 @@ private static string GetAppliedPropertyFormatting(this ExtractedObjProperty p, } // custom string-based formats (single switch to avoid multiple ToLower() checks) - switch (fmtLower) + switch (fmt.ToLowerInvariant()) { case "uppercase": return val?.ToUpperInvariant(); case "lowercase": return val?.ToLowerInvariant(); @@ -102,8 +100,7 @@ public static bool IsPropertyValueConditionPassed(this ExtractedObjProperty prop } } - if (t == typeof(int) || t == typeof(double) || t == typeof(long) || - t == typeof(float) || t == typeof(decimal)) + if (t == typeof(int) || t == typeof(double) || t == typeof(long) || t == typeof(float) || t == typeof(decimal)) { double v1 = Convert.ToDouble(original ?? 0, CultureInfo.InvariantCulture); double v2 = Convert.ToDouble(GetConvertibleValue(valueComparer), CultureInfo.InvariantCulture); diff --git a/ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs b/ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs index 1014a12..4747e4e 100644 --- a/ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs +++ b/ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Text; namespace ObjectSemantics.NET.Engine.Extensions @@ -16,7 +17,7 @@ public static string ToMD5String(this string input) // Convert the byte array to hexadecimal string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) - sb.Append(hashBytes[i].ToString("X2")); + sb.Append(hashBytes[i].ToString("X2", CultureInfo.InvariantCulture)); return sb.ToString(); } } diff --git a/ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs b/ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs index 126a677..a17a943 100644 --- a/ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs +++ b/ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Globalization; namespace ObjectSemantics.NET.Engine.Models { @@ -8,7 +9,8 @@ internal class ExtractedObjProperty public Type Type { get; set; } public string Name { get; set; } public object OriginalValue { get; set; } - public string StringFormatted { get { return string.Format("{0}", OriginalValue); } } + public string StringFormatted => Convert.ToString(OriginalValue, CultureInfo.InvariantCulture); + public bool IsEnumerableObject { get { return typeof(IEnumerable).IsAssignableFrom(Type) && Type != typeof(string); } diff --git a/ObjectSemantics.NET/ObjectSemantics.NET.csproj b/ObjectSemantics.NET/ObjectSemantics.NET.csproj index 3dd06c1..088593a 100644 --- a/ObjectSemantics.NET/ObjectSemantics.NET.csproj +++ b/ObjectSemantics.NET/ObjectSemantics.NET.csproj @@ -15,9 +15,9 @@ ToBase64 FromBase64 . Added template extension method to allow mapping directly from Template - 7.0.1 - 7.0.1 - 7.0.1 + 7.0.2 + $(Version) + $(Version) false README.md