📄 test/JsonLdRecipeParser.Tests/RecipeTests/ParseShould.cs
using System;
using System.Text.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

namespace JsonLdRecipeParser.Tests.RecipeTests;

[TestClass]
public class ParseShould
{
    [TestMethod]
    public void ParseJsonLdFromGoogleExample()
    {
        // Arrange
        var document = JsonSerializer.Deserialize<JsonDocument>(TestData.GoogleExample)!;

        // Act
        var result = Recipe.Parse(document);

        // Assert
        result.ShouldBeEquivalentTo(expectedGoogleExampleRecipe);
    }

    [TestMethod]
    public void ParseJsonLdFromGoogleExampleInArray()
    {
        // Arrange
        var document = JsonSerializer.Deserialize<JsonDocument>($"[{TestData.GoogleExample}]")!;

        // Act
        var result = Recipe.Parse(document);

        // Assert
        result.ShouldBeEquivalentTo(expectedGoogleExampleRecipe);
    }

    private static readonly Recipe expectedGoogleExampleRecipe = new()
    {
        Name = "Non-Alcoholic Piña Colada",
        Description = "This non-alcoholic pina colada is everyone's favorite!",
        Authors = [new Author { Name = "Mary Stone" }],
        PrepTime = TimeSpan.FromMinutes(1),
        TotalTime = TimeSpan.FromMinutes(3),
        CookTime = TimeSpan.FromMinutes(2),
        Nutrients = new Nutrients
        {
            Calories = new Amount { Value = new ExactAmountValue(120.0d), Unit = "calories" },
        },
        Category = ["Drink"],
        Cuisine = ["American"],
        Ingredients =
        [
            new Ingredient
            {
                Name = "of",
                Amount = new Amount { Value = new ExactAmountValue(400.0d), Unit = "ml" },
            },
            new Ingredient
            {
                Name = "cream",
                Amount = new Amount { Value = new ExactAmountValue(100.0d), Unit = "ml" },
            },
            new Ingredient { Name = "ice" },
        ],
        InstructionSections =
        [
            new InstructionSection
            {
                Instructions =
                [
                    new Instruction
                    {
                        Name = "Blend",
                        Text = "Blend 400ml of pineapple juice and 100ml cream of coconut until smooth.",
                    },
                ],
            },
            new InstructionSection
            {
                Instructions = [new Instruction { Name = "Fill", Text = "Fill a glass with ice." }],
            },
            new InstructionSection
            {
                Instructions =
                [
                    new Instruction { Name = "Pour", Text = "Pour the pineapple juice and coconut mixture over ice." },
                ],
            },
        ],
        Yield = new Amount { Value = new ExactAmountValue(4.0d), Unit = "servings" },
    };
}