Exemplo n.º 1
0
        public void ReadAsDateTime_Null_Success()
        {
            JValue n = JValue.CreateNull();

            JTokenReader reader = new JTokenReader(n);

            Assert.AreEqual(null, reader.ReadAsDateTime());
        }
Exemplo n.º 2
0
        public void ReadAsDateTime_DateTimeOffset()
        {
            JValue v = new JValue(new DateTimeOffset(2012, 1, 24, 3, 50, 0, TimeSpan.Zero));

            JTokenReader reader = new JTokenReader(v);

            Assert.AreEqual(new DateTime(2012, 1, 24, 3, 50, 0, DateTimeKind.Utc), reader.ReadAsDateTime());
        }
Exemplo n.º 3
0
        public void ReadAsDateTime_String()
        {
            JValue v = new JValue("2012-01-24T03:50Z");

            JTokenReader reader = new JTokenReader(v);

            Assert.AreEqual(new DateTime(2012, 1, 24, 3, 50, 0, DateTimeKind.Utc), reader.ReadAsDateTime());
        }
Exemplo n.º 4
0
        public void ReadAsDateTime_InvalidToken()
        {
            JArray a = new JArray
            {
                1, 2
            };

            JTokenReader reader = new JTokenReader(a);

            ExceptionAssert.Throws<JsonReaderException>(
                () => { reader.ReadAsDateTime(); },
                "Error reading date. Unexpected token: StartArray. Path ''.");
        }