Ejemplo n.º 1
0
        public async Task ReadAsDateTimeOffset_Null_SuccessAsync()
        {
            JValue n = JValue.CreateNull();

            JTokenReader reader = new JTokenReader(n);

            Assert.AreEqual(null, await reader.ReadAsDateTimeOffsetAsync());
        }
        public async Task ReadAsDateTimeOffset_StringAsync()
        {
            JValue v = new JValue("2012-01-24T03:50Z");

            JTokenReader reader = new JTokenReader(v);

            Assert.AreEqual(
                new DateTimeOffset(2012, 1, 24, 3, 50, 0, TimeSpan.Zero),
                await reader.ReadAsDateTimeOffsetAsync()
                );
        }
        public async Task ReadAsDateTimeOffset_DateTimeAsync()
        {
            JValue v = new JValue(new DateTime(2001, 12, 12, 12, 12, 12, DateTimeKind.Utc));

            JTokenReader reader = new JTokenReader(v);

            Assert.AreEqual(
                new DateTimeOffset(2001, 12, 12, 12, 12, 12, TimeSpan.Zero),
                await reader.ReadAsDateTimeOffsetAsync()
                );
        }
Ejemplo n.º 4
0
        public async Task ReadAsDateTimeOffset_InvalidTokenAsync()
        {
            JArray a = new JArray
            {
                1, 2
            };

            JTokenReader reader = new JTokenReader(a);

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(
                async() => { await reader.ReadAsDateTimeOffsetAsync(); },
                "Error reading date. Unexpected token: StartArray. Path ''.");
        }