diff --git a/DomainModel.md b/DomainModel.md new file mode 100644 index 00000000..050ff992 --- /dev/null +++ b/DomainModel.md @@ -0,0 +1,91 @@ + +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. + + + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Basket ` | `AddItem(Item item) ` | Add item to basket, if not full |(bool) True if added, otherwise false | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Basket ` | `RemoveItem(Item item) ` | Remove item from basket, if exists |(bool) True if removed, otherwise false | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Basket ` | `ChangeCapacity(Person person, int cap) ` | If manager, change capacity |(bool) Returns true if changed, false if not | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Basket ` | `GetPrice() ` | returns price of basket |(double) Cost of basket | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Basket ` | `GetDiscountPrice() ` | returns price of discount |(double) Cost of discount | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Bagel ` | `AddFilling(string namefilling) ` | add filling to bagel |(string) returns string indicating if it was added| +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Bagel ` | `RemoveFilling(string nameFilling) ` | Removes filling from bagel |(bool) True if removed, otherwise false | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Bagel ` | `GetPrice() ` | Gets price with fillings |(double) returns price of bagel | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Receipt ` | `GetReceipt(Basket basket) ` | Gets receipt of basket |(string) returns receipt | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Receipt ` | `PrintReceipt() ` | Prints receipt |(void) prints receipt | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `SMSService ` | `SendSMS(string message) ` | Sends receipt of order |(void) Sends receipt by SMS | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| +| `Inventory ` | `GetInventory() ` | Method for checking avaliable stock|(List) returns list with stock of items | +| | | | | +|-----------------|---------------------------------------------|------------------------------------|--------------------------------------------------| diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs new file mode 100644 index 00000000..66017562 --- /dev/null +++ b/exercise.main/Bagel.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Bagel : Item + { + + private int _id; + public int Id + { + get { return _id; } + set { _id = value; } + } + private string _sku; + public string Sku + { + get { return _sku; } + set { _sku = value; } + } + private string _name; + public string Name + { + get => _name; set => _name = value; + } + private double _price; + public double Price + { + get => _price; set => _price = value; + } + private string _variant; + public string Variant + { + get => _variant; set => _variant = value; + } + + private List _fillings; + public List Fillings + { + get => _fillings; set => _fillings = value; + } + + public Bagel(string sku, double price, string variant, string name) + { + this._sku = sku; + this._name = name; + this._price = price; + this._variant = variant; + this._fillings = new List(); + } + + + public List GetFillings() + { + return this._fillings; + } + public string AddFilling(string nameFilling) + { + List inventory = Inventory.GetInventory(); + + foreach (var item in inventory) + { + if (item.Name.Equals(nameFilling)) + { + Filling filling = (Filling)item; + _fillings.Add(filling); + return "Filling added"; + } + } + return "Filling not in inventory"; + } + + public bool RemoveFilling(string filling1) + { + foreach (var item in _fillings) + { + if (item.Name.Equals(filling1)) + { + _fillings.Remove(item); + return true; + } + } + return false; + } + + public double GetPrice() + { + double price = this._price; + + foreach (var item in _fillings) + { + price += item.Price; + } + return price; + } + } +} diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..f36adf75 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + private int _id; + private int _capacity; + public int Capacity { get { return _capacity; }set { _capacity = value; } } + + private List _items; + + public List Items + { + get { return _items; } + + } + + + public Basket(int capacity) { + this._items = new List(); + this._capacity = capacity; + } + + public bool AddItem(Item item) + { + + if (_items.Count >= _capacity){ + return false; + } + _items.Add(item); + return true; + } + + public bool RemoveItem(Item item) + { + + if (_items.Contains(item)) + { + _items.Remove(item); + return true; + } + return false; + } + + public double GetPrice() + { + double price = 0; + + foreach(var product in _items) + { + price += product.Price; + + } + price = Math.Round(price, 2); + + + return price; + } + + public double GetDiscountPrice() + { + + List bagels = this._items.Where(x => x.GetType() == typeof(Bagel)).ToList(); + List coffee = this._items.Where(x => x.GetType() == typeof(Coffee)).ToList(); + List filling = this._items.Where(x => x.GetType() == typeof(Filling)).ToList(); + List bagelFilling = new List(); + + + foreach (var item in bagels) + { + Bagel bagel = (Bagel)item; + + bagelFilling.AddRange(bagel.GetFillings()); + } + //Getting discount on bagels + double price = 0; + int bagelsLeft = bagels.Count; + + price += (bagelsLeft / 12) * 3.99; + bagelsLeft = bagels.Count % 12; + price += (bagelsLeft / 6) * 2.49; + bagelsLeft = bagelsLeft % 6; + + price += bagelsLeft * 0.49; + + //Adding fillings to price + + foreach (var item in bagelFilling) + { + price += item.Price; + } + + //Adding price of coffee items + foreach (var item in coffee) + { + price += item.Price; + } + + //Adding price of fillings + foreach (var item in filling) + { + price += item.Price; + } + return Math.Round(price, 2); + + } + + public bool ChangeCapacity(Person person, int newCapacity) + { + if (person.Manager == true) + { + _capacity = newCapacity; + return true; + } + return false; + } + + + } +} diff --git a/exercise.main/BobsBagel.cs b/exercise.main/BobsBagel.cs new file mode 100644 index 00000000..1472478a --- /dev/null +++ b/exercise.main/BobsBagel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public static class BobsBagel + { + + public static string Name { get; set; } = "Bob's Bagels"; + + + } +} diff --git a/exercise.main/ClassDiagram1.cd b/exercise.main/ClassDiagram1.cd new file mode 100644 index 00000000..4bf62ba1 --- /dev/null +++ b/exercise.main/ClassDiagram1.cd @@ -0,0 +1,63 @@ + + + + + + AhACIAEAAQAIAAAAAABAAAQAAACAAAAAEAAAAAAAAAA= + Filling.cs + + + + + + + AAAAIAAAAICABCAAAAAAAIEAABAEAAAAAAAAAAAAAAA= + Receipt.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA= + SMSService.cs + + + + + + AhACIAAAAQAIAAAAAABAAAQAAACAAAAAEAAAAAAAAAA= + Coffee.cs + + + + + + + AhACIAFAAQAIAAAgEABAAAQABACAAAAAEAQAAAAAAAA= + Bagel.cs + + + + + + + AAAAAAgAAAAACAAAEABAAAQCgBAAAAAEAAAAAAAACAA= + Basket.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA= + BobsBagel.cs + + + + + + AAACAAAAAQAAAAAAAAAAAAQAAACAAAAAEAAAAAAAAAA= + Item.cs + + + + \ No newline at end of file diff --git a/exercise.main/Coffee.cs b/exercise.main/Coffee.cs new file mode 100644 index 00000000..2558dfc1 --- /dev/null +++ b/exercise.main/Coffee.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Coffee : Item + { + private int _id; + public int Id + { + get { return _id; } + set { _id = value; } + } + private string _sku; + public string Sku + { + get { return _sku; } + set { _sku = value; } + } + private string _name; + public string Name + { + get => _name; set => _name = value; + } + private double _price; + public double Price + { + get => _price; set => _price = value; + } + private string _variant; + public string Variant + { + get => _variant; set => _variant = value; + } + + public Coffee(string sku, double price, string name, string variant) + { + this._sku = sku; + this._name = name; + this._price = price; + this._variant = variant; + } + + public enum CoffeeVariant + { + Black, + White, + Capuccino, + Latte + } + + } +} diff --git a/exercise.main/Filling.cs b/exercise.main/Filling.cs new file mode 100644 index 00000000..cf7fb101 --- /dev/null +++ b/exercise.main/Filling.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Filling : Item + { + private int _id; + public int Id + { + get { return _id; } + set { _id = value; } + } + private string _sku; + public string Sku + { + get { return _sku; } + set { _sku = value; } + } + private string _name; + public string Name + { + get => _name; set => _name = value; + } + private double _price; + public double Price + { + get => _price; set => _price = value; + } + private string _variant; + public string Variant + { + get => _variant; set => _variant = value; + } + private List _fillings = new List(); + + + public Filling(string sku, double price, string variant, string name) + { + this._sku = sku; + this._name = name; + this._price = price; + this._variant = variant; + } + + } +} diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs new file mode 100644 index 00000000..ffb235ae --- /dev/null +++ b/exercise.main/Inventory.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public static class Inventory + { + private static List _items = new List(); + + public static List GetInventory() + { + + Bagel onion = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + Bagel plain = new Bagel("BGLP", 0.39, "Bagel", "Plain"); + Bagel everything = new Bagel("BGLE", 0.49, "Bagel", "Everything"); + Bagel sesame = new Bagel("BGLS", 0.49, "Bagel", "Sesame"); + + Coffee black = new Coffee("COFB", 0.99, "Coffee", "Black"); + Coffee white = new Coffee("COFW", 1.19, "Coffee", "White"); + Coffee capuccino = new Coffee("COFC", 1.29, "Coffee", "Capuccino"); + Coffee latte = new Coffee("COFL", 1.29, "Coffee", "Latte"); + + Filling bacon = new Filling("FILB", 0.12, "Filling", "Bacon"); + Filling egg = new Filling("FILE", 0.12, "Filling", "Egg"); + Filling cheese = new Filling("FILC", 0.12, "Filling", "Cheese"); + Filling creamCheese = new Filling("FILX", 0.12, "Filling", "Cream Cheese"); + Filling smokedSalmon = new Filling("FILS", 0.12, "Filling", "Smoked Salmon"); + Filling ham = new Filling("FILH", 0.12, "Filling", "Ham"); + + _items.Add(onion); + _items.Add(plain); + _items.Add(everything); + _items.Add(sesame); + _items.Add(black); + _items.Add(white); + _items.Add(capuccino); + _items.Add(latte); + _items.Add(bacon); + _items.Add(egg); + _items.Add(cheese); + _items.Add(creamCheese); + _items.Add(smokedSalmon); + _items.Add(ham); + + return _items; + + + } + + + } +} diff --git a/exercise.main/Item.cs b/exercise.main/Item.cs new file mode 100644 index 00000000..7f07d033 --- /dev/null +++ b/exercise.main/Item.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public interface Item + { + int Id { get; } + string Sku { get; set; } + string Name { get; set; } + double Price { get; set; } + string Variant { get; set; } + + + + } +} diff --git a/exercise.main/Person.cs b/exercise.main/Person.cs new file mode 100644 index 00000000..3f5e4f76 --- /dev/null +++ b/exercise.main/Person.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Person + { + private int _id; + private bool _manager; + private List _basket = new List(); + + public bool Manager { + + get { return _manager; } set { _manager = value; } + + } + + + public Person(int id, bool manager) { + this._id = id; + this._manager = manager; + } + } +} diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..119ae256 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,37 @@ // See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using exercise.main; +using System.Threading.Tasks; +using System; + + +Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Bagel bagel2 = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Bagel bagel3 = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Bagel bagel4 = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Bagel bagel5 = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Bagel bagel6 = new Bagel("BGLO", 0.49, "Bagel", "Onion"); +Coffee coffee = new Coffee("COFB", 0.99, "Coffee", "Black"); +Filling filling = new Filling("FILB", 0.12, "Filling", "Bacon"); +Bagel bagel1 = new Bagel("BGLP", 0.39, "Bagel", "Plain"); +Basket basket = new Basket(20); +bagel.AddFilling("Bacon"); +bagel.AddFilling("Bacon"); +bagel.AddFilling("Bacon"); +bagel2.AddFilling("Bacon"); +bagel2.AddFilling("Bacon"); +bagel2.AddFilling("Bacon"); +basket.AddItem(bagel); +basket.AddItem(bagel2); +basket.AddItem(bagel3); +basket.AddItem(bagel4); +basket.AddItem(bagel5); +basket.AddItem(bagel6); +basket.AddItem(coffee); +basket.AddItem(filling); +basket.AddItem(bagel1); + +Receipt receipt = new Receipt(basket); +receipt.PrintReceipt(); + + + diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs new file mode 100644 index 00000000..69d3a875 --- /dev/null +++ b/exercise.main/Receipt.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Receipt + { + private DateTime _receiptDate; + private DateTime _deliveryTime; + private string _shopName; + private double _totalPrice; + private double _discountPrice; + private List _items; + private string _receipt; + + public Receipt(Basket basket) + { + _receiptDate = DateTime.Now; + _shopName = BobsBagel.Name; + _totalPrice = basket.GetPrice(); + _discountPrice = basket.GetDiscountPrice(); + _items = basket.Items; + _receipt = GetReceipt(basket); + } + + + + + public string GetReceipt(Basket basket) + { + StringBuilder sb = new StringBuilder(); + DateTime deliveryTime = DateTime.UtcNow.AddMinutes(150); + + + sb.AppendLine($" ~~~ Bob's Bagels ~~~\n"); + sb.AppendLine($" {_receiptDate:yyyy-MM-dd HH:mm:ss}\n"); + sb.AppendLine($"------------------------------\n"); + + + double priceFillings = 0; + + foreach (var item in basket.Items) + { + sb.AppendLine($"{item.Name.PadRight(5)} {item.Variant.PadRight(3)} {item.Price:F2}"); + if (item.GetType() == typeof(Bagel)) + { + Bagel bagel = (Bagel)item; + foreach (var item1 in bagel.Fillings) + { + sb.AppendLine(" - " + item1.Name + " " + item1.Price); + priceFillings += item1.Price; + } + + } + } + + + sb.AppendLine($"------------------------------\n"); + double priceBeforeDiscount = basket.GetPrice() + priceFillings; + priceBeforeDiscount = Math.Round(priceBeforeDiscount, 2); + double priceAfterDiscount = basket.GetDiscountPrice(); + double savings = priceBeforeDiscount - priceAfterDiscount; + sb.AppendLine($" You saved a total of {Math.Round(savings,2)}"); + sb.AppendLine($" Your total price is: {priceAfterDiscount}"); + + sb.AppendLine($" Thank you"); + sb.AppendLine($" for your order!\n"); + sb.AppendLine($"Estimated delivery time is: {deliveryTime}"); + + SMSService sms = new SMSService(); + sms.SendSMS(sb.ToString()); + return sb.ToString(); + + + } + + public void PrintReceipt() + { + Console.WriteLine(_receipt); + } + } +} diff --git a/exercise.main/SMSService.cs b/exercise.main/SMSService.cs new file mode 100644 index 00000000..489d813b --- /dev/null +++ b/exercise.main/SMSService.cs @@ -0,0 +1,38 @@ +using System; +using Twilio; +using Twilio.Rest.Api.V2010.Account; +using System.Threading.Tasks; + +namespace exercise.main + +{ + + public class SMSService + { + + + + + public SMSService() + { + + } + + public void SendSMS(string receiptMessage) + { + // Find your Account SID and Auth Token at twilio.com/console + // and set the environment variables. See http://twil.io/secure + string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); + string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); + + TwilioClient.Init(accountSid, authToken); + + var message = MessageResource.Create( + body: receiptMessage, + from: new Twilio.Types.PhoneNumber("+14159916511"), + to: new Twilio.Types.PhoneNumber("+4790146419")); + + Console.WriteLine(message.Body); + } + } +} diff --git a/exercise.main/exercise.main.csproj b/exercise.main/exercise.main.csproj index 2150e379..fdd1a66a 100644 --- a/exercise.main/exercise.main.csproj +++ b/exercise.main/exercise.main.csproj @@ -7,4 +7,8 @@ enable + + + + diff --git a/exercise.sln b/exercise.sln index 0efb5453..89c7b23e 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 + DomainModel.md = DomainModel.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 = {B5598B72-5251-437D-9694-1727B45F38F6} + EndGlobalSection EndGlobal diff --git a/exercise.tests/BagelTest.cs b/exercise.tests/BagelTest.cs new file mode 100644 index 00000000..cffc4b9b --- /dev/null +++ b/exercise.tests/BagelTest.cs @@ -0,0 +1,56 @@ +namespace exercise.tests; +using exercise.main; + +[TestFixture] +public class BagelTest +{ + + + [Test] + public void AddFillingTest() + { + + Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + + string filling1 = "Bacon"; + string filling2 = "Egg"; + string filling3 = "Tuna"; + + string added1 = bagel.AddFilling(filling1); + string added2 = bagel.AddFilling(filling2); + string added3 = bagel.AddFilling(filling3); + + + Assert.That(added1, Is.EqualTo("Filling added")); + Assert.That(added2, Is.EqualTo("Filling added")); + Assert.That(added3, Is.EqualTo("Filling not in inventory")); + } + + [Test] + public void RemoveFillingTest() + { + Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + + string filling1 = "Bacon"; + string filling2 = "Egg"; + string filling3 = "Cheese"; + string filling4 = "Tuna"; + + string added1 = bagel.AddFilling(filling1); + string added2 = bagel.AddFilling(filling2); + string added3 = bagel.AddFilling(filling3); + + bool removed1 = bagel.RemoveFilling(filling1); + bool removed2 = bagel.RemoveFilling(filling2); + bool removed3 = bagel.RemoveFilling(filling3); + bool removed4 = bagel.RemoveFilling(filling4); + + Assert.That(removed1, Is.True); + Assert.That(removed2, Is.True); + Assert.That(removed3, Is.True); + Assert.That(removed4, Is.False); + + + } + +} \ No newline at end of file diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs new file mode 100644 index 00000000..6de54153 --- /dev/null +++ b/exercise.tests/BasketTest.cs @@ -0,0 +1,129 @@ +namespace exercise.tests; +using exercise.main; + +[TestFixture] +public class BasketTest +{ + [Test] + public void AddItemTest() + { + + Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + Coffee coffee = new Coffee("COFB", 0.99, "Coffee", "Black"); + Filling filling = new Filling("FILB", 0.12, "Filling", "Bacon"); + Bagel bagel1 = new Bagel("BGLP", 0.39, "Bagel", "Plain"); + Basket basket = new Basket(3); + + bool added1 = basket.AddItem(bagel); + bool added2 = basket.AddItem(coffee); + bool added3 = basket.AddItem(filling); + bool added4 = basket.AddItem(bagel1); + + Assert.That(added1, Is.True); + Assert.That(added2, Is.True); + Assert.That(added3, Is.True); + Assert.That(added4, Is.False); + } + + [Test] + public void RemoveItemTest() + { + + Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + Coffee coffee = new Coffee("COFB", 0.99, "Coffee", "Black"); + Filling filling = new Filling("FILB", 0.12, "Filling", "Bacon"); + Bagel bagel1 = new Bagel("BGLP", 0.39, "Bagel", "Plain"); + Basket basket = new Basket(4); + + basket.AddItem(bagel); + basket.AddItem(coffee); + basket.AddItem(filling); + + bool removed1 = basket.RemoveItem(bagel); + bool removed2 = basket.RemoveItem(coffee); + bool removed3 = basket.RemoveItem(filling); + bool removed4 = basket.RemoveItem(bagel1); + + Assert.That(removed1, Is.True); + Assert.That(removed2, Is.True); + Assert.That(removed3, Is.True); + Assert.That(removed4, Is.False); + } + + [Test] + public void GetPriceTest() + { + Bagel bagel = new Bagel("BGLO", 0.49, "Bagel", "Onion"); + Coffee coffee = new Coffee("COFB", 0.99, "Coffee", "Black"); + Filling filling = new Filling("FILB", 0.12, "Filling", "Bacon"); + Bagel bagel1 = new Bagel("BGLP", 0.39, "Bagel", "Plain"); + Basket basket = new Basket(4); + basket.AddItem(bagel); + basket.AddItem(coffee); + basket.AddItem(filling); + basket.AddItem(bagel1); + + double price1 = basket.GetPrice(); + + double actual1 = 0.49 + 0.99 + 0.12 + 0.39; + actual1 = Math.Round(actual1, 2); + + + Assert.That(price1, Is.EqualTo(actual1)); + + + } + + [Test] + public void ChangeCapacityTest() + { + Person manager = new Person(1, true); + Person customer = new Person(1, false); + + Basket basket = new Basket(4); + + bool changed1 = basket.ChangeCapacity(manager, 5); + bool changed2 = basket.ChangeCapacity(customer, 5); + + Assert.That(changed1 == true); + Assert.That(changed2 == false); + } + + [TestCase (6, 0, 0, 2.49)] //6 Bagels, 0 Coffees, 0Fillings + [TestCase (6, 0, 1, 2.61)] //6 Bagels, 0 Coffees, 1Fillings + [TestCase (12, 0, 0, 3.99)] //12 Bagels, 0 Coffees, 0Fillings + [TestCase (11, 1, 0, 5.93)] //11 Bagels, 1 Coffees, 0Fillings + [TestCase (22, 0, 0, 8.44)] //22 Bagels, 0 Coffees, 0Fillings + public void AddDiscountTest(int numberOfBagels, int numberOfCoffee, int numberOfFilling, double expected) + { + + + Bagel bagel1 = new Bagel("BGLE", 0.49, "Bagel", "Everything"); + Coffee coffee = new Coffee("COFB", 0.99, "Coffee", "Black"); + Filling filling = new Filling("FILB", 0.12, "Filling", "Bacon"); + Basket basket = new Basket(30); + Bagel bagel; + + for (int i = 0; i < numberOfBagels; i++) + { + bagel = new Bagel("BGLE", 0.49, "Bagel", "Everything"); + basket.AddItem(bagel); + } + + for (int i = 0; i < numberOfCoffee; i++) + { + basket.AddItem(coffee); + } + + for (int i = 0; i < numberOfFilling; i++) + { + basket.AddItem(filling); + } + + double actualPrice = basket.GetDiscountPrice(); + + + + Assert.That(actualPrice, Is.EqualTo(expected)); + } +} \ 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..93317f6f 100644 --- a/exercise.tests/exercise.tests.csproj +++ b/exercise.tests/exercise.tests.csproj @@ -17,4 +17,8 @@ + + + +