예제 #1
0
        public void GivenListOfItems_WhenItemssAreValid_ReturnsTotalCostWithDiscounts()
        {
            //arrange
            var     listOfItems            = TestVariables.GetFakeListOfItems();
            Decimal totalApplePriceInList  = listOfItems.Where(x => x.ItemName.ToLower() == "apple").Sum(y => y.ItemPrice);
            Decimal totalOrangePriceInList = listOfItems.Where(x => x.ItemName.ToLower() == "orange").Sum(y => y.ItemPrice);

            var appleDiscountPercent  = 0.5M;
            var orangeDiscountPercent = 2M / 3M;

            var totalPriceInLIst = listOfItems.Sum(x => x.ItemPrice);

            var totalDiscountedPrice = totalPriceInLIst - ((totalApplePriceInList * appleDiscountPercent) + (totalOrangePriceInList * orangeDiscountPercent));


            var sut = new Checkout();

            //act
            var result = Decimal.Round(sut.CalculateTotalPriceAndApplyDiscounts(listOfItems), 2);

            //Assert
            Assert.Equal(Decimal.Round(totalDiscountedPrice, 2), result);
        }