public void ShoppingCartWithOneByWeightPriceLineItemTest() { // arrange ShoppingCart shoppingCart = new ShoppingCart { HasCoupon = false, CouponTotalPriceThreshold = 10.00m, CouponDiscount = 1.00m }; LineItem lineItem = new ByWeightPriceLineItem { ProductId = 1, Name = "Apples", WeightInPounds = 2.00, PricePerPound = 2.00m }; shoppingCart.Add(lineItem); //act decimal actualTotalPrice = shoppingCart.GetTotalPrice(); // assert const decimal expectedTotalPrice = 4.00m; Assert.AreEqual(expectedTotalPrice, actualTotalPrice); }
public void ByWeightPriceLineItemsSettersAndGetterTests() { // arrange ByWeightPriceLineItem fixedPriceLineItem = new ByWeightPriceLineItem { ProductId = 1, Name = "Oranges", PricePerPound = 2.00m, WeightInPounds = 1.50 }; //act int actualProductId = fixedPriceLineItem.ProductId; string actualName = fixedPriceLineItem.Name; decimal actualPricePerPound = fixedPriceLineItem.PricePerPound; double actualWeightInPounds = fixedPriceLineItem.WeightInPounds; // assert const int expectedProductId = 1; const string expectedName = "Oranges"; const decimal expectedPricePerPound = 2.00m; const double expectedWeightInPounds = 1.50; Assert.AreEqual(expectedProductId, actualProductId); Assert.AreEqual(expectedName, actualName); Assert.AreEqual(expectedPricePerPound, actualPricePerPound); Assert.AreEqual(expectedWeightInPounds, actualWeightInPounds); }
public void PrintByWeightLineItemTest() { // arrange ByWeightPriceLineItem byWeightPriceLineItem = new ByWeightPriceLineItem { ProductId = 3, Name = "Apples", PricePerPound = 1.00m, WeightInPounds = 1.75 }; //act string byWeightPriceLineItemString = byWeightPriceLineItem.ToString(); // assert Assert.AreNotEqual(0, byWeightPriceLineItemString.Length); }
private void Add(ByWeightPriceLineItem byWeightPriceLineItem) { if (byWeightPriceLineItem == null) { throw new ArgumentNullException("byWeightPriceLineItem"); } ByWeightPriceLineItem existingByWeightPriceLineItem = _uniqueByWeightPriceLineItemList.SingleOrDefault(p => p.ProductId == byWeightPriceLineItem.ProductId); if (existingByWeightPriceLineItem != null) { // if by weight item exists in shopping cart, then add new weight existingByWeightPriceLineItem.WeightInPounds += byWeightPriceLineItem.WeightInPounds; } else { // else add to shopping cart _uniqueByWeightPriceLineItemList.Add(byWeightPriceLineItem); } }