コード例 #1
0
        public void WriteJson_ThrowsInvalidCastException(object data)
        {
            var converter = new EpochTimeConverter();

            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var writer       = new JsonTextWriter(stringWriter);
            var serializer   = new JsonSerializer();

            var exception = Record.Exception(() => converter.WriteJson(writer, data, serializer));

            Assert.NotNull(exception);
            Assert.IsType <InvalidCastException>(exception);
        }
コード例 #2
0
        public void EpochTimeConverter_WriteJsonString_ThrowsInvalidCastException()
        {
            var converter = new EpochTimeConverter();

            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var writer       = new JsonTextWriter(stringWriter);
            var serializer   = new JsonSerializer();

            converter.WriteJson(writer, "xyz", serializer);

            var actual = sb.ToString();

            Assert.AreNotEqual("1439134235", actual);
        }
コード例 #3
0
        public void WriteJson(string expected, DateTimeOffset original)
        {
            var converter = new EpochTimeConverter();

            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var writer       = new JsonTextWriter(stringWriter);
            var serializer   = new JsonSerializer();

            converter.WriteJson(writer, original, serializer);

            var actual = sb.ToString();

            Assert.Equal(expected, actual);
        }
コード例 #4
0
        public void EpochTimeConverter_WriteJsonInt64_AreNotEqual()
        {
            var converter = new EpochTimeConverter();

            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var writer       = new JsonTextWriter(stringWriter);
            var serializer   = new JsonSerializer();

            var date = new DateTimeOffset(new DateTime(2015, 8, 4, 15, 30, 32, DateTimeKind.Utc));

            converter.WriteJson(writer, date, serializer);

            var actual = sb.ToString();

            Assert.AreNotEqual("1439134235", actual);
        }