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

namespace JsonLdRecipeParser.Tests.NutrientsTests;

[TestClass]
public class FromShould
{
    [TestMethod]
    public void MapStringQuantities()
    {
        // Arrange
        var nutrition = new NutritionInformation
        {
            Calories = new Quantity { Value = "120 calories" },
            CarbohydrateContent = new Quantity { Value = "10 g" },
            CholesterolContent = new Quantity { Value = "0 mg" },
            FatContent = new Quantity { Value = "5 g" },
            FiberContent = new Quantity { Value = "2 g" },
            ProteinContent = new Quantity { Value = "3 g" },
            SaturatedFatContent = new Quantity { Value = "1 g" },
            ServingSize = new Quantity { Value = "1 cup" },
            SodiumContent = new Quantity { Value = "200 mg" },
            SugarContent = new Quantity { Value = "4 g" },
            TransFatContent = new Quantity { Value = "0 g" },
            UnsaturatedFatContent = new Quantity { Value = "4 g" },
        };

        // Act
        var result = Nutrients.From(nutrition);

        // Assert
        result.ShouldBeEquivalentTo(
            new Nutrients
            {
                Calories = new Amount { Value = new ExactAmountValue(120.0d), Unit = "calories" },
                Carbohydrate = new Amount { Value = new ExactAmountValue(10.0d), Unit = "g" },
                Cholesterol = new Amount { Value = new ExactAmountValue(0.0d), Unit = "mg" },
                Fat = new Amount { Value = new ExactAmountValue(5.0d), Unit = "g" },
                Fiber = new Amount { Value = new ExactAmountValue(2.0d), Unit = "g" },
                Protein = new Amount { Value = new ExactAmountValue(3.0d), Unit = "g" },
                SaturatedFat = new Amount { Value = new ExactAmountValue(1.0d), Unit = "g" },
                ServingSize = new Amount { Value = new ExactAmountValue(1.0d), Unit = "cup" },
                Sodium = new Amount { Value = new ExactAmountValue(200.0d), Unit = "mg" },
                Sugar = new Amount { Value = new ExactAmountValue(4.0d), Unit = "g" },
                TransFat = new Amount { Value = new ExactAmountValue(0.0d), Unit = "g" },
                UnsaturatedFat = new Amount { Value = new ExactAmountValue(4.0d), Unit = "g" },
            }
        );
    }

    [TestMethod]
    public void MapQuantitativeValueQuantities()
    {
        // Arrange
        var nutrition = new NutritionInformation
        {
            Calories = new Quantity
            {
                Value = new QuantitativeValue
                {
                    Value = new ValueProperty { Value = 120.0d },
                    UnitText = "calories",
                },
            },
        };

        // Act
        var result = Nutrients.From(nutrition);

        // Assert
        result.ShouldBeEquivalentTo(
            new Nutrients
            {
                Calories = new Amount { Value = new ExactAmountValue(120.0d), Unit = "calories" },
            }
        );
    }

    [TestMethod]
    public void MapNullNutrientFields()
    {
        // Arrange
        var nutrition = new NutritionInformation { Calories = new Quantity { Value = "120 calories" } };

        // Act
        var result = Nutrients.From(nutrition);

        // Assert
        result.ShouldBeEquivalentTo(
            new Nutrients
            {
                Calories = new Amount { Value = new ExactAmountValue(120.0d), Unit = "calories" },
            }
        );
        result.Carbohydrate.ShouldBeNull();
        result.Cholesterol.ShouldBeNull();
        result.Fat.ShouldBeNull();
        result.Fiber.ShouldBeNull();
        result.Protein.ShouldBeNull();
        result.SaturatedFat.ShouldBeNull();
        result.ServingSize.ShouldBeNull();
        result.Sodium.ShouldBeNull();
        result.Sugar.ShouldBeNull();
        result.TransFat.ShouldBeNull();
        result.UnsaturatedFat.ShouldBeNull();
    }
}