diff --git a/DomainModelCore.md b/DomainModelCore.md new file mode 100644 index 00000000..5d7d7adf --- /dev/null +++ b/DomainModelCore.md @@ -0,0 +1,124 @@ + ## USER-STORIES +1. +As a member of the public, +So I can order a bagel before work, +I'd like to add a specific type of bagel to my basket. + +2. +As a member of the public, +So I can change my order, +I'd like to remove a bagel from my basket. + +3. +As a member of the public, +So that I can not overfill my small bagel basket +I'd like to know when my basket is full when I try adding an item beyond my basket capacity. + +4. +As a Bob's Bagels manager, +So that I can expand my business, +I’d like to change the capacity of baskets. + +5. +As a member of the public +So that I can maintain my sanity +I'd like to know if I try to remove an item that doesn't exist in my basket. + +6. +As a customer, +So I know how much money I need, +I'd like to know the total cost of items in my basket. + +7. +As a customer, +So I know what the damage will be, +I'd like to know the cost of a bagel before I add it to my basket. + +8. +As a customer, +So I can shake things up a bit, +I'd like to be able to choose fillings for my bagel. + +9. +As a customer, +So I don't over-spend, +I'd like to know the cost of each filling before I add it to my bagel order. + +10. +As the manager, +So we don't get any weird requests, +I want customers to only be able to order things that we stock in our inventory. + + +----------------------------------------------------- +## EXTENSIONS + +1. +As a customer, +So I can choose special offers, +I want customers to be able to see special offers and get discount on the receipt + +2. +As a customer, +So I can see what i bought, +I want customers to get a receipt of what items they bought + +3. +As a customer, +So i can see the correct price, +I want customers to see the discount if there is one on the items they bought + +4. Textmessage +Part 1: +- Users should receive a text message with their order summary, + and delivery time when they complete their order. + + + +| Classes | Methods | Scenario | Outputs | +|-----------------|----------------------------------------------------|----------------------------------------------------|------------| +| `Item` | `Public Item(string id, double price, ` | Item can be either Bagel, Coffe or Filling | Double | +| | `string name, string variant)` | | | +| | | | | +| `Person` | `Public Person(string name, Role role)` | Person can be a Manager or Customer | Person | +| | `Public Enum Role {CUSTOMER, MANAGER}` | | | +| | | | | +| `Inventory` | `Public List Inventory` | List of all of the Items in Bobs inventory | List | +| | | | | +| | | | | +| `Basket` | `Inventory inventory` | Property for Bobs inventory | List | +| | `List basket = new List()` | Basket-list for all the Items | List | +| | | | | +| | `AddItem(Item item)` | User order bagel/filling/coffee to basket-list | bool | +| | | If Bagel/Coffe/filling not in inventory (message) | bool | +| | | If basket is full (message) | bool | +| | | | | +| | `RemoveBagelOrItem(Item item)` | User can remove bagel from basket | bool | +| | | No bagel found to remove (message) | bool | +| | | | | +| | `public int MaxBasketSize { get; set; } = int` | Property for holding and setting full basket value | int | +| | | | | +| | | | | +| | | | | +| | `ChangeBasketCapacity(int capacity, Role role)` | If Role is Manager the basket capacity can | int | +| | | be changed | | +| | | | | +| | `TotalCost()` | Sum of all the items in the basket | Double | +| | | | | +| | `GetPriceOfItem(Item item)` | User can see the price of a specific item | Double | +| | | | | +|-----------------|----------------------------------------------------|----------------------------------------------------|------------| +| | | | | +| `Basket` | `Discount()` | If special offer decided by count of items it | double | +| | | gives a discount | | +| | | | | +| | `Receipt()` | Displays all the items a customer has bought | void | +| | | | | +| | `ReceiptWithDiscount()` | Displays the items bought with discount | void | +| | | (if discount) | | +| | | | | +| | | | | +| | | | | +|-----------------|----------------------------------------------------|----------------------------------------------------|------------| + + diff --git a/DomainModelExtensions.md b/DomainModelExtensions.md new file mode 100644 index 00000000..e69de29b diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..69f70cd6 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,246 @@ +using System; + +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + Inventory inventory = new Inventory(); + //Person person = new Person("Bob", Role.MANAGER); + private int MAX_BASKET_SIZE { get; set; } = 5; + + public List basketItems = new List(); + + public Dictionary countOfItems = new Dictionary(); + + //Help method for not having to write the long condition check in the if statement in addItem :) + public bool Equals(Item one, Item two) + { + if (one.id == two.id && one.price == two.price && one.name == two.name && one.variant == two.variant) + { + return true; + } + return false; + } + + public bool addItem(Item? plainBagel) + { + // initiate max size of basket + if (plainBagel == null) + { + Console.WriteLine("Wrong input!"); + return false; + } + + if (basketItems.Count < MAX_BASKET_SIZE && inventory.getInventory().Any(item => Equals(item, plainBagel))) { + basketItems.Add(plainBagel); + return true; + } + + Console.WriteLine("Basket is full or not in our inventory!"); + return false; + + } + + public bool removeBagelOrItem(Item item) + { + if (!basketItems.Any(x => Equals(x, item))) + { + Console.WriteLine($"{item.name} {item.variant} not in basket!"); + return false; + } + + basketItems.Remove(item); + + Console.WriteLine("Removed: " + item.variant); + return true; + } + + public int changeBasketCapacity(int newCapacity, Role role) + { + + if (role != Role.MANAGER) + { + Console.WriteLine("Only the manager can change capacity!"); + return -1; + } + + MAX_BASKET_SIZE = newCapacity; + + basketItems.Capacity = MAX_BASKET_SIZE; + + Console.WriteLine(basketItems.Capacity); + return basketItems.Capacity; + } + + public double totalCost() + { + return Math.Round(basketItems.Sum(item => item.price), 2); + } + + public double getPriceOfItem(Item item) + { + if (!inventory.getInventory().Any(x => Equals(x, item))) + { + Console.WriteLine($"{item.name} {item.variant} not in Bobs inventory"); + return -1; + } + + return item.price; + } + + public void Receipt() + { + + List itemsCounted = new List(); + + string receipt = "~~~ Bob's Bagels ~~~" + "\n\n" + + DateTime.Now.ToString() + "\n\n" + + "------------------------" + "\n\n"; + + + basketItems.ForEach(item => { + + if (!itemsCounted.Contains(item.id)) + { + int itemCount = 0; + foreach (var copy in basketItems) + { + if (copy.id == item.id) + { + itemCount++; + } + } + receipt += $"{item.name} {item.variant} {itemCount} £{item.price * itemCount} \n\n"; + itemsCounted.Add(item.id); + } + }); + + receipt += $"------------------------ \n\nTotal £{totalCost()} \n\nThank you for your order!"; + + Console.WriteLine(receipt); + } + + public double discount() + { + + List itemsCounted = new List(); + + basketItems.ForEach((item) => + { + + if (!itemsCounted.Contains(item.id)) + { + int itemCount = 0; + foreach (var copy in basketItems) + { + if (copy.id == item.id) + { + itemCount++; + } + } + + countOfItems.Add(item, itemCount); + itemsCounted.Add(item.id); + } + }); + + double bagAndCof = 1.25; + double sixBagels = 2.49; + double twelBagels = 3.99; + + List cof = inventory.getInventory().Where(item => item.id.Contains("COF")).ToList(); + List bgl = inventory.getInventory().Where(item => item.id.Contains("BGL")).ToList(); + + if (basketItems.Count == 2 && (cof.Any(i => i.id.Contains(countOfItems.First().Key.id) || i.id.Contains(countOfItems.Last().Key.id)) + && (bgl.Any(i => i.id.Contains(countOfItems.First().Key.id) || i.id.Contains(countOfItems.Last().Key.id))))) + { + return bagAndCof; + } + + if (countOfItems.Count > 0) + { + + foreach (var item in countOfItems) + { + if (item.Key.id.Contains("BGL") && item.Value == 6) + { + return sixBagels; + } + else if (item.Key.id.Contains("BGL") && item.Value == 12) + { + return twelBagels; + } + else + { + return 0; + } + } + } + + return 0; + } + + public void ReceiptWithDiscount() + { + + double bagAndCof = 1.25; + double sixBagels = 2.49; + double twelBagels = 3.99; + + double discountVal = discount(); + double totalBagelPrice = 0; + + string receipt = "~~~ Bob's Bagels ~~~" + "\n\n" + + DateTime.Now.ToString() + "\n\n" + + "------------------------" + "\n\n"; + + if (discountVal == bagAndCof) + { + foreach (var item in countOfItems) + { + receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{item.Key.price * item.Value} \n\n"; + } + + receipt += $"Discount (£{bagAndCof}) \n" + + $"------------------------ \n\nTotal £{bagAndCof} \n\n You saved a total of \n £{Math.Round(totalCost() - bagAndCof, 2)} on this shop " + + $"\n\nThank you for your order! \n "; + + Console.WriteLine(receipt); + } + else if (discountVal == sixBagels || discountVal == twelBagels) + { + //Plain Bagel is less than the discount for 6.. need to make a check in the BGL list in discount + foreach (var item in countOfItems) + { + if (item.Value == 6 || item.Value == 12) + { + totalBagelPrice = (item.Key.price * item.Value); + receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{totalBagelPrice} \n\n"; + } + else + { + receipt += $"{item.Key.name} {item.Key.variant} {item.Value} £{item.Key.price * item.Value} \n\n"; + } + } + Console.WriteLine(" TOTALT: " + totalBagelPrice); + double dis = Math.Round(totalBagelPrice - discountVal, 2); + + receipt += $"Discount (-£{dis}) \n" + + $"------------------------ \n\nTotal £{totalCost()-dis} \n\n You saved a total of \n £{dis} on this shop " + + $"\n\nThank you for your order! \n "; + + Console.WriteLine(receipt); + + } + else + { + Receipt(); + } + } + } +} diff --git a/exercise.main/Basket2.cs b/exercise.main/Basket2.cs new file mode 100644 index 00000000..61a46eb8 --- /dev/null +++ b/exercise.main/Basket2.cs @@ -0,0 +1,157 @@ +using exercise.main.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket2 + { + Inventory2 inventory2 = new Inventory2(); + //Person person = new Person("Bob", Role.MANAGER); + private int MAX_BASKET_SIZE { get; set; } = 5; + + public List _basketItems = new List(); + + public Dictionary itemsWithCount = new Dictionary(); + + + //Help method for not having to write the long condition check in the if statement in addItem :) + public bool itemsIsEqual(IItem one, IItem two) + { + if (one.id == two.id && one.price == two.price && one.name == two.name && one.variant == two.variant) + { + return true; + } + return false; + } + public bool addItem(IItem item) + { + if (item == null) + { + Console.WriteLine("Wrong input!"); + return false; + } + + if (_basketItems.Count < MAX_BASKET_SIZE && inventory2.getInventory2().Any(i => itemsIsEqual(i, item))) + { + _basketItems.Add(item); + return true; + } + + Console.WriteLine("Basket is full or not in our inventory!"); + return false; + } + + public bool removeItem(IItem item) + { + if (!_basketItems.Any(x => itemsIsEqual(x, item))) + { + Console.WriteLine($"{item.name} {item.variant} not in basket!"); + return false; + } + + _basketItems.Remove(item); + + Console.WriteLine($"Removed: {item.name} {item.variant}"); + return true; + } + + public int changeBasketCapacity(int newCapacity, Role role) + { + + if (role != Role.MANAGER) + { + Console.WriteLine("Only the manager can change capacity!"); + return -1; + } + + MAX_BASKET_SIZE = newCapacity; + + return MAX_BASKET_SIZE; + } + + public double totalCost() + { + return Math.Round(_basketItems.Sum(item => item.price), 2); + } + + public double getPriceOfItem(IItem item) + { + if (!inventory2.getInventory2().Any(x => itemsIsEqual(x, item))) + { + Console.WriteLine($"{item.name} {item.variant} not in Bobs inventory"); + return -1; + } + + return item.price; + } + + public void Receipt() + { + + + string receipt = "~~~ Bob's Bagels ~~~" + "\n\n" + + DateTime.Now.ToString() + "\n\n" + + "------------------------" + "\n\n"; + + List itemsCounted = new List(); + + _basketItems.ForEach(item => { + + if (!itemsCounted.Contains(item.id)) + { + int itemCount = 0; + foreach (var copy in _basketItems) + { + if (copy.id == item.id) + { + itemCount++; + } + } + receipt += $"{item.name} {item.variant} {itemCount} £{item.price * itemCount} \n\n"; + itemsCounted.Add(item.id); + } + }); + + receipt += $"------------------------ \n\nTotal £{totalCost()} \n\nThank you for your order!"; + + Console.WriteLine(receipt); + } + + /* + public double Discount() + { + List itemsCounted = new List(); + + _basketItems.ForEach((item) => + { + if (!itemsCounted.Contains(item.id)) + { + int itemCount = 0; + foreach (var copy in _basketItems) + { + if (copy.id == item.id) + { + itemCount++; + } + } + itemsWithCount.Add(item, itemCount); + itemsCounted.Add(item.id); + } + }); + + double bagAndCof = 1.25; + double sixBagels = 2.49; + double twelBagels = 3.99; + + if () { + + if (_basketItems.Count == 2 && itemsCounted is IDiscountable) { + + } + */ + } +} diff --git a/exercise.main/ClassDiagram.cd b/exercise.main/ClassDiagram.cd new file mode 100644 index 00000000..4c4de87d --- /dev/null +++ b/exercise.main/ClassDiagram.cd @@ -0,0 +1,39 @@ + + + + + + AAAAAAAAAgAAAAAAgACAAQIAAAAIAAAGASAAAAAAAAA= + Basket.cs + + + + + + AAAAACAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAA= + Inventory.cs + + + + + + AAABAAAAAAAAAAAAAAAAAIAAAAAEAAAAAAAAAAAAAgA= + Item.cs + + + + + + AAAAAAAAAAAAAAAAAAAAABAAAAAEAAAAAAAAAAAAAAA= + Person.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAAAQAAAAQAAAAAAAAAAAAA= + Person.cs + + + + \ No newline at end of file diff --git a/exercise.main/Interfaces/IDiscountable.cs b/exercise.main/Interfaces/IDiscountable.cs new file mode 100644 index 00000000..18ca06d1 --- /dev/null +++ b/exercise.main/Interfaces/IDiscountable.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Interfaces +{ + public interface IDiscountable + { + int discount { get; set; } + } +} diff --git a/exercise.main/Interfaces/IItem.cs b/exercise.main/Interfaces/IItem.cs new file mode 100644 index 00000000..eff3e7e5 --- /dev/null +++ b/exercise.main/Interfaces/IItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Interfaces +{ + public interface IItem + { + string id { get; set; } + double price { get; set; } + string name { get; set; } + string variant { get; set; } + } +} diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs new file mode 100644 index 00000000..4cbee7f6 --- /dev/null +++ b/exercise.main/Inventory.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Inventory + { + public List _inventory = new List(); + + public List getInventory() + { + _inventory.Add(new Item("BGLO", 0.49, "Bagel", "Onion")); + _inventory.Add(new Item("BGLP", 0.39, "Bagel", "Plain")); + _inventory.Add(new Item("BGLE", 0.49, "Bagel", "Everything")); + _inventory.Add(new Item("BGLS", 0.49, "Bagel", "Sesame")); + _inventory.Add(new Item("COFB", 0.99, "Coffee", "Black")); + _inventory.Add(new Item("COFW", 1.19, "Coffee", "White")); + _inventory.Add(new Item("COFC", 1.29, "Coffee", "Capuccino")); + _inventory.Add(new Item("COFL", 1.29, "Coffee", "Latte")); + _inventory.Add(new Item("FILB", 0.12, "Filling", "Bacon")); + _inventory.Add(new Item("FILE", 0.12, "Filling", "Egg")); + _inventory.Add(new Item("FILC", 0.12, "Filling", "Cheese")); + _inventory.Add(new Item("FILX", 0.12, "Filling", "Cream Cheese")); + _inventory.Add(new Item("FILS", 0.12, "Filling", "Smoked Salmon")); + _inventory.Add(new Item("FILH", 0.12, "Filling", "Ham")); + + return _inventory; + } + } +} diff --git a/exercise.main/Inventory2.cs b/exercise.main/Inventory2.cs new file mode 100644 index 00000000..701c3b7b --- /dev/null +++ b/exercise.main/Inventory2.cs @@ -0,0 +1,35 @@ +using exercise.main.Interfaces; +using exercise.main.Items; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Inventory2 + { + public List _inventory = new List(); + + public List getInventory2() + { + _inventory.Add(new Bagel("BGLO", 0.49, "Bagel", "Onion")); + _inventory.Add(new Bagel("BGLP", 0.39, "Bagel", "Plain")); + _inventory.Add(new Bagel("BGLE", 0.49, "Bagel", "Everything")); + _inventory.Add(new Bagel("BGLS", 0.49, "Bagel", "Sesame")); + _inventory.Add(new Coffee("COFB", 0.99, "Coffee", "Black")); + _inventory.Add(new Coffee("COFW", 1.19, "Coffee", "White")); + _inventory.Add(new Coffee("COFC", 1.29, "Coffee", "Capuccino")); + _inventory.Add(new Coffee("COFL", 1.29, "Coffee", "Latte")); + _inventory.Add(new Filling("FILB", 0.12, "Filling", "Bacon")); + _inventory.Add(new Filling("FILE", 0.12, "Filling", "Egg")); + _inventory.Add(new Filling("FILC", 0.12, "Filling", "Cheese")); + _inventory.Add(new Filling("FILX", 0.12, "Filling", "Cream Cheese")); + _inventory.Add(new Filling("FILS", 0.12, "Filling", "Smoked Salmon")); + _inventory.Add(new Filling("FILH", 0.12, "Filling", "Ham")); + + return _inventory; + } +} +} diff --git a/exercise.main/Item.cs b/exercise.main/Item.cs new file mode 100644 index 00000000..40fd5b56 --- /dev/null +++ b/exercise.main/Item.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Item + { + public string id { get; set; } + public double price { get; set; } + public string name { get; set; } + public string variant { get; set; } + + public Item() { } + + public Item(string id, double price, string name, string variant) + { + this.id = id; + this.price = price; + this.name = name; + this.variant = variant; + } + } +} diff --git a/exercise.main/Items/Bagel.cs b/exercise.main/Items/Bagel.cs new file mode 100644 index 00000000..f3da99e7 --- /dev/null +++ b/exercise.main/Items/Bagel.cs @@ -0,0 +1,30 @@ +using exercise.main.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Items +{ + public class Bagel : IItem, IDiscountable + { + public string id { get; set; } + public double price { get; set; } + public string name { get; set; } + public string variant { get; set; } + + public ICollection fillings { get; set; } + public int discount { get; set; } + + public Bagel() { } + + public Bagel(string id, double price, string name, string variant) + { + this.id = id; + this.price = price; + this.name = name; + this.variant = variant; + } + } +} diff --git a/exercise.main/Items/Coffee.cs b/exercise.main/Items/Coffee.cs new file mode 100644 index 00000000..73f3a046 --- /dev/null +++ b/exercise.main/Items/Coffee.cs @@ -0,0 +1,28 @@ +using exercise.main.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Items +{ + public class Coffee : IItem, IDiscountable + { + public string id { get; set; } + public double price { get; set; } + public string name { get; set; } + public string variant { get; set; } + public int discount { get; set; } + + public Coffee() { } + + public Coffee(string id, double price, string name, string variant) + { + this.id = id; + this.price = price; + this.name = name; + this.variant = variant; + } + } +} diff --git a/exercise.main/Items/Filling.cs b/exercise.main/Items/Filling.cs new file mode 100644 index 00000000..51bd5556 --- /dev/null +++ b/exercise.main/Items/Filling.cs @@ -0,0 +1,27 @@ +using exercise.main.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Items +{ + public class Filling : IItem + { + public string id { get; set; } + public double price { get; set; } + public string name { get; set; } + public string variant { get; set; } + + public Filling() { } + + public Filling(string id, double price, string name, string variant) + { + this.id = id; + this.price = price; + this.name = name; + this.variant = variant; + } + } +} diff --git a/exercise.main/Person.cs b/exercise.main/Person.cs new file mode 100644 index 00000000..28f8d1a7 --- /dev/null +++ b/exercise.main/Person.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + + public enum Role { MANAGER, CUSTOMER } + public class Person + { + public string name { get; set; } + public Role role { get; set; } + + public Person() { } + public Person(string name, Role role) + { + this.name = name; + this.role = role; + } + + } +} diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..bc87f64a 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,82 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); + +using exercise.main; +using exercise.main.Interfaces; +using exercise.main.Items; + +// Originial BASKET (before refacotirng with interfaces and polymorphism) +/* +Inventory inventory = new Inventory(); + +inventory.getInventory().ForEach(x => Console.WriteLine(x.id + " " + x.price + " " + x.name + " " + x.variant)); +Console.WriteLine("-------------------------------- \n"); +Person person = new Person("Bob", Role.MANAGER); + +Basket basket = new Basket(); + +Item wrongBagel = new Item("BGLW", 0.40, "Cake", "Wrong"); +Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); +Item blackCoffe = new Item("COFB", 0.99, "Coffee", "Black"); + + +basket.changeBasketCapacity(15, person.role); +// basket.addItem(plainBagel); +//basket.removeBagelOrItem(plainBagel); + +basket.addItem(plainBagel); +basket.addItem(blackCoffe); + +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); + +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); +basket.addItem(plainBagel); + +// Console.WriteLine(basket.discount()); + +Console.WriteLine( "TOTALT: " + basket.totalCost()); + +Console.WriteLine("\n"); +// basket.Receipt(); + +Console.WriteLine($"\n New receipt \n"); +basket.ReceiptWithDiscount(); +*/ + +// ---------- NEW REFACTORED BASKET ----------------- +Inventory2 inventory2 = new Inventory2(); + +inventory2.getInventory2().ForEach(x => Console.WriteLine(x.id + " " + x.price + " " + x.name + " " + x.variant)); +Console.WriteLine("-------------------------------- \n"); + +Person person = new Person("Bob", Role.MANAGER); + +Basket2 basket2 = new Basket2(); + +IItem bp = new Bagel() { id="BGLP", price=0.39, name="Bagel", variant="Plain" }; + +//Console.WriteLine(basket2.removeItem(bp)); + +Console.WriteLine(basket2.changeBasketCapacity(8, person.role)); + +Console.WriteLine(basket2.addItem(bp)); +Console.WriteLine(basket2.addItem(bp)); +Console.WriteLine(basket2.addItem(bp)); +Console.WriteLine(basket2.addItem(bp)); +Console.WriteLine(basket2.addItem(bp)); +Console.WriteLine(basket2.addItem(bp)); + +// Console.WriteLine(basket2.removeItem(bp)); +// Console.WriteLine(basket2.getPriceOfItem(bp)); + +// Console.WriteLine("TOTAL: " + basket2.totalCost()); + +Console.WriteLine("\n"); +basket2.Receipt(); diff --git a/exercise.sln b/exercise.sln index 0efb5453..8f640a3c 100644 --- a/exercise.sln +++ b/exercise.sln @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exercise.tests", "exercise. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{825CCFE7-4F2E-4770-8393-FEB732F66EE4}" ProjectSection(SolutionItems) = preProject + DomainModelCore.md = DomainModelCore.md extension1.md = extension1.md extension2.md = extension2.md extension3.md = extension3.md @@ -34,4 +35,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {559CE3C9-D418-4211-99CF-60C42CE6AACB} + EndGlobalSection EndGlobal diff --git a/exercise.tests/BagelCoreTests.cs b/exercise.tests/BagelCoreTests.cs new file mode 100644 index 00000000..92969a15 --- /dev/null +++ b/exercise.tests/BagelCoreTests.cs @@ -0,0 +1,162 @@ + +using exercise.main; +namespace exercise.tests; + + +public class Tests +{ + [SetUp] + public void Setup() + { + } + + [Test] + public void AddItemTest() + { + + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); + + Item wrongBagel = new Item("BGLW", 0.40, "Cake", "Wrong"); + + bool expectedTrue = true; + bool expectedFalse = false; + + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + // basket.addItem(plainBagel); + + bool resultTrue = basket.addItem(plainBagel); + bool resultWrong = basket.addItem(wrongBagel); + + Assert.That(expectedTrue == resultTrue); + // Assert.That(expectedFalse == resultWrong); + + } + + + [Test] + public void RemoveBagelOrItemTest() + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); + + Item wrongBagel = new Item("BGLW", 0.40, "Cake", "Wrong"); + + basket.addItem(plainBagel); + + bool expectedTrue = true; + bool expectedFalse = false; + + bool result = basket.removeBagelOrItem(plainBagel); + + Assert.That(expectedTrue == result); + } + + [Test] + public void ChangeBasketCapacityTest() + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Person bob = new Person("Bob", Role.MANAGER); + Person customer = new Person("Jimmy", Role.CUSTOMER); + + + int expectedCapacity = 7; + int result = basket.changeBasketCapacity(7, bob.role); + + Assert.That(expectedCapacity == result); + } + + [Test] + public void TotalCostTest() + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); + Item blackCoffe = new Item("COFB", 0.99, "Coffee", "Black"); + + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(blackCoffe); + + double expected = plainBagel.price + plainBagel.price + blackCoffe.price; + + double result = basket.totalCost(); + + Assert.That(expected == result); + } + + [Test] + public void GetPriceOfItemTest() + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); + Item blackCoffe = new Item("COFB", 0.99, "Coffee", "Black"); + + Item wrongBagel = new Item("BGLW", 0.40, "Cake", "Wrong"); + + double expected = plainBagel.price; + + double result = basket.getPriceOfItem(plainBagel); + + Assert.That(expected == result); + } + + [TestCase(1.25, 2.49, 3.99)] + public void DiscountTest(double d1, double d2, double d3) + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + + Item plainBagel = new Item("BGLP", 0.39, "Bagel", "Plain"); + Item blackCoffe = new Item("COFB", 0.99, "Coffee", "Black"); + + basket.changeBasketCapacity(14, Role.MANAGER); + + basket.addItem(plainBagel); + basket.addItem(blackCoffe); + + /* + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + + + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + basket.addItem(plainBagel); + */ + + double expectedCofBag = d1; + double expectedSixBagel = d2; + double expectedTwelBagel = d3; + + double result = basket.discount(); + + Assert.That(expectedCofBag == result); + + } +} \ No newline at end of file diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs deleted file mode 100644 index 7bdb8968..00000000 --- a/exercise.tests/UnitTest1.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace exercise.tests; - -public class Tests -{ - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } -} \ No newline at end of file diff --git a/exercise.tests/exercise.tests.csproj b/exercise.tests/exercise.tests.csproj index 0072a6d1..fb313e62 100644 --- a/exercise.tests/exercise.tests.csproj +++ b/exercise.tests/exercise.tests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -17,4 +17,8 @@ + + + +