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

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

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

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

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

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

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

        var dto = new DateOnlyDto {
            Date = date
        };

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

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

        var nullableDto = new NullableDateOnlyDto {
            Date = date
        };

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

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