예제 #1
0
        public void it_should_calculate_its_total()
        {
            // arrange
            var basket = new BasketModel();

            basket.ID = Guid.NewGuid();
            var basketLine1 = new VerifiedBasketLine();
            var basketLine2 = new VerifiedBasketLine();

            basketLine1.Price = 22.11M;
            basketLine1.Grams = 10;
            basketLine1.RowNo = 0;

            basketLine2.Price = 30.00M;
            basketLine2.Grams = 10;
            basketLine2.RowNo = 1;

            basket.Lines = new VerifiedBasketLine[2] {
                basketLine1, basketLine2
            };

            // assert
            Assert.Equal(2, basket.Lines.Length);
            Assert.Equal(52.11M, basket.Total);
        }
예제 #2
0
        public BasketModel UpdateBasket(UnverifiedBasket basket)
        {
            var newBasket = new BasketModel();

            if (basket.ID == Guid.Empty)
            {
                newBasket.ID = Guid.NewGuid();
            }
            else
            {
                newBasket.ID = basket.ID;
            }

            var newLines = new List <VerifiedBasketLine>();

            if (basket.Lines?.Length > 0)
            {
                foreach (var basketLine in basket.Lines)
                {
                    var cheese = this._cheeseCache.Read(basketLine.ProductID);
                    if (cheese != null)
                    {
                        var line = new VerifiedBasketLine();
                        line.Grams     = basketLine.Grams;
                        line.Name      = cheese.Name;
                        line.RowNo     = basketLine.RowNo;
                        line.Price     = Math.Round((basketLine.Grams * cheese.PricePerKG) / 1000, 2, MidpointRounding.AwayFromZero);
                        line.ProductID = cheese.ID;

                        newLines.Add(line);
                    }
                }
            }

            newBasket.Lines = newLines.ToArray();

            return(newBasket);
        }