Refactor Code
Refactor Test Code
Rather than repeating the same test/behaviour for different values, we can make it data driven by giving the data in line:
[Theory]
[InlineData("Apple", 3, true, 2.00)]
[InlineData("Apple", 6, true, 4.00)]
[InlineData("Apple", 7, true, 5.00)]
[InlineData("Banana", 3, false, 3.00)]
[InlineData("Banana", 6, false, 6.00)]
public void Apply_BuyTwoGetOneFreeOffer_WhenApplicable(string itemName, int quantity, bool isEligible, double expectedTotal)
{
_mockOfferService.Setup(s => s.IsEligibleForBuyTwoGetOne(itemName)).Returns(isEligible);
_cart.AddItem(new Item(itemName, quantity, 1.00));
var total = _cart.CalculateTotalCost();
total.Should().Be(expectedTotal);
}
Repeat the tests to ensure they are passing.
Last updated