Пример #1
0
        public void JsonDataTimeTests()
        {
            var serializer = MediaWikiHelper.CreateWikiJsonSerializer();
            var value      = DeserializeWith <JValue>("\"2008-08-23T18:05:46Z\"", serializer);

            // https://github.com/CXuesong/WikiClientLibrary/issues/49
            // We want to keep string intact as JValue
            Assert.Equal(JTokenType.String, value.Type);
            // We want to allow it get parsed into DateTime at the same time.
            Assert.Equal(new DateTime(2008, 08, 23, 18, 05, 46, DateTimeKind.Utc),
                         DeserializeWith <DateTime>("\"2008-08-23T18:05:46Z\"", serializer));
            Assert.Equal(new DateTimeOffset(2008, 08, 23, 18, 05, 46, TimeSpan.Zero),
                         DeserializeWith <DateTimeOffset>("\"2008-08-23T18:05:46Z\"", serializer));
            string[] infinityValues = { "infinite", "indefinite", "infinity", "never" };
            foreach (var iTest in infinityValues)
            {
                Assert.Equal(DateTime.MaxValue, DeserializeWith <DateTime>($"\"{iTest}\"", serializer));
                Assert.Equal(DateTimeOffset.MaxValue, DeserializeWith <DateTimeOffset>($"\"{iTest}\"", serializer));
            }
        }