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); } }
public void Null_Returns_Empty(object input) { // Arrange // Act var result = JsonF.Serialise(input); // Assert Assert.Equal(JsonF.Empty, result); }
public void Serialise_Null_Returns_Empty_Json(Enumerated input) { // Arrange // Act var result = JsonF.Serialise(input); // Assert Assert.Equal(JsonF.Empty, result); }
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); }
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); }
public void Returns_Gospels() { // Arrange const string?gospels = "[\"Matthew\",\"Mark\",\"Luke\",\"John\"]"; // Act var result = JsonF.Serialise(BibleBooks.Gospels); // Assert Assert.Equal(gospels, result); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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()); }
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); }
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); }
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); } }
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); }
/// <summary> /// Serialise object to JSON /// </summary> /// <param name="xml">T value</param> protected override string Format(T xml) => JsonF.Serialise(xml).Unwrap(JsonF.Empty);
/// <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) { }