static void Main(string[] args) { var cart = new Cart(Inventory.Instance()); cart.Add('A', 7); cart.Add('B', 7); cart.Add('C', 4); Console.WriteLine(cart.CheckOut()); Console.ReadLine(); }
public void Test_add_2_different_books_to_cart_then_checkout_total_should_be_equal_sell_price_5_percent_save_off() { // Arrange var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 }; var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 }; var expected = 190; var target = new Cart(); target.Add(book_1); target.Add(book_2); target.Checkout(); // Act var actual = target.Total; // Assert Assert.AreEqual(expected, actual); }
public void Test_add_1_book_to_cart_then_checkout_total_should_be_equal_sell_price() { // Arrange var book = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 }; var expected = 100; var target = new Cart(); target.Add(book); target.Checkout(); // Act var actual = target.Total; // Assert Assert.AreEqual(expected, actual); }
static void Main(string[] args) { //number of items which can be added in inventory, can be any number var numberOfItems = 100; var userInput = string.Empty; //to indicate if adding items to inventory is finished bool stageOneFinished = false; var currentCart = new List <InventoryModel> { }; //derived classed initialization InventoryStore inventory = new InventoryStore(); Cart shoppingCart = new Cart(inventory.items); //loop so console application doesn't get closed for (int i = 0; i < numberOfItems; i++) { if (!stageOneFinished) { //display message just once, on opening app if (i == 0) { Console.WriteLine("Add items to inventory in expected input format: \nADD sku(number) name(string) quantity(number) price(number i.e 3.5)"); } //read user input userInput = Console.ReadLine().ToUpper(); //check for user command ADD if (userInput.Contains("ADD")) { //check number of elements in user input, splitted by space if (userInput.Split(' ').Length == 5) { int sku, quantity; float price; //try parse array elements bool convertSku = int.TryParse(userInput.Split(' ')[1], out sku); string name = userInput.Split(' ')[2].ToLower(); bool convertQuantity = int.TryParse(userInput.Split(' ')[3], out quantity); bool convertPrice = float.TryParse(userInput.Split(' ')[4].Replace('.', ','), out price); //check if all elements are succesfully parsed, if yes call add method if (convertSku && convertQuantity && convertPrice) { inventory.Add(sku, name, quantity, price); } else { Console.WriteLine("Add item in expected input format!"); } } else { Console.WriteLine("Some input parameters missing!"); } } //user END command else if (userInput.Contains("END")) { inventory.End(); //set stage one to finished stageOneFinished = true; userInput = string.Empty; } } else { //display message just once, on proceeding to stage two if (inventory.items.Count == i - 1) { Console.WriteLine("Additem to the current shopping cart in expected input format: \nADD sku(number) quantity(number)"); } userInput = Console.ReadLine().ToUpper(); if (userInput.Contains("ADD")) { if (userInput.Split(' ').Length == 3) { int sku, quantity; bool convertSku = int.TryParse(userInput.Split(' ')[1], out sku); bool convertQuantity = int.TryParse(userInput.Split(' ')[2], out quantity); if (convertSku && convertQuantity) { currentCart = shoppingCart.Add(sku, quantity); } else { Console.WriteLine("Add item in expected input format!"); } } else { Console.WriteLine("Some input parameters missing!"); } } else if (userInput.Contains("REMOVE")) { if (userInput.Split(' ').Length == 3) { var sku = int.Parse(userInput.Split(' ')[1]); var quantity = int.Parse(userInput.Split(' ')[2]); currentCart = shoppingCart.Remove(sku, quantity); } } //call cart checkout method else if (userInput.Contains("CHECKOUT")) { shoppingCart.Checkout(currentCart); } //exist console app else if (userInput.Contains("END")) { shoppingCart.End(); } } } }
public void Test_add_3_diff_1_same_books_to_cart_then_checkout_total_should_be_equal_370() { // Arrange var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 }; var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 }; var book_3 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 }; var book_4 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 }; var expected = 370; var target = new Cart(); target.Add(book_1); target.Add(book_2); target.Add(book_3); target.Add(book_4); target.Checkout(); // Act var actual = target.Total; // Assert Assert.AreEqual(expected, actual); }
public void Test_add_5_different_books_to_cart_then_checkout_total_should_be_equal_sell_price_25_percent_save_off() { // Arrange var book_1 = new Book { Id = 1, Name = "Harry Potter and the Philosopher's Stone", SellPrice = 100 }; var book_2 = new Book { Id = 2, Name = "Harry Potter and the Chamber of Secrets", SellPrice = 100 }; var book_3 = new Book { Id = 3, Name = "Harry Potter and the Prisoner of Azkaban", SellPrice = 100 }; var book_4 = new Book { Id = 4, Name = "Harry Potter and the Goblet of Fire", SellPrice = 100 }; var book_5 = new Book { Id = 5, Name = "Harry Potter and the Order of the Phoenix", SellPrice = 100 }; var expected = 375; var target = new Cart(); target.Add(book_1); target.Add(book_2); target.Add(book_3); target.Add(book_4); target.Add(book_5); target.Checkout(); // Act var actual = target.Total; // Assert Assert.AreEqual(expected, actual); }