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

            var orangeDiscountPercent = Decimal.Round(2M / 3M, 2);


            var discountedPrice = Decimal.Round(totalOrangePriceInList * orangeDiscountPercent, 2);

            //I know there are 3 oranges
            var expectedResult = Decimal.Round((3 * Utility.orangeCost) * orangeDiscountPercent, 2);

            Assert.Equal(expectedResult, discountedPrice);
        }
예제 #2
0
        public void GivenListOfApples_WhenThereIs2For1Offer_AppliesCorrectyTheDiscount()
        {
            //arrange
            var     listOfItems           = TestVariables.GetFakeListOfItems();
            Decimal totalApplePriceInList = listOfItems.Where(x => x.ItemName.ToLower() == "apple").Sum(y => y.ItemPrice);

            var appleDiscountPercent = 0.5M;


            var discountedPrice = Decimal.Round(totalApplePriceInList * appleDiscountPercent, 2);

            //I know there are 2 apples

            var expectedResult = (2 * Utility.appleCost) * appleDiscountPercent;

            Assert.Equal(expectedResult, discountedPrice);
        }
예제 #3
0
        public void GivenListOfItems_WhenItemssAreValid_ReturnsTotalCost()
        {
            //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     totalPriceInLIst       = listOfItems.Sum(x => x.ItemPrice);

            var sut = new Checkout();
            //add


            //act
            var result = sut.CalculateTotalPrice(listOfItems);

            //Assert
            Assert.Equal((Decimal)totalPriceInLIst, (Decimal)result);
        }
예제 #4
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);
        }