Пример #1
0
    public void Can_json_serialize_TimeOnly()
    {
        var time = new TimeOnly(13, 13, 13);
        var json = time.ToJson();

        Assert.That(json, Is.EqualTo("\"PT13H13M13S\""));

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

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

        var dto = new TimeOnlyDto {
            Time = time
        };

        json = dto.ToJson();
        Assert.That(json, Is.EqualTo("{\"Time\":\"PT13H13M13S\"}"));
        var fromJsonDto = json.FromJson <TimeOnlyDto>();

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

        var nullableDto = new NullableTimeOnlyDto {
            Time = time
        };

        json = nullableDto.ToJson();
        Assert.That(json, Is.EqualTo("{\"Time\":\"PT13H13M13S\"}"));
        var fromJsonNullableDto = json.FromJson <NullableTimeOnlyDto>();

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