Beispiel #1
0
        public void Can_Deserialize_DateTime_With_DateTimeStyles()
        {
            DateTime   item0 = new DateTime(2010, 2, 8, 11, 11, 11, DateTimeKind.Local);
            DateTime   item1 = new DateTime(2011, 2, 8, 11, 11, 11, DateTimeKind.Utc);
            DateTime   item2 = new DateTime(2012, 2, 8, 11, 11, 11, DateTimeKind.Unspecified);
            JsonObject data  = new JsonObject();

            data["Items"] = new JsonArray
            {
                item0,
                item1,
                item2,
                "/Date(1309421746929+0000)/"
            };

            JsonDeserializer d        = new JsonDeserializer();
            RestResponse     response = new RestResponse {
                Content = data.ToString()
            };
            GenericWithList <DateTime> p = d.Deserialize <GenericWithList <DateTime> >(response);

            Assert.AreNotEqual(item0.Kind, p.Items[0].Kind);
            Assert.AreEqual(item1.Kind, p.Items[1].Kind);
            Assert.AreEqual(DateTimeKind.Utc, p.Items[2].Kind);
            Assert.AreEqual(DateTimeKind.Utc, p.Items[3].Kind);
        }
Beispiel #2
0
        public void Can_Deserialize_Generic_List_of_DateTime()
        {
            DateTime   item1 = new DateTime(2010, 2, 8, 11, 11, 11);
            DateTime   item2 = item1.AddSeconds(12345);
            JsonObject data  = new JsonObject();

            data["Items"] = new JsonArray
            {
                item1.ToString("u"),
                item2.ToString("u")
            };

            JsonDeserializer d        = new JsonDeserializer();
            RestResponse     response = new RestResponse {
                Content = data.ToString()
            };
            GenericWithList <DateTime> p = d.Deserialize <GenericWithList <DateTime> >(response);

            Assert.AreEqual(2, p.Items.Count);
            Assert.AreEqual(item1, p.Items[0]);
            Assert.AreEqual(item2, p.Items[1]);
        }