Exemplo n.º 1
0
        public void ReadJson(DateTimeOffset expected, string original)
        {
            var converter = new EpochTimeConverter();

            var reader = new JsonTextReader(new StringReader(original));

            reader.Read();
            var serializer = new JsonSerializer();

            var actual = (DateTimeOffset)converter.ReadJson(reader, typeof(DateTimeOffset), null, serializer);

            Assert.Equal(expected, actual);
        }
        public void EpochTimeConverter_ReadJsonString_ThrowsInvalidCastException()
        {
            var converter = new EpochTimeConverter();

            var reader = new JsonTextReader(new StringReader("'abcdefg'"));

            reader.Read();
            var serializer = new JsonSerializer();

            var expected = new DateTimeOffset(new DateTime(2015, 8, 9, 15, 30, 35, DateTimeKind.Utc));
            var actual   = (DateTimeOffset)converter.ReadJson(reader, typeof(DateTimeOffset), null, serializer);

            Assert.AreEqual(expected, actual);
        }
        public void EpochTimeConverter_ReadJsonInt64_AreNotEqual()
        {
            var converter = new EpochTimeConverter();

            var reader = new JsonTextReader(new StringReader("1439134235"));

            reader.Read();
            var serializer = new JsonSerializer();

            var expected = new DateTimeOffset(new DateTime(2005, 8, 9, 15, 30, 35, DateTimeKind.Utc));
            var actual   = (DateTimeOffset)converter.ReadJson(reader, typeof(DateTimeOffset), null, serializer);

            Assert.AreNotEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void ReadJson_ThrowsInvalidCastException(string data)
        {
            var converter = new EpochTimeConverter();

            var reader = new JsonTextReader(new StringReader(data));

            reader.Read();
            var serializer = new JsonSerializer();

            var exception = Record.Exception(() => converter.ReadJson(reader, typeof(DateTimeOffset), null, serializer));

            Assert.NotNull(exception);
            Assert.IsType <InvalidCastException>(exception);
        }