| Name | Message | Date |
|---|---|---|
| 📄 DeserializeShould.cs | 1 day ago |
📄
test/JsonLdRecipeParser.Tests/Json/JsonLdSerializerContextTests/DeserializeShould.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System; using System.Text.Json; using JsonLdRecipeParser.Json; using Microsoft.VisualStudio.TestTools.UnitTesting; using Shouldly; namespace JsonLdRecipeParser.Tests.Json.JsonLdSerializerContextTests; [TestClass] public class DeserializeShould { [TestMethod] public void DeserializeAnEmptyArray() { // Arrange var json = "[]"; // Act var result = JsonSerializer.Deserialize(json, JsonLdSerializerContext.Default.JsonLd); // Assert result.ShouldNotBeNull(); var things = result.Value.ShouldBeOfType<Thing[]>(); things.ShouldBeEmpty(); } [TestMethod] public void DeserializeJsonLdFromGoogleExample() { // Act var result = JsonSerializer.Deserialize(TestData.GoogleExample, JsonLdSerializerContext.Default.JsonLd); // Assert result.ShouldNotBeNull(); var recipe = result.Value.ShouldBeOfType<JsonLdRecipeParser.Json.Recipe>(); recipe.ShouldBeEquivalentTo( new JsonLdRecipeParser.Json.Recipe { Name = "Non-Alcoholic Piña Colada", Description = "This non-alcoholic pina colada is everyone's favorite!", Author = new Authors { Value = new JsonLdRecipeParser.Json.Author { Value = new Person { Name = "Mary Stone" } }, }, PrepTime = TimeSpan.FromMinutes(1), TotalTime = TimeSpan.FromMinutes(3), CookTime = TimeSpan.FromMinutes(2), Nutrition = new NutritionInformation { Calories = new Quantity { Value = "120 calories" } }, RecipeCategory = new RecipeCategories { Value = "Drink" }, RecipeCuisine = new RecipeCuisines { Value = "American" }, RecipeIngredient = [ new RecipeIngredient { Value = "400ml of pineapple juice" }, new RecipeIngredient { Value = "100ml cream of coconut" }, new RecipeIngredient { Value = "ice" }, ], RecipeInstructions = [ new RecipeInstruction { Value = new HowToStep { Name = "Blend", Text = "Blend 400ml of pineapple juice and 100ml cream of coconut until smooth.", }, }, new RecipeInstruction { Value = new HowToStep { Name = "Fill", Text = "Fill a glass with ice." }, }, new RecipeInstruction { Value = new HowToStep { Name = "Pour", Text = "Pour the pineapple juice and coconut mixture over ice.", }, }, ], RecipeYield = new Quantity { Value = "4 servings" }, } ); } [TestMethod] public void DeserializeJsonLdFromGoogleExampleInArray() { // Arrange const string json = $"[{TestData.GoogleExample}]"; // Act var result = JsonSerializer.Deserialize(json, JsonLdSerializerContext.Default.JsonLd); // Assert result.ShouldNotBeNull(); var things = result.Value.ShouldBeOfType<Thing[]>(); things.Length.ShouldBe(1); things[0].ShouldBeOfType<JsonLdRecipeParser.Json.Recipe>(); } }