public void ShoppingCart_AddingTwoIdentical() { // arrange ShoppingCart shoppingCart = new ShoppingCart(); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p1.productId = 124; p1.productName = "Apple"; p1.unitPrice = 2.49m; p1.addWeight(2.4m); ProductSellByWeight p2 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p2.productId = 124; p2.productName = "Apple"; p2.unitPrice = 2.49m; p2.addWeight(1.3m); //act shoppingCart.add((ProductSell)p1); shoppingCart.add((ProductSell)p2); decimal totalPrice = shoppingCart.getTotalPrice(); int totalItemNumber = shoppingCart.getTotalItemNumber(); // assert const decimal expectedTotalPrice = 2.49m * 3.7m; const int expectedTotalItemNumber = 1; Assert.AreEqual(expectedTotalPrice, totalPrice); Assert.AreEqual(expectedTotalItemNumber, totalItemNumber); }
public void ShoppingCart_AddingTwoIdenticalProductID_WithConflictedProductName() { // arrange ShoppingCart shoppingCart = new ShoppingCart(); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p1.productId = 124; p1.productName = "xxxx"; p1.unitPrice = 2.49m; p1.addWeight(2.4m); ProductSellByWeight p2 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p2.productId = 124; p2.productName = "yyyy"; p2.unitPrice = 2.49m; p2.addWeight(1.3m); //act shoppingCart.add((ProductSell)p1); shoppingCart.add((ProductSell)p2); // assert //Must throw ArgumentOutOfRangeException : There is a conflict on the given ProductName. }
private void add(ProductSellByWeight productSellByWeight) { if (productSellByWeight != null) { ProductSell existingProductSell = productSellList.SingleOrDefault(productSell => productSell.productId == productSellByWeight.productId); if (existingProductSell == null) { productSellList.Add(productSellByWeight as ProductSell); } else { if (!existingProductSell.productName.Equals(productSellByWeight.productName)) { throw new ArgumentException("There is a conflict on the given productName"); } else if (existingProductSell.unitPrice != productSellByWeight.unitPrice) { throw new ArgumentException("There is a conflict on the given unitPrice"); } else { ((ProductSellByWeight)existingProductSell).addWeight(productSellByWeight.weight); } } } else { throw new ArgumentNullException("ProductSellByWeight"); } }
public void ProductSellByWeight_SettersAndGetterTest() { // arrange ProductSellByWeight productSellByWeight = new ProductSellByWeight { productId = 124, productName = "Apple", unitPrice = 2.49m }; productSellByWeight.addWeight(2.4m); //act int actualProductId = productSellByWeight.productId; string actualProductName = productSellByWeight.productName; decimal actualUnitPrice = productSellByWeight.unitPrice; decimal actualweight = productSellByWeight.weight; // assert const int expectedProductId = 124; const string expectedProductName = "Apple"; const decimal expectedUnitPrice = 2.49m; const decimal expectedweight = 2.4m; Assert.AreEqual(expectedProductId, actualProductId); Assert.AreEqual(expectedProductName, actualProductName); Assert.AreEqual(expectedUnitPrice, actualUnitPrice); Assert.AreEqual(expectedweight, actualweight); }
public void ProductSellByWeight_EmptyTest() { // arrange ProductSellByWeight p = new ProductSellByWeight(); //act decimal price = p.getPrice(); // assert Assert.AreEqual(0, price); }
public void ShoppingCart_AddingInvalidEmptyProductSell() { // arrange ShoppingCart shoppingCart = new ShoppingCart(); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); //act shoppingCart.add((ProductSell)p); // assert //Must throw ArgumentOutOfRangeException : productSell does not contain valid attributes }
public void ShoppingCart_RemoveProductSell() { // arrange ShoppingCart shoppingCart = new ShoppingCart(); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p1.productId = 124; p1.productName = "Apple"; p1.unitPrice = 2.49m; p1.addWeight(2.4m); ProductSellByQuantity p2 = (ProductSellByQuantity)productSellFactory.GetProductSell(ProductSellType.byQuantity); p2.productId = 276; p2.productName = "Boxes of Cheerios"; p2.unitPrice = 6.99m; p2.addQuantity(4); ProductSellByQuantityInGroupSell p3 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell); p3.productId = 312; p3.productName = "Body Shampoo"; p3.unitPrice = 12.99m; p3.addQuantity(3); p3.discountThreshold = 3; ProductSellByQuantityInGroupSell p4 = (ProductSellByQuantityInGroupSell)productSellFactory.GetProductSell(ProductSellType.byQuantityInGroupSell); p4.productId = 312; p4.productName = "Body Shampoo"; p4.unitPrice = 12.99m; p4.addQuantity(1); p4.discountThreshold = 3; //act shoppingCart.add((ProductSell)p1); shoppingCart.add((ProductSell)p2); shoppingCart.add((ProductSell)p3); shoppingCart.add((ProductSell)p4); shoppingCart.remove((ProductSell)p2); decimal totalPrice = shoppingCart.getTotalPrice(); int totalItemNumber = shoppingCart.getTotalItemNumber(); // assert const decimal expectedTotalPrice = 2.49m * 2.4m + 12.99m * 3; const int expectedTotalItemNumber = 2; Assert.AreEqual(expectedTotalPrice, totalPrice); Assert.AreEqual(expectedTotalItemNumber, totalItemNumber); }
public void ShoppingCartByCoupon_InValidTotalPriceDiscountThreshold() { // arrange ShoppingCartByCoupon shoppingCart = new ShoppingCartByCoupon(new ShoppingCart(), -1, 100); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p1 = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p1.productId = 124; p1.productName = "Apple"; p1.unitPrice = 2.49m; p1.addWeight(2.4m); //act shoppingCart.add((ProductSell)p1); decimal totalPrice = shoppingCart.getTotalPrice(); int totalItemNumber = shoppingCart.getTotalItemNumber(); // assert //Must throw ArgumentOutOfRangeException : DiscountCouponValue does not contain a valid value. }
public void ProductSellByWeight_PriceTest() { // arrange ProductSellByWeight p = new ProductSellByWeight { productId = 124, productName = "Apple", unitPrice = 2.49m }; p.addWeight(2.4m); //act decimal price = p.getPrice(); // assert const decimal expectedPrice = 2.49m * 2.4m; Assert.AreEqual(expectedPrice, price); }
public void ShoppingCart_AddingSingle() { // arrange ShoppingCart shoppingCart = new ShoppingCart(); ProductSellFactory productSellFactory = new ProductSellFactory(); ProductSellByWeight p = (ProductSellByWeight)productSellFactory.GetProductSell(ProductSellType.byWeight); p.productId = 124; p.productName = "Apple"; p.unitPrice = 2.49m; p.addWeight(2.4m); //act shoppingCart.add((ProductSell)p); decimal totalPrice = shoppingCart.getTotalPrice(); // assert const decimal expectedTotalPrice = 2.49m * 2.4m; Assert.AreEqual(expectedTotalPrice, totalPrice); }