Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ObjectSemantics.NET.Tests/CognitiveMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
15 changes: 9 additions & 6 deletions ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down Expand Up @@ -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<double>(valueComparer), CultureInfo.InvariantCulture);
Expand Down
3 changes: 2 additions & 1 deletion ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Text;

namespace ObjectSemantics.NET.Engine.Extensions
Expand All @@ -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();
}
}
Expand Down
4 changes: 3 additions & 1 deletion ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Globalization;

namespace ObjectSemantics.NET.Engine.Models
{
Expand All @@ -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); }
Expand Down
6 changes: 3 additions & 3 deletions ObjectSemantics.NET/ObjectSemantics.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
ToBase64
FromBase64
. Added template extension method to allow mapping directly from Template</PackageReleaseNotes>
<AssemblyVersion>7.0.1</AssemblyVersion>
<FileVersion>7.0.1</FileVersion>
<Version>7.0.1</Version>
<Version>7.0.2</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ApplicationIcon></ApplicationIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down