Skip to content

Commit

Permalink
test: dateTime kind after conversion #134
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Nov 11, 2023
1 parent 9ba85db commit cfb6abf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/Gridify.Tests/Issue134Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Reflection;
using Xunit;

namespace Gridify.Tests;
Expand All @@ -15,13 +16,17 @@ public void GridifyMapperConvertor_WhenDateTimeIsParsed_ShouldKeepDateTimeKind()
.AddMap("dt", q => q.MyDateTime, value => DateTime.Parse(value, null, DateTimeStyles.AdjustToUniversal))
.AddCondition($"dt={dateTimeStringUtc}");

var expected = DateTime.Parse(dateTimeStringUtc, null, DateTimeStyles.AdjustToUniversal)
.ToString(CultureInfo.CurrentCulture);
var expected = DateTime.Parse(dateTimeStringUtc, null, DateTimeStyles.AdjustToUniversal);
var expectedKind = expected.Kind;

// act
var actual = qb.BuildFilteringExpression().ToString();
var actual = qb.BuildFilteringExpression();

// assert
Assert.Contains(expected, actual);
var compiled = actual.Compile();
var constants = (object[])compiled.Target!.GetType().GetField("Constants")!.GetValue(compiled.Target)!;
var actualKind = ((DateTime)constants[0]).Kind;
Assert.Equal(expectedKind,actualKind);
Assert.Contains(expected.ToString(CultureInfo.CurrentCulture), actual.ToString());
}
}

0 comments on commit cfb6abf

Please sign in to comment.