public void DateTimeProperty_CorrectlyDeserialized(string value, DateTimeOffset expectedDateTime)
        {
            //arrange
            var jsonClass = new NullableDateTimeOffsetClass();

            //act
            _convert.FromJson(jsonClass, $"{{\"Property\":{value}}}");

            //assert
            Assert.That(jsonClass.Property, Is.EqualTo(expectedDateTime));
        }
        public void ToJson_Null_CorrectJson()
        {
            //arrange
            var dateTimeObject = new NullableDateTimeOffsetClass();

            dateTimeObject.Property = null;

            //act
            var json = ToJson(dateTimeObject);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Property\":null}"));
        }
        public void ToJson_Utc_CorrectJson()
        {
            //arrange
            var dateTimeObject = new NullableDateTimeOffsetClass();

            dateTimeObject.Property = new DateTime(2016, 1, 2, 23, 59, 58, 555, DateTimeKind.Utc);

            //act
            var json = ToJson(dateTimeObject);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Property\":\"2016-01-02T23:59:58.555+00:00\"}"));
        }
        public void ToJson_DateAndTime_CorrectJson()
        {
            //arrange
            var dateTimeObject = new NullableDateTimeOffsetClass();

            dateTimeObject.Property = new DateTimeOffset(new DateTime(2016, 1, 2, 23, 59, 58, 555), new TimeSpan(-9, -15, 00));

            //act
            var json = ToJson(dateTimeObject);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Property\":\"2016-01-02T23:59:58.555-09:15\"}"));
        }
        public void ToJson_DateOnly_CorrectJson()
        {
            //arrange
            var dateTimeObject = new NullableDateTimeOffsetClass();

            dateTimeObject.Property = new DateTimeOffset(new DateTime(2017, 3, 7), new TimeSpan(13, 00, 00));

            //act
            var json = ToJson(dateTimeObject);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Property\":\"2017-03-07T00:00:00+13:00\"}"));
        }
Beispiel #6
0
        public void ToJson_Local_CorrectJson()
        {
            //arrange
            var dateTimeObject = new NullableDateTimeOffsetClass();

            dateTimeObject.Property = new DateTime(2016, 1, 2, 23, 59, 58, 555, DateTimeKind.Local);

            //act
            var json = _convert.ToJson(dateTimeObject);

            //assert
            var offset  = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
            var sign    = offset.Duration().TotalMinutes >= 0 ? "+" : "-";
            var hours   = Math.Abs(offset.Hours).ToString("00");
            var minutes = offset.Minutes.ToString("00");

            Assert.That(json.ToString(), Is.EqualTo($"{{\"Property\":\"2016-01-02T23:59:58.555{sign}{hours}:{minutes}\"}}"));
        }
 protected abstract string ToJson(NullableDateTimeOffsetClass jsonClass);
        protected override string ToJson(NullableDateTimeOffsetClass jsonClass)
        {
            var jsonUtf8 = _convert.ToJsonUtf8(jsonClass);

            return(Encoding.UTF8.GetString(jsonUtf8));
        }
 protected override string ToJson(NullableDateTimeOffsetClass jsonClass)
 {
     return(_convert.ToJson(jsonClass).ToString());
 }