Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 68b313d

Browse files
committed
Add test showing Date's are serialized with UnixTime within JS Scope
1 parent d02003d commit 68b313d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/ServiceStack.Text.Tests/Utils/DateTimeSerializerTests.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,14 @@ public void Can_deserialize_LocalTime_using_UnixTime()
625625
}
626626
}
627627

628+
public class TestObject
629+
{
630+
public DateTime Date { get; set; }
631+
}
632+
628633
[TestFixture]
629634
public class UnixEpochMsTests
630635
{
631-
public class TestObject
632-
{
633-
public DateTime Date { get; set; }
634-
}
635-
636636
[TestFixtureSetUp]
637637
public void TestFixtureSetUp()
638638
{
@@ -734,4 +734,25 @@ public void Can_Parse_TimeSpan_NSTimeSpan()
734734
Assert.That("31539661.001".FromJson<TimeSpan>(), Is.EqualTo(Time1Y1M1H1S1MS));
735735
}
736736
}
737+
738+
[TestFixture]
739+
public class UnixTimeScopeTests
740+
{
741+
[Test]
742+
public void Does_serialize_to_UnixTime_when_scoped()
743+
{
744+
var dto = new TestObject { Date = new DateTime(2001,01,01, 0, 0, 0, DateTimeKind.Utc) };
745+
746+
using (var config = JsConfig.BeginScope())
747+
{
748+
config.DateHandler = DateHandler.UnixTime;
749+
750+
var json = dto.ToJson();
751+
Assert.That(json, Is.EquivalentTo("{\"Date\":978307200}"));
752+
753+
var fromJson = JsonSerializer.DeserializeFromString<TestObject>(json);
754+
Assert.That(fromJson.Date, Is.EqualTo(dto.Date));
755+
}
756+
}
757+
}
737758
}

0 commit comments

Comments
 (0)