Пример #1
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);
    }
}
Пример #2
0
    public void Null_Returns_Empty(object input)
    {
        // Arrange

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

        // Assert
        Assert.Equal(JsonF.Empty, result);
    }
Пример #3
0
    public void Serialise_Null_Returns_Empty_Json(Enumerated input)
    {
        // Arrange

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

        // Assert
        Assert.Equal(JsonF.Empty, result);
    }
Пример #4
0
    public void Returns_NewTestament_Books()
    {
        // Arrange
        const string?nt = "[\"Matthew\",\"Mark\",\"Luke\",\"John\",\"Acts\",\"Romans\",\"1 Corinthians\",\"2 Corinthians\",\"Galatians\",\"Ephesians\",\"Philippians\",\"Colossians\",\"1 Thessalonians\",\"2 Thessalonians\",\"1 Timothy\",\"2 Timothy\",\"Titus\",\"Philemon\",\"Hebrews\",\"James\",\"1 Peter\",\"2 Peter\",\"1 John\",\"2 John\",\"3 John\",\"Jude\",\"Revelation\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.NewTestament);

        // Assert
        Assert.Equal(nt, result);
    }
Пример #5
0
    public void Returns_MajorProphets_Books()
    {
        // Arrange
        const string?prophets = "[\"Isaiah\",\"Jeremiah\",\"Lamentations\",\"Ezekiel\",\"Daniel\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.MajorProphets);

        // Assert
        Assert.Equal(prophets, result);
    }
Пример #6
0
    public void Returns_Gospels()
    {
        // Arrange
        const string?gospels = "[\"Matthew\",\"Mark\",\"Luke\",\"John\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.Gospels);

        // Assert
        Assert.Equal(gospels, result);
    }
Пример #7
0
    public void Object_Input_String_Key_Returns_Encrypted_Json()
    {
        // Arrange

        // Act
        var json   = JsonF.Serialise(defaultInputObject);
        var result = defaultInputObject.Encrypt(defaultStringKey);

        // Assert
        Assert.NotEqual(json, result);
    }
Пример #8
0
    public void Returns_All_Books()
    {
        // Arrange
        const string?all = "[\"Genesis\",\"Exodus\",\"Leviticus\",\"Numbers\",\"Deuteronomy\",\"Joshua\",\"Judges\",\"Ruth\",\"1 Samuel\",\"2 Samuel\",\"1 Kings\",\"2 Kings\",\"1 Chronicles\",\"2 Chronicles\",\"Ezra\",\"Nehemiah\",\"Esther\",\"Job\",\"Psalms\",\"Proverbs\",\"Ecclesiastes\",\"Song of Songs\",\"Isaiah\",\"Jeremiah\",\"Lamentations\",\"Ezekiel\",\"Daniel\",\"Hosea\",\"Joel\",\"Amos\",\"Obadiah\",\"Jonah\",\"Micah\",\"Nahum\",\"Habakkuk\",\"Zephaniah\",\"Haggai\",\"Zechariah\",\"Malachi\",\"Matthew\",\"Mark\",\"Luke\",\"John\",\"Acts\",\"Romans\",\"1 Corinthians\",\"2 Corinthians\",\"Galatians\",\"Ephesians\",\"Philippians\",\"Colossians\",\"1 Thessalonians\",\"2 Thessalonians\",\"1 Timothy\",\"2 Timothy\",\"Titus\",\"Philemon\",\"Hebrews\",\"James\",\"1 Peter\",\"2 Peter\",\"1 John\",\"2 John\",\"3 John\",\"Jude\",\"Revelation\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.All);

        // Assert
        Assert.Equal(all, result);
    }
Пример #9
0
    public void Returns_Epistles()
    {
        // Arrange
        const string?epistles = "[\"Acts\",\"Romans\",\"1 Corinthians\",\"2 Corinthians\",\"Galatians\",\"Ephesians\",\"Philippians\",\"Colossians\",\"1 Thessalonians\",\"2 Thessalonians\",\"1 Timothy\",\"2 Timothy\",\"Titus\",\"Philemon\",\"Hebrews\",\"James\",\"1 Peter\",\"2 Peter\",\"1 John\",\"2 John\",\"3 John\",\"Jude\",\"Revelation\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.Epistles);

        // Assert
        Assert.Equal(epistles, result);
    }
Пример #10
0
    public void Returns_OldTestament_Books()
    {
        // Arrange
        const string?ot = "[\"Genesis\",\"Exodus\",\"Leviticus\",\"Numbers\",\"Deuteronomy\",\"Joshua\",\"Judges\",\"Ruth\",\"1 Samuel\",\"2 Samuel\",\"1 Kings\",\"2 Kings\",\"1 Chronicles\",\"2 Chronicles\",\"Ezra\",\"Nehemiah\",\"Esther\",\"Job\",\"Psalms\",\"Proverbs\",\"Ecclesiastes\",\"Song of Songs\",\"Isaiah\",\"Jeremiah\",\"Lamentations\",\"Ezekiel\",\"Daniel\",\"Hosea\",\"Joel\",\"Amos\",\"Obadiah\",\"Jonah\",\"Micah\",\"Nahum\",\"Habakkuk\",\"Zephaniah\",\"Haggai\",\"Zechariah\",\"Malachi\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.OldTestament);

        // Assert
        Assert.Equal(ot, result);
    }
Пример #11
0
    public void Returns_MinorProphets_Books()
    {
        // Arrange
        const string?prophets = "[\"Hosea\",\"Joel\",\"Amos\",\"Obadiah\",\"Jonah\",\"Micah\",\"Nahum\",\"Habakkuk\",\"Zephaniah\",\"Haggai\",\"Zechariah\",\"Malachi\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.MinorProphets);

        // Assert
        Assert.Equal(prophets, result);
    }
Пример #12
0
    public void Returns_Wisdom_Books()
    {
        // Arrange
        const string?wisdom = "[\"Job\",\"Psalms\",\"Proverbs\",\"Ecclesiastes\",\"Song of Songs\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.Wisdom);

        // Assert
        Assert.Equal(wisdom, result);
    }
Пример #13
0
    public void Returns_Law_Books()
    {
        // Arrange
        const string?law = "[\"Genesis\",\"Exodus\",\"Leviticus\",\"Numbers\",\"Deuteronomy\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.Law);

        // Assert
        Assert.Equal(law, result);
    }
Пример #14
0
    public void Returns_History_Books()
    {
        // Arrange
        const string?history = "[\"Joshua\",\"Judges\",\"Ruth\",\"1 Samuel\",\"2 Samuel\",\"1 Kings\",\"2 Kings\",\"1 Chronicles\",\"2 Chronicles\",\"Ezra\",\"Nehemiah\",\"Esther\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.History);

        // Assert
        Assert.Equal(history, result);
    }
Пример #15
0
    public void Returns_PaulineLetters()
    {
        // Arrange
        const string?pauline = "[\"Romans\",\"1 Corinthians\",\"2 Corinthians\",\"Galatians\",\"Ephesians\",\"Philippians\",\"Colossians\",\"1 Thessalonians\",\"2 Thessalonians\",\"1 Timothy\",\"2 Timothy\",\"Titus\",\"Philemon\"]";

        // Act
        var result = JsonF.Serialise(BibleBooks.PaulineLetters);

        // Assert
        Assert.Equal(pauline, result);
    }
Пример #16
0
	public void Object_Creates_With_Json()
	{
		// Arrange
		var value = new Test(Rnd.Str, Rnd.Int);
		var json = JsonF.Serialise(value).UnsafeUnwrap();

		// Act
		var result = Jsonb.Create(value);

		// Assert
		Assert.Equal(json, result.ToString());
	}
Пример #17
0
    public void Serialise_Returns_Json_Value()
    {
        // Arrange
        var value      = Rnd.Str;
        var enumerated = new EnumeratedTest(value);

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

        // Assert
        Assert.Equal($"\"{value}\"", result);
    }
Пример #18
0
    public void Serialise_None_Returns_Empty_Json()
    {
        // Arrange
        var maybe = Create.None <int>();

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

        // Assert
        var some = result.AssertSome();

        Assert.Equal(JsonF.Empty, some);
    }
Пример #19
0
    public void ArrayDoesNotContainBibleBooks_ReturnsOriginalArray()
    {
        // Arrange
        var array         = new[] { Rnd.Str, Rnd.Str, Rnd.Str, Rnd.Str };
        var shuffled      = array.Shuffle().ToList();
        var originalOrder = JsonF.Serialise(shuffled);

        // Act
        shuffled.SortBibleBooks(b => b);

        // Assert
        Assert.Equal(originalOrder, JsonF.Serialise(shuffled));
    }
 /// <summary>
 /// Assert that <paramref name="actual"/> and <paramref name="expected"/> are equal by
 /// serialising as JSON - to support anonymous types
 /// </summary>
 /// <param name="expected">Expected value</param>
 /// <param name="actual">Actual value</param>
 /// <exception cref="EqualJsonException"></exception>
 internal static void AssertEqualJson(object expected, object?actual)
 {
     try
     {
         Assert.Equal(
             expected: JsonF.Serialise(expected).UnsafeUnwrap(),
             actual: JsonF.Serialise(actual).UnsafeUnwrap()
             );
     }
     catch (EqualException ex)
     {
         throw new EqualJsonException($"Expected '{expected}' but value was '{actual}'.", ex);
     }
 }
Пример #21
0
    public void Serialise_Some_Returns_Some_Value_As_Json()
    {
        // Arrange
        var valueStr = Rnd.Str;
        var valueInt = Rnd.Int;
        var value    = new Test(valueStr, valueInt);
        var maybe    = F.Some(value);
        var json     = $"{{\"foo\":\"{valueStr}\",\"bar\":{valueInt}}}";

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

        // Assert
        var some = result.AssertSome();

        Assert.Equal(json, some);
    }
Пример #22
0
 /// <summary>
 /// Serialise object to JSON
 /// </summary>
 /// <param name="xml">T value</param>
 protected override string Format(T xml) =>
 JsonF.Serialise(xml).Unwrap(JsonF.Empty);
Пример #23
0
 /// <summary>
 /// Encode object as JSON
 /// </summary>
 /// <param name="obj">Content to be encoded</param>
 /// <param name="type">Content-type</param>
 public JsonHttpContent(object obj, string type) : base(JsonF.Serialise(obj).Unwrap(string.Empty), Encoding.UTF8, type)
 {
 }