Beispiel #1
0
        public void DateTimeProperty_CorrectlyDeserialized(string value, DateTime expectedDateTime, DateTimeKind expectedKind)
        {
            //arrange
            var jsonClass = new DateTimeClass();

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

            //assert
            Assert.That(jsonClass.Property, Is.EqualTo(expectedDateTime));
            Assert.That(jsonClass.Property.Kind, Is.EqualTo(expectedKind));
        }
Beispiel #2
0
        public void ToJson_DateAndTimeNoOffset_CorrectJson()
        {
            //arrange
            var dateTimeObject = new DateTimeClass();

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

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

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

            dateTimeObject.Property = new DateTime(2017, 3, 7);

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

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Property\":\"2017-03-07T00:00:00\"}"));
        }
        public void ToJson_Utc_CorrectJson()
        {
            //arrange
            var dateTimeObject = new DateTimeClass();

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

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

            //assert
            Assert.That(json, Is.EqualTo("{\"Property\":\"2016-01-02T23:59:58.555Z\"}"));
        }
Beispiel #5
0
        public void ToJson_Local_CorrectJson()
        {
            //arrange
            var dateTimeObject = new DateTimeClass();

            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}\"}}"));
        }
Beispiel #6
0
 protected abstract string ToJson(DateTimeClass jsonClass);
Beispiel #7
0
        protected override string ToJson(DateTimeClass jsonClass)
        {
            var jsonUtf8 = _convert.ToJsonUtf8(jsonClass);

            return(Encoding.UTF8.GetString(jsonUtf8));
        }
Beispiel #8
0
 protected override string ToJson(DateTimeClass jsonClass)
 {
     return(_convert.ToJson(jsonClass).ToString());
 }