public decimal CalculateTotal(IEnumerable <Product> products, string country = "Sweden") { var total = products.Sum(x => x.Price + (x.Price * _vatStore.Get(x.Category, country))); return(_discountLibrary .GetDiscounts() .Where(discount => discount.AppliesTo(products)) .Aggregate(total, (current, discount) => current - discount.Calculate(products))); }
public void SetUp() { _discountLibrary = A.Fake <IObtainDiscounts>(); _vatLibrary = A.Fake <IObtainVAT>(); _calculator = new PriceCalculator(_discountLibrary, _vatLibrary); A.CallTo(() => _vatLibrary.Get(A <ProductCategory> .Ignored, A <string> .Ignored)).Returns(0); _products = new List <Product>() { new Product("Apple", ProductCategory.Food, 10), new Product("Apple", ProductCategory.Food, 10), new Product("Hax phone", ProductCategory.Tech, 20000) }; }