示例#1
0
    public void Null_Or_Empty_Returns_Empty_List(string input)
    {
        // Arrange

        // Act
        var result = EnumeratedList.Deserialise <Foo>(input);

        // Assert
        Assert.Empty(result);
    }
示例#2
0
    public void Incorrect_Json_Returns_Empty_List()
    {
        // Arrange
        const string?json = /*lang=json,strict*/ "{\"foo\":\"bar\"}";

        // Act
        var result = EnumeratedList.Deserialise <Foo>(json);

        // Assert
        Assert.Empty(result);
    }
示例#3
0
    public void Invalid_Json_Returns_Empty_List()
    {
        // Arrange
        var json = Rnd.Str;

        // Act
        var result = EnumeratedList.Deserialise <Foo>(json);

        // Assert
        Assert.Empty(result);
    }
示例#4
0
    public void Correct_Json_Returns_List()
    {
        // Arrange
        var itemA = new Foo(Rnd.Str);
        var itemB = new Foo(Rnd.Str);
        var itemC = new Foo(Rnd.Str);
        var itemD = new Foo(Rnd.Str);
        var json  = $"[\"{itemB}\",\"{itemD}\",\"{itemA}\",\"{itemC}\"]";

        // Act
        var result = EnumeratedList.Deserialise <Foo>(json);

        // Assert
        Assert.Collection(result,
                          b => Assert.Equal(itemB, b),
                          d => Assert.Equal(itemD, d),
                          a => Assert.Equal(itemA, a),
                          c => Assert.Equal(itemC, c)
                          );
    }
示例#5
0
 /// <summary>
 /// Parse from list of string values and convert
 /// </summary>
 /// <param name="xml">JSON string</param>
 protected override EnumeratedList <T> Parse(string xml) =>
 EnumeratedList.Deserialise <T>(xml);