From cfb6abfa1f5a5d2d8744e4fa663c443163268db8 Mon Sep 17 00:00:00 2001 From: AliReZa Sabouri Date: Sat, 11 Nov 2023 12:53:19 +0100 Subject: [PATCH] test: dateTime kind after conversion #134 --- test/Gridify.Tests/Issue134Tests.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/Gridify.Tests/Issue134Tests.cs b/test/Gridify.Tests/Issue134Tests.cs index 1fb68a1d..bb177eeb 100644 --- a/test/Gridify.Tests/Issue134Tests.cs +++ b/test/Gridify.Tests/Issue134Tests.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Reflection; using Xunit; namespace Gridify.Tests; @@ -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()); } }