public void When_Creating_A_Serving_Then_Food_Cannot_Be_Null() { #pragma warning disable 8625 Action constructor = () => _ = new ServingOfFood(null, 1); #pragma warning restore 8625 constructor.Should().ThrowExactly <ArgumentNullException>(); }
public void When_Creating_A_Serving_Then_Servings_Must_Be_Greater_Than_Zero( [Values(-1f, -0.1f, -0.01f, -0f, 0f)] float badServings) { Action constructor = () => _ = new ServingOfFood(new Food("test"), badServings); constructor.Should().ThrowExactly <ArgumentOutOfRangeException>() .WithMessage("A serving of food must be a positive value.*"); }
public void Then_Protein_Energy_Ratio_Is_Correct( [ValueSource(nameof(PeRatioTestCases))] PERatioTestCase testData, [Values(0.01f, 0.1f, 1f, 2.5f, 10f)] float servingSize) { var food = new Food("fake food") { Carbohydrates = testData.Carbs, Fat = testData.Fat, Fiber = testData.Fiber, Protein = testData.Protein }; var model = new ServingOfFood(food, servingSize); model.PERatio.Should().BeApproximately(testData.ExpectedRatio, 0.001f); }
public void When_Creating_A_Serving_Of_Food_Then_Properties_Match_Values( [Values(0.01f, 0.1f, 1f, 12.13f)] float expectedServings) { var expectedFood = new Food("test food") { Protein = 11.12f, Carbohydrates = 13.1f, Description = "Fake description", Fat = 13.12f, Fiber = 1 }; var model = new ServingOfFood(expectedFood, expectedServings); using (new AssertionScope()) { model.Food.Should().BeEquivalentTo(expectedFood); model.Servings.Should().BeApproximately(expectedServings, 0.001f); } }
public void Then_Macronutrients_Are_Multiplied_By_Serving_Size( [ValueSource(nameof(PeRatioTestCases))] PERatioTestCase testData, [Values(0.01f, 0.1f, 1f, 2.5f, 10f)] float servingSize) { var food = new Food("fake food") { Carbohydrates = testData.Carbs, Fat = testData.Fat, Fiber = testData.Fiber, Protein = testData.Protein }; var model = new ServingOfFood(food, servingSize); using (new AssertionScope()) { model.TotalCarbs.Should().Be(testData.Carbs < 0 ? 0 : testData.Carbs * servingSize); model.TotalFat.Should().Be(testData.Fat < 0 ? 0 : testData.Fat * servingSize); model.TotalFiber.Should().Be(testData.Fiber < 0 ? 0 : testData.Fiber * servingSize); model.TotalProtein.Should().Be(testData.Protein < 0 ? 0 : testData.Protein * servingSize); } }