diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..a20b4c94 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,95 @@ +# Domain models + +## Core requirements + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|------------------------------|--------------------------------------|---------| +| Basket.cs | AddProduct(IProduct product) | Add bagel to List MyBasket | bool | + + +2. As a member of the public, So I can change my order, I'd like to remove a bagel from my basket. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|---------------------------------|-------------------------------------------|---------| +| Basket.cs | RemoveProduct(IProduct product) | Remove bagel from List MyBasket | bool | + + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|----------------------------------|--------------------------------|---------| +| Basket.cs | private int _basketCapacity = 3; | Sets _basketCapacity to 3 | bool | +| Basket.cs | AddProduct(IProduct product) | If basket is full return false | bool | + + +4. As a Bob's Bagels manager, So that I can expand my business, I’d like to change the capacity of baskets. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|---------------------------------------|-------------------------------------|---------| +| Basket.cs | ChangeBasketCapacity(int newCapacity) | Sets _basketCapacity to newCapacity | bool | + + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|---------------------------------|-----------------------------------|---------| +| Basket.cs | RemoveProduct(IProduct product) | If product not found return false | bool | + + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|-------------------------------------------------------------------------|---------------------------------------------|---------| +| Basket.cs | public double TotalCost { get { return MyBasket.Sum(x => x.Price); } } | Sums the prices of the products in Mybasket | double | + + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|----------|--------------------------------|------------------------------------------------------|---------| +| Bagel.cs | public double Price => _price; | Gets the price of the bagel before added to MyBasket | double | + + +8. As a customer, So I can shake things up a bit, I'd like to be able to choose fillings for my bagel. + +| Classes | Methods/Properties | Scenario | Outputs | +|----------|------------------------------|-------------------------|---------| +| Bagel.cs | AddFilling(IProduct product) | Adds filling to MyBagel | bool | + + +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. + +| Classes | Methods/Properties | Scenario | Outputs | +|------------|--------------------------------|-------------------------------------------------------------------|---------| +| Filling.cs | public double Price => _price; | Gets the price of the filling before added to MyBasket or Mybagel | double | + + +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/Properties | Scenario | Outputs | +|-----------|------------------------------|----------------------------------|---------| +| Basket.cs | AddProduct(IProduct product) | If not in inventory return false | bool | + + + +## Extension 1: Discounts + +Our goods are priced individually. In addition, some items are multi-priced: buy n of them, and they'll cost you y pounds. +Every Bagel is available for the 6 for 2.49 and 12 for 3.99 offer, but fillings still cost the extra amount per bagel. +Update and extend your program to handle these orders at Bob's Bagels. + +| Classes | Methods/Properties | Scenario | Outputs | +|-----------|----------------------------------------------------------------------|-------------------------------------------------------------|---------| +| Basket.cs | private double GroupCost(KeyValuePair> group) | Calculate the cost for each variant with the bagel discount | double | + + + +## Extension 2: Receipts + +Update and extend your program to handle printing receipts. These receipts should print to the terminal. + +| Classes | Methods/Properties | Scenario | Outputs | +|-------------|--------------------|------------------------------------|---------| +| Receipts.cs | PrintReceipt() | Prints the recipts to the terminal | bool | \ No newline at end of file diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..c497afd3 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,151 @@ +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + private int _basketCapacity = 3; + + public List MyBasket { get; set; } = new List(); + + public Dictionary> MyGroupedBasket => MyBasket.GroupBy(p => p.SKU).OrderBy(g => g.Key).ToDictionary(g => g.Key, g => g.ToList()); + + public double TotalCost + { + get + { + double totalCost = 0; + + foreach (var group in MyGroupedBasket) + { + totalCost += GroupCost(group); + } + + return totalCost; + } + } + + private double GroupCost(KeyValuePair> group) + { + { + double groupCost = 0; + + int quantity = group.Value.Count(); + + if (quantity >= 6 && group.Value.First().Name == "Bagel") + { + int numOf12Deals = quantity / 12; + groupCost += (numOf12Deals * 3.99); + + quantity -= numOf12Deals * 12; + int numOf6Deals = quantity / 6; + groupCost += (numOf6Deals * 2.49); + + quantity -= numOf6Deals * 6; + } + + groupCost += (quantity * group.Value.First().Price); + + return groupCost; + } + } + + public bool AddProduct(IProduct product) + { + InventoryDictionary inventoryDictionary = new InventoryDictionary(); + + if ((inventoryDictionary.SKU_Info(product.SKU).Item1 == "")) + { + Console.WriteLine("Item not in inventory"); + return false; + } + + if (MyBasket.Count < _basketCapacity) + { + MyBasket.Add(product); + return true; + } + else + { + Console.WriteLine("Basket is full"); + return false; + } + } + + public bool RemoveProduct(IProduct product) + { + if (MyBasket.Contains(product)) + { + MyBasket.Remove(product); + return true; + } + else + { + Console.WriteLine("Product not found"); + return false; + } + } + + public void ChangeBasketCapacity(int newCapacity) + { + _basketCapacity = newCapacity; + } + + public bool PrintReceipt() + { + if (MyBasket.Count == 0) + { + Console.WriteLine("No items in the basket, could not print receipt"); + return false; + } + else + { + Console.WriteLine(" ~~~ Bob's Bagels ~~~ "); + Console.WriteLine(" "); + Console.WriteLine($" {DateTime.Now.Year:D4}-{DateTime.Now.Month:D2}-{DateTime.Now.Day:D2} {DateTime.Now.Hour:D2}:{DateTime.Now.Minute:D2}:{DateTime.Now.Second:D2} "); + Console.WriteLine(" "); + Console.WriteLine(" -------------------------------------- "); + Console.WriteLine(" "); + + foreach (var group in MyGroupedBasket) + { + var product = group.Value.First(); + var quantity = group.Value.Count(); + string col1 = $" {product.Variant} {product.Name}"; + string col2 = $"{quantity}"; + + var groupCost = GroupCost(group); + string col3 = $"£{(groupCost):0.00}"; + //string col3 = $"£{(product.Price * quantity):0.00}"; + + Console.WriteLine("{0,-27} {1,-5} {2,-15}", col1, col2, col3); + } + + Console.WriteLine(" "); + Console.WriteLine(" -------------------------------------- "); + + string totalCost = $"£{TotalCost:0.00}"; + if (TotalCost >= 10.0) + { + Console.WriteLine("{0,-31} {1,0} {2,-15}", " Total", "", totalCost); + } + else + { + Console.WriteLine("{0,-32} {1,0} {2,-15}", " Total", "", totalCost); + } + + Console.WriteLine(" "); + Console.WriteLine(" Thank you "); + Console.WriteLine(" for your order! "); + + return true; + } + } + } +} + \ No newline at end of file diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs new file mode 100644 index 00000000..8e9bd25c --- /dev/null +++ b/exercise.main/IProduct.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 interface IProduct + { + string SKU { get; } + string Name { get; } + string Variant { get; } + double Price { get; } + } +} diff --git a/exercise.main/InventoryDictionary.cs b/exercise.main/InventoryDictionary.cs new file mode 100644 index 00000000..a97fc4ff --- /dev/null +++ b/exercise.main/InventoryDictionary.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class InventoryDictionary + { + Dictionary inventoryDictionary; + public InventoryDictionary() + { + inventoryDictionary = new Dictionary(); + + double bagelPrice = 0.49; + inventoryDictionary.Add("BGLO", ("Onion", bagelPrice)); + inventoryDictionary.Add("BGLP", ("Plain", 0.39)); + inventoryDictionary.Add("BGLE", ("Everything", bagelPrice)); + inventoryDictionary.Add("BGLS", ("Sesame", bagelPrice)); + + double fillingPrice = 0.12; + inventoryDictionary.Add("FILB", ("Bacon", fillingPrice)); + inventoryDictionary.Add("FILE", ("Egg", fillingPrice)); + inventoryDictionary.Add("FILC", ("Cheese", fillingPrice)); + inventoryDictionary.Add("FILX", ("Cream Cheese", fillingPrice)); + inventoryDictionary.Add("FILS", ("Smoked Salmon", fillingPrice)); + inventoryDictionary.Add("FILH", ("Ham", fillingPrice)); + + double coffeePrice = 1.29; + inventoryDictionary.Add("COFB", ("Black", 0.99)); + inventoryDictionary.Add("COFW", ("White", 1.19)); + inventoryDictionary.Add("COFC", ("Capuccino", coffeePrice)); + inventoryDictionary.Add("COFL", ("Latte", coffeePrice)); + + /*foreach (KeyValuePair kvp in inventoryDictionary) + { + Console.WriteLine($"Key: {kvp.Key} Value: {kvp.Value}"); + }*/ + } + + public (string, double) SKU_Info(string SKU) + { + if (inventoryDictionary.ContainsKey(SKU)) + { + (string, double) info; + info = inventoryDictionary[SKU]; + return info; + } + + return ("", 0.00); + } + } +} diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs new file mode 100644 index 00000000..c636abb1 --- /dev/null +++ b/exercise.main/Products/Bagel.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Products +{ + public class Bagel : IProduct + { + private string _SKU; + private string _name; + private string _variant; + private double _price; + + + public Bagel(string SKU) + { + _SKU = SKU; + _name = "Bagel"; + + InventoryDictionary inventoryDictionary = new InventoryDictionary(); + (string, double) result = inventoryDictionary.SKU_Info(SKU); + + _variant = result.Item1; + _price = result.Item2; + } + + public List MyBagel { get; set; } = new List(); + + public string SKU => _SKU; + public string Name => _name; + public string Variant => _variant; + public double Price => _price + MyBagel.Sum(x => x.Price); + + public bool AddFilling(IProduct product) + { + InventoryDictionary inventoryDictionary = new InventoryDictionary(); + + if ((inventoryDictionary.SKU_Info(product.SKU).Item1 == "")) + { + Console.WriteLine("Item not in inventory"); + return false; + } + + MyBagel.Add(product); + return true; + } + } +} diff --git a/exercise.main/Products/Coffee.cs b/exercise.main/Products/Coffee.cs new file mode 100644 index 00000000..f01995d5 --- /dev/null +++ b/exercise.main/Products/Coffee.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Products +{ + public class Coffee : IProduct + { + private string _SKU; + private string _name; + private string _variant; + private double _price; + + public Coffee(string SKU) + { + _SKU = SKU; + _name = "Coffee"; + + InventoryDictionary inventoryDictionary = new InventoryDictionary(); + (string, double) result = inventoryDictionary.SKU_Info(SKU); + + _variant = result.Item1; + _price = result.Item2; + } + + public string SKU => _SKU; + public string Name => _name; + public string Variant => _variant; + public double Price => _price; + } +} diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs new file mode 100644 index 00000000..3c9ebf04 --- /dev/null +++ b/exercise.main/Products/Filling.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Products +{ + public class Filling : IProduct + { + + private string _SKU; + private string _name; + private string _variant; + private double _price; + + public Filling(string SKU) + { + _SKU = SKU; + _name = "Filling"; + + InventoryDictionary inventoryDictionary = new InventoryDictionary(); + (string, double) result = inventoryDictionary.SKU_Info(SKU); + + _variant = result.Item1; + _price = result.Item2; + } + + public string SKU => _SKU; + public string Name => _name; + public string Variant => _variant; + public double Price => _price; + } +} diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..65bff117 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,41 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using exercise.main; +using exercise.main.Products; +using System.Net.Http.Headers; + +Basket basket = new Basket(); + +Bagel onionbagel = new Bagel("BGLO"); +Bagel plainbagel = new Bagel("BGLP"); +Bagel everythingbagel = new Bagel("BGLE"); +Coffee blackcoffee = new Coffee("COFB"); + +basket.ChangeBasketCapacity(23); + +basket.AddProduct(onionbagel); +basket.AddProduct(onionbagel); + +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); +basket.AddProduct(plainbagel); + +basket.AddProduct(everythingbagel); +basket.AddProduct(everythingbagel); +basket.AddProduct(everythingbagel); +basket.AddProduct(everythingbagel); +basket.AddProduct(everythingbagel); +basket.AddProduct(everythingbagel); + +basket.AddProduct(blackcoffee); +basket.AddProduct(blackcoffee); +basket.AddProduct(blackcoffee); + +basket.PrintReceipt(); diff --git a/exercise.sln b/exercise.sln index 0efb5453..72cf5c42 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 + domain-model.md = domain-model.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 = {545A706E-EFE3-49A3-B048-5CA1477175EA} + EndGlobalSection EndGlobal diff --git a/exercise.tests/CoreTests.cs b/exercise.tests/CoreTests.cs new file mode 100644 index 00000000..e74688d2 --- /dev/null +++ b/exercise.tests/CoreTests.cs @@ -0,0 +1,203 @@ +using exercise.main; +using exercise.main.Products; +using NUnit.Framework.Interfaces; + +namespace exercise.tests; + +public class Tests +{ + // 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. + [Test] + public void AddBagelToBasket() + { + // arrange + Basket basket = new Basket(); + Bagel bagel = new Bagel("BGLO"); + + // act + basket.AddProduct(bagel); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 1); + Assert.That(basket.MyBasket[0].SKU, Is.EqualTo("BGLO")); + } + + // 2. As a member of the public, So I can change my order, I'd like to remove a bagel from my basket. + [Test] + public void RemoveBagelFromBasket() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + basket.AddProduct(bagel1); + basket.AddProduct(bagel2); + + // act + basket.RemoveProduct(bagel1); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 1); + Assert.That(basket.MyBasket[0].SKU, Is.EqualTo("BGLP")); + } + + // 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. + [Test] + public void IsBasketFull() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + Bagel bagel3 = new Bagel("BGLE"); + Bagel bagel4 = new Bagel("BGLS"); + basket.AddProduct(bagel1); + basket.AddProduct(bagel2); + basket.AddProduct(bagel3); + + // act + var result = basket.AddProduct(bagel4); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 3); + Assert.That(result, Is.EqualTo(false)); + } + + // 4. As a Bob's Bagels manager, So that I can expand my business, I’d like to change the capacity of baskets. + [Test] + public void ChangeBasketCapacity() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + Bagel bagel3 = new Bagel("BGLE"); + Bagel bagel4 = new Bagel("BGLS"); + basket.AddProduct(bagel1); + basket.AddProduct(bagel2); + basket.AddProduct(bagel3); + + // act + basket.ChangeBasketCapacity(4); + var result = basket.AddProduct(bagel4); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 4); + Assert.That(result, Is.EqualTo(true)); + } + + // 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. + [Test] + public void RemoveItemDoesNotExist() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + basket.AddProduct(bagel1); + + // act + var result = basket.RemoveProduct(bagel2); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 1); + Assert.That(result, Is.EqualTo(false)); + } + + // 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. + [Test] + public void GetTotalCostofItemsInBasket() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + basket.AddProduct(bagel1); + basket.AddProduct(bagel2); + + // act + var result = basket.TotalCost; + + // assert + Assert.IsTrue(basket.MyBasket.Count == 2); + Assert.That(result, Is.EqualTo(0.88)); + } + + // 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. + [Test] + public void GetCostOfBagel() + { + // arrange + Bagel bagel = new Bagel("BGLO"); + Filling filling = new Filling("FILB"); + bagel.AddFilling(filling); + + // act + var result = bagel.Price; + + // assert + Assert.That(result, Is.EqualTo(0.61)); + } + + // 8. As a customer, So I can shake things up a bit, I'd like to be able to choose fillings for my bagel. + [Test] + public void ChooseFillingForBagel() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLO"); + basket.AddProduct(bagel1); + Filling filling1 = new Filling("FILB"); + Filling filling2 = new Filling("FILE"); + Filling filling3 = new Filling("FILA"); + + // act + var result1 = bagel1.AddFilling(filling1); + var result2 = bagel1.AddFilling(filling2); + var result3 = bagel1.AddFilling(filling3); + + // assert + Assert.IsTrue(bagel1.MyBagel.Count == 2); + Assert.That(bagel1.MyBagel[0].SKU, Is.EqualTo("FILB")); + Assert.That(bagel1.MyBagel[1].SKU, Is.EqualTo("FILE")); + Assert.IsFalse(result3); + } + + // 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. + [Test] + public void GetCostOfFilling() + { + // arrange + Filling filling = new Filling("FILX"); + + // act + var result = filling.Price; + + // assert + Assert.That(result, Is.EqualTo(0.12)); + } + + // 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. + [Test] + public void OnlyProductsInInventory() + { + // arrange + Basket basket = new Basket(); + Bagel bagel1 = new Bagel("BGLA"); + Bagel bagel2 = new Bagel("BGLO"); + Coffee coffee1 = new Coffee("COFA"); + Coffee coffee2 = new Coffee("COFB"); + + // act + var result1 = basket.AddProduct(bagel1); + basket.AddProduct(bagel2); + var result2 = basket.AddProduct(coffee1); + basket.AddProduct(coffee2); + + // assert + Assert.That(result1, Is.EqualTo(false)); + Assert.That(basket.MyBasket[0].SKU, Is.EqualTo("BGLO")); + Assert.That(result2, Is.EqualTo(false)); + Assert.That(basket.MyBasket[1].SKU, Is.EqualTo("COFB")); + } +} diff --git a/exercise.tests/TestsExtention.cs b/exercise.tests/TestsExtention.cs new file mode 100644 index 00000000..1a79aa6e --- /dev/null +++ b/exercise.tests/TestsExtention.cs @@ -0,0 +1,132 @@ +using exercise.main; +using exercise.main.Products; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + public class TestsExtention + { + [Test] + public void AddsDiscounts1() + { + // arrange + Basket basket12 = new Basket(); + Bagel onionBagel = new Bagel("BGLO"); + + basket12.ChangeBasketCapacity(13); + + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + basket12.AddProduct(onionBagel); + + Basket basket6 = new Basket(); + + basket6.ChangeBasketCapacity(7); + + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + basket6.AddProduct(onionBagel); + + Basket basket = new Basket(); + + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + + // act + double result12 = Math.Round(basket12.TotalCost, 2); + double result6 = Math.Round(basket6.TotalCost, 2); + double result = Math.Round(basket.TotalCost, 2); + + // assert + Assert.IsTrue(basket12.MyBasket.Count == 13); + Assert.That(result12, Is.EqualTo(4.48)); + Assert.IsTrue(basket6.MyBasket.Count == 7); + Assert.That(result6, Is.EqualTo(2.98)); + Assert.IsTrue(basket.MyBasket.Count == 3); + Assert.That(result, Is.EqualTo(0.49 * 3)); + } + + [Test] + public void AddsDiscounts2() + { + // arrange + Basket basket = new Basket(); + Bagel onionBagel = new Bagel("BGLO"); + + basket.ChangeBasketCapacity(21); + + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + basket.AddProduct(onionBagel); + + basket.AddProduct(onionBagel); + + // act + double result = Math.Round(basket.TotalCost, 2); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 19); + Assert.That(result, Is.EqualTo(6.97)); + } + + [Test] + public void PrintsReceipt() + { + // arrange + Basket basket = new Basket(); + Basket emptyBasket = new Basket(); + Bagel onionBagel = new Bagel("BGLO"); + Bagel plainBagel = new Bagel("BGLP"); + Coffee blackCoffee = new Coffee("COFB"); + basket.AddProduct(onionBagel); + basket.AddProduct(plainBagel); + basket.AddProduct(blackCoffee); + + // act + var result1 = basket.PrintReceipt(); + var result2 = emptyBasket.PrintReceipt(); + + // assert + Assert.IsTrue(basket.MyBasket.Count == 3); + Assert.IsTrue(result1); + Assert.IsTrue(emptyBasket.MyBasket.Count == 0); + Assert.That(result2, Is.EqualTo(false)); + } + } +} 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 9fed8e17..a3a97d4f 100644 --- a/exercise.tests/exercise.tests.csproj +++ b/exercise.tests/exercise.tests.csproj @@ -17,4 +17,8 @@ + + + +