📄 test/JsonLdRecipeParser.Tests/InstructionSectionTests/FromShould.cs
using JsonLdRecipeParser.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;

namespace JsonLdRecipeParser.Tests.InstructionSectionTests;

[TestClass]
public class FromShould
{
    [TestMethod]
    public void MapAStringRecipeInstruction()
    {
        // Arrange
        var instruction = new RecipeInstruction { Value = "Mix well and serve." };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection { Instructions = [new Instruction { Text = "Mix well and serve." }] }
        );
    }

    [TestMethod]
    public void MapAHowToStepRecipeInstruction()
    {
        // Arrange
        var instruction = new RecipeInstruction
        {
            Value = new HowToStep { Name = "Blend", Text = "Blend until smooth." },
        };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection { Instructions = [new Instruction { Name = "Blend", Text = "Blend until smooth." }] }
        );
    }

    [TestMethod]
    public void MapAHowToSectionRecipeInstructionWithStringSteps()
    {
        // Arrange
        var instruction = new RecipeInstruction
        {
            Value = new HowToSection
            {
                Name = "Prepare the batter",
                ItemListElement =
                [
                    new ItemListElement { Value = "Sift the flour." },
                    new ItemListElement { Value = "Add the eggs." },
                ],
            },
        };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection
            {
                Name = "Prepare the batter",
                Instructions =
                [
                    new Instruction { Text = "Sift the flour." },
                    new Instruction { Text = "Add the eggs." },
                ],
            }
        );
    }

    [TestMethod]
    public void MapAHowToSectionRecipeInstructionWithHowToStepElements()
    {
        // Arrange
        var instruction = new RecipeInstruction
        {
            Value = new HowToSection
            {
                Name = "Cook",
                ItemListElement =
                [
                    new ItemListElement
                    {
                        Value = new HowToStep { Name = "Heat", Text = "Heat the pan." },
                    },
                    new ItemListElement
                    {
                        Value = new HowToStep { Name = "Fry", Text = "Fry until golden." },
                    },
                ],
            },
        };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection
            {
                Name = "Cook",
                Instructions =
                [
                    new Instruction { Name = "Heat", Text = "Heat the pan." },
                    new Instruction { Name = "Fry", Text = "Fry until golden." },
                ],
            }
        );
    }

    [TestMethod]
    public void MapAnItemListRecipeInstructionWithStringElements()
    {
        // Arrange
        var instruction = new RecipeInstruction
        {
            Value = new ItemList
            {
                Name = "Steps",
                ItemListElement =
                [
                    new ItemListElement { Value = "Step one." },
                    new ItemListElement { Value = "Step two." },
                ],
            },
        };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection
            {
                Name = "Steps",
                Instructions = [new Instruction { Text = "Step one." }, new Instruction { Text = "Step two." }],
            }
        );
    }

    [TestMethod]
    public void MapAnItemListRecipeInstructionWithNestedHowToStepElements()
    {
        // Arrange
        var instruction = new RecipeInstruction
        {
            Value = new ItemList
            {
                ItemListElement =
                [
                    new ItemListElement
                    {
                        Value = new HowToStep { Name = "Mix", Text = "Mix ingredients." },
                    },
                ],
            },
        };

        // Act
        var result = InstructionSection.From(instruction);

        // Assert
        result.ShouldBeEquivalentTo(
            new InstructionSection { Instructions = [new Instruction { Name = "Mix", Text = "Mix ingredients." }] }
        );
    }
}