Пример #1
0
    public void ValidJson_ReturnsObject()
    {
        // Arrange
        var v0    = Rnd.Lng;
        var v1    = Rnd.Str;
        var v2    = Rnd.Int;
        var v3    = Rnd.DateTime;
        var v4    = Rnd.Flip;
        var input =
            "{" +
            $"\"id\":\"{v0}\"," +
            $"\"str\":\"{v1}\"," +
            $"\"num\":{v2}," +
            $"\"dt\":\"{v3:s}\"," +
            $"\"mbe\":{JsonF.Bool(v4)}," +
            "\"empty\":null" +
            "}";
        var expected = new Test {
            Id = new(v0), Str = v1, Num = v2, DT = v3, Mbe = v4
        };

        // Act
        var result = JsonF.Deserialise <Test>(input).Unwrap(() => new Test());

        // Assert
        Assert.Equal(expected, result, new TestComparer());
    }
Пример #2
0
    public void Object_Returns_Json()
    {
        // Arrange
        var v0    = Rnd.Lng;
        var v1    = Rnd.Str;
        var v2    = Rnd.Int;
        var v3    = Rnd.DateTime;
        var v4    = Rnd.Flip;
        var input = new Test {
            Id = new(v0), Str = v1, Num = v2, DT = v3, Mbe = v4
        };
        var expected =
            "{" +
            $"\"id\":\"{v0}\"," +
            $"\"str\":\"{v1}\"," +
            $"\"num\":{v2}," +
            $"\"dt\":\"{v3:s}\"," +
            $"\"mbe\":{JsonF.Bool(v4)}," +
            "\"empty\":null" +
            "}";

        // Act
        var result = JsonF.Serialise(input);

        // Assert
        Assert.Equal(expected, result);
    }
}
Пример #3
0
    public void Returns_Correct_Value(bool value, string expected)
    {
        // Arrange

        // Act
        var result = JsonF.Bool(value);

        // Assert
        Assert.Equal(expected, result);
    }
Пример #4
0
    public void Returns_Json()
    {
        // Arrange
        var e0           = new EventModel(Rnd.DateTime, Rnd.DateTime, false, Rnd.Str, Rnd.Str, Rnd.Str, false);
        var e1           = new EventModel(Rnd.DateTime, Rnd.DateTime, false, Rnd.Str, Rnd.Str, Rnd.Str, true);
        var events       = ImmutableList.Create(e0, e1);
        var lastModified = Rnd.DateTime;
        var calendar     = new CalendarModel(events, lastModified);
        var tzid         = Rnd.Str;
        var jsonCalendar = new JsonCalendar(calendar, tzid);

        var expected =
            "{" +
            "\"calendar\":{" +
            "\"events\":{" +
            $"\"{lastModified:yyyyMMdd\\THHmmss}-000000\":{{" +
            $"\"start\":\"{e0.Start:s}\"," +
            $"\"end\":\"{e0.End:s}\"," +
            $"\"isAllDay\":{JsonF.Bool(e0.IsAllDay)}," +
            $"\"summary\":\"{e0.Summary}\"," +
            $"\"description\":\"{e0.Description}\"," +
            $"\"location\":\"{e0.Location}\"," +
            $"\"free\":{JsonF.Bool(e0.Free)}" +
            "}," +
            $"\"{lastModified:yyyyMMdd\\THHmmss}-000001\":{{" +
            $"\"start\":\"{e1.Start:s}\"," +
            $"\"end\":\"{e1.End:s}\"," +
            $"\"isAllDay\":{JsonF.Bool(e1.IsAllDay)}," +
            $"\"summary\":\"{e1.Summary}\"," +
            $"\"description\":\"{e1.Description}\"," +
            $"\"location\":\"{e1.Location}\"," +
            $"\"free\":{JsonF.Bool(e1.Free)}" +
            "}" +
            "}," +
            $"\"lastModified\":\"{lastModified:s}\"," +
            $"\"timezone\":\"{tzid}\"" +
            "}" +
            "}";

        // Act
        var result = jsonCalendar.ToString();

        // Assert
        Assert.Equal(expected, result);
    }