public void DateTimeDeserializationNegative()
        {
            List<Tuple<string, string>> testCases = new List<Tuple<string, string>>() {
                new Tuple<string, string>("{\"DateTime\":\"I'm not a Date\"}", "String was not recognized as a valid DateTime."),
                new Tuple<string, string>("{\"DateTime\":true}", "Unexpected token parsing date. Expected String, got Boolean. Path 'DateTime', line 1, position 16."),
                new Tuple<string, string>("{\"DateTime\":5}", "Unexpected token parsing date. Expected String, got Integer. Path 'DateTime', line 1, position 13."),
                new Tuple<string, string>("{\"DateTime\":\"\t\"}", "String was not recognized as a valid DateTime."),
            };

            // Need to ensure that the type is registered as a table to force the id property check
            DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(DateTimeType));

            foreach (var testCase in testCases)
            {
                var input = testCase.Item1;
                var expectedError = testCase.Item2;

                DateTimeType actual = new DateTimeType();
                Exception actualError = null;
                try
                {
                    DefaultSerializer.Deserialize(input, actual);
                }
                catch (Exception e)
                {
                    actualError = e;
                }

                Assert.AreEqual(actualError.Message, expectedError);
            }
        }
        public void DateTimeDeserialization()
        {
            List<Tuple<DateTimeType, string>> testCases = new List<Tuple<DateTimeType, string>>()
            {
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{\"DateTime\":null}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{\"DateTime\":" + MinDateTimeSerializedToJson + "}")
            };

            List<DateTime> dates = new List<DateTime>
            {
                new DateTime(1999, 12, 31, 23, 59, 59),
                new DateTime(2005, 3, 14, 12, 34, 16, DateTimeKind.Local).ToLocalTime(),
                new DateTime(2005, 4, 14, 12, 34, 16, DateTimeKind.Unspecified),
                new DateTime(2005, 3, 14, 12, 34, 16, DateTimeKind.Local),
                new DateTime(2005, 5, 14, 12, 34, 16, DateTimeKind.Utc).ToLocalTime(),
                new DateTime(2012, 2, 29, 12, 0, 0, DateTimeKind.Utc).ToLocalTime() // leap day
            };

            foreach (var date in dates) {
                testCases.Add(new Tuple<DateTimeType,string>(
                    new DateTimeType { DateTime = date },
                    "{\"DateTime\":" + ExpectedDateTimeSerialization(date) + "}"));
            }

            // Need to ensure that the type is registered as a table to force the id property check
            DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(DateTimeType));

            foreach (var testCase in testCases)
            {
                var input = JToken.Parse(testCase.Item2);
                var expected = testCase.Item1;

                DateTimeType actual = new DateTimeType();
                DefaultSerializer.Deserialize(input, actual);

                Assert.AreEqual(actual.DateTime.ToUniversalTime(), expected.DateTime.ToUniversalTime());

                if (testCase.Item2 != "{}")
                {
                    actual = new DateTimeType();
                    actual.DateTime = DateTime.Now;
                    DefaultSerializer.Deserialize(input, actual);
                }

                Assert.AreEqual(actual.DateTime.ToUniversalTime(), expected.DateTime.ToUniversalTime());

                JArray json = JToken.Parse("[" + testCase.Item2 + "]") as JArray;
                actual = DefaultSerializer.Deserialize<DateTimeType>(json).FirstOrDefault();

                Assert.AreEqual(actual.DateTime.ToUniversalTime(), expected.DateTime.ToUniversalTime());

                actual = (DateTimeType)DefaultSerializer.Deserialize<DateTimeType>(input);

                Assert.AreEqual(actual.DateTime.ToUniversalTime(), expected.DateTime.ToUniversalTime());
            }
        }
        public void DateTimeDeserialization()
        {
            List<Tuple<DateTimeType, string>> testCases = new List<Tuple<DateTimeType, string>>() {
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{\"DateTime\":null}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime() }, "{\"DateTime\":\"0001-01-01T08:00:00.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(1999, 12, 31, 23, 59, 59) }, "{\"DateTime\":\"2000-01-01T07:59:59.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(2005, 3, 14, 12, 34, 16, DateTimeKind.Local).ToLocalTime() }, "{\"DateTime\":\"2005-03-14T20:34:16.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(2005, 4, 14, 12, 34, 16, DateTimeKind.Unspecified) }, "{\"DateTime\":\"2005-04-14T19:34:16.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(2005, 3, 14, 12, 34, 16, DateTimeKind.Local) }, "{\"DateTime\":\"2005-03-14T20:34:16.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(2005, 5, 14, 12, 34, 16, DateTimeKind.Utc).ToLocalTime() }, "{\"DateTime\":\"2005-05-14T12:34:16.000Z\"}"),
                new Tuple<DateTimeType, string>(new DateTimeType() { DateTime = new DateTime(2012, 2, 29, 12, 0, 0, DateTimeKind.Utc).ToLocalTime() }, "{\"DateTime\":\"2012-02-29T12:00:00.000Z\"}"), // Leap Day
            };

            // Need to ensure that the type is registered as a table to force the id property check
            DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(DateTimeType));

            foreach (var testCase in testCases)
            {
                var input = JToken.Parse(testCase.Item2);
                var expected = testCase.Item1;

                DateTimeType actual = new DateTimeType();
                DefaultSerializer.Deserialize(input, actual);

                Assert.AreEqual(actual.DateTime, expected.DateTime);

                if (testCase.Item2 != "{}")
                {
                    actual = new DateTimeType();
                    actual.DateTime = DateTime.Now;
                    DefaultSerializer.Deserialize(input, actual);
                }

                Assert.AreEqual(actual.DateTime, expected.DateTime);

                JArray json = JToken.Parse("[" + testCase.Item2 + "]") as JArray;
                actual = DefaultSerializer.Deserialize<DateTimeType>(json).FirstOrDefault();

                Assert.AreEqual(actual.DateTime, expected.DateTime);

                actual = (DateTimeType)DefaultSerializer.Deserialize<DateTimeType>(input);

                Assert.AreEqual(actual.DateTime, expected.DateTime);
            }
        }