Skip to content

Commit e012c2e

Browse files
authored
Merge pull request #23 from swagfin/feature/minor-improvements
chore: minor improvements
2 parents 558576a + 22bc4fc commit e012c2e

6 files changed

Lines changed: 22 additions & 19 deletions

File tree

ObjectSemantics.NET.Tests/CognitiveMapTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void Additional_Headers_Should_Also_Be_Mapped()
4848
{ "DateOfBirth", new DateTime(1995, 01, 01) }
4949
};
5050

51-
string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth }}".Map(person, additionalParams);
52-
53-
Assert.Equal($"Name: {person.Name} | Occupation: {additionalParams["Occupation"]} | DOB: {additionalParams["DateOfBirth"]}", generatedTemplate);
51+
string generatedTemplate = "Name: {{ Name }} | Occupation: {{ Occupation }} | DOB: {{ DateOfBirth:yyyy }}".Map(person, additionalParams);
52+
string expected = "Name: John Doe | Occupation: Developer | DOB: 1995";
53+
Assert.Equal(expected, generatedTemplate);
5454
}
5555

5656

ObjectSemantics.NET.Tests/PropertyDateTimeMapTests.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ public class PropertyDateTimeMapTests
99
[Fact]
1010
public void Should_Map_From_Date()
1111
{
12-
DateTime date = new DateTime(2022, 11, 27, 18, 13, 59);
12+
DateTime date = new DateTime(2022, 2, 27, 18, 13, 59);
1313
Car car = new Car()
1414
{
1515
ManufactureDate = date
1616
};
1717
string result = car.Map("{{ ManufactureDate:yyyy }}|{{ ManufactureDate:yyyy-MM-dd HH:mm tt }}");
18-
Assert.Equal($"{car.ManufactureDate:yyyy}|{car.ManufactureDate:yyyy-MM-dd HH:mm tt}", result, false, true, true);
18+
string expected = "2022|2022-02-27 18:13 PM";
19+
Assert.Equal(expected, result, false, true, true);
1920
}
2021

2122
[Fact]
@@ -25,8 +26,9 @@ public void Should_Map_From_Null_Date()
2526
{
2627
LastServiceDate = null
2728
};
28-
string result = car.Map("Last serviced: {{ LastServiceDate }}");
29-
Assert.Equal($"Last serviced: {car.LastServiceDate}", result, false, true, true);
29+
string result = car.Map("Last serviced: {{ LastServiceDate:yyyy-MM-dd hh:mm tt }}");
30+
string expected = "Last serviced: ";
31+
Assert.Equal(expected, result, false, true, true);
3032
}
3133

3234
[Fact]
@@ -36,8 +38,9 @@ public void Should_Map_From_Nullable_Date()
3638
{
3739
LastServiceDate = new DateTime(2025, 1, 1)
3840
};
39-
string result = car.Map("Last serviced: {{ LastServiceDate }}");
40-
Assert.Equal($"Last serviced: {car.LastServiceDate}", result, false, true, true);
41+
string result = car.Map("Last serviced: {{ LastServiceDate:yyyy-MM-dd hh:mm tt }}");
42+
string expected = $"Last serviced: 2025-01-01 12:00 AM";
43+
Assert.Equal(expected, result, false, true, true);
4144
}
4245
}
4346
}

ObjectSemantics.NET/Engine/Extensions/ExtractedObjPropertyExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ private static string GetAppliedPropertyFormatting(this ExtractedObjProperty p,
3131

3232
// avoid repeated ToLower calls
3333
string fmt = customFormat.Trim();
34-
string fmtLower = fmt.ToLowerInvariant();
35-
3634
// handle numeric and datetime formats first
3735
try
3836
{
@@ -55,7 +53,7 @@ private static string GetAppliedPropertyFormatting(this ExtractedObjProperty p,
5553
}
5654

5755
// custom string-based formats (single switch to avoid multiple ToLower() checks)
58-
switch (fmtLower)
56+
switch (fmt.ToLowerInvariant())
5957
{
6058
case "uppercase": return val?.ToUpperInvariant();
6159
case "lowercase": return val?.ToLowerInvariant();
@@ -102,8 +100,7 @@ public static bool IsPropertyValueConditionPassed(this ExtractedObjProperty prop
102100
}
103101
}
104102

105-
if (t == typeof(int) || t == typeof(double) || t == typeof(long) ||
106-
t == typeof(float) || t == typeof(decimal))
103+
if (t == typeof(int) || t == typeof(double) || t == typeof(long) || t == typeof(float) || t == typeof(decimal))
107104
{
108105
double v1 = Convert.ToDouble(original ?? 0, CultureInfo.InvariantCulture);
109106
double v2 = Convert.ToDouble(GetConvertibleValue<double>(valueComparer), CultureInfo.InvariantCulture);

ObjectSemantics.NET/Engine/Extensions/StringExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Text;
34

45
namespace ObjectSemantics.NET.Engine.Extensions
@@ -16,7 +17,7 @@ public static string ToMD5String(this string input)
1617
// Convert the byte array to hexadecimal string
1718
StringBuilder sb = new StringBuilder();
1819
for (int i = 0; i < hashBytes.Length; i++)
19-
sb.Append(hashBytes[i].ToString("X2"));
20+
sb.Append(hashBytes[i].ToString("X2", CultureInfo.InvariantCulture));
2021
return sb.ToString();
2122
}
2223
}

ObjectSemantics.NET/Engine/Models/ExtractedObjProperty.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.Globalization;
34

45
namespace ObjectSemantics.NET.Engine.Models
56
{
@@ -8,7 +9,8 @@ internal class ExtractedObjProperty
89
public Type Type { get; set; }
910
public string Name { get; set; }
1011
public object OriginalValue { get; set; }
11-
public string StringFormatted { get { return string.Format("{0}", OriginalValue); } }
12+
public string StringFormatted => Convert.ToString(OriginalValue, CultureInfo.InvariantCulture);
13+
1214
public bool IsEnumerableObject
1315
{
1416
get { return typeof(IEnumerable).IsAssignableFrom(Type) && Type != typeof(string); }

ObjectSemantics.NET/ObjectSemantics.NET.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
ToBase64
1616
FromBase64
1717
. Added template extension method to allow mapping directly from Template</PackageReleaseNotes>
18-
<AssemblyVersion>7.0.1</AssemblyVersion>
19-
<FileVersion>7.0.1</FileVersion>
20-
<Version>7.0.1</Version>
18+
<Version>7.0.2</Version>
19+
<AssemblyVersion>$(Version)</AssemblyVersion>
20+
<FileVersion>$(Version)</FileVersion>
2121
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
2222
<ApplicationIcon></ApplicationIcon>
2323
<PackageReadmeFile>README.md</PackageReadmeFile>

0 commit comments

Comments
 (0)