Exemple #1
0
    public void Can_jsv_serialize_DateOnly_UnixTime()
    {
        using (JsConfig.With(new Config {
            DateHandler = DateHandler.UnixTime
        }))
        {
            var date = new DateOnly(2001, 1, 13);
            var json = date.ToJsv();
            Assert.That(json, Is.EqualTo("979344000"));

            var fromJson = json.FromJsv <DateOnly>();
            Assert.That(fromJson, Is.EqualTo(date));

            var dto = new DateOnlyDto {
                Date = date
            };
            json = dto.ToJsv();
            Assert.That(json, Is.EqualTo("{Date:979344000}"));

            var nullableDto = new NullableDateOnlyDto {
                Date = date
            };
            json = nullableDto.ToJsv();
            Assert.That(json, Is.EqualTo("{Date:979344000}"));
        }
    }
Exemple #2
0
    public void Can_jsv_serialize_DateOnly()
    {
        var date = new DateOnly(2001, 1, 13);
        var json = date.ToJsv();

        Assert.That(json, Is.EqualTo("2001-01-13"));

        var fromJson = json.FromJsv <DateOnly>();

        Assert.That(fromJson, Is.EqualTo(date));

        var dto = new DateOnlyDto {
            Date = date
        };

        json = dto.ToJsv();
        Assert.That(json, Is.EqualTo("{Date:2001-01-13}"));
        var fromJsonDto = json.FromJsv <DateOnlyDto>();

        Assert.That(fromJsonDto, Is.EqualTo(dto));

        var nullableDto = new NullableDateOnlyDto {
            Date = date
        };

        json = nullableDto.ToJsv();
        Assert.That(json, Is.EqualTo("{Date:2001-01-13}"));
        var fromJsonNullableDto = json.FromJsv <NullableDateOnlyDto>();

        Assert.That(fromJsonNullableDto, Is.EqualTo(nullableDto));
    }