From 145f690e7b872b74aa41629779c847f5929eac3d Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 11:59:35 +0200 Subject: [PATCH 01/16] added domain-model --- domain-model.md | 8 ++++++++ exercise.sln | 1 + 2 files changed, 9 insertions(+) create mode 100644 domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..a10c2e24 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,8 @@ +| User stories | Classes | Methods | Output/Function | +|--------------|-----------|--------------------------------------------------------------------------------------------------------------------------|--------------------------------| +| 1,3 | Customer | AddBagel(Bagel bagel) Include Exception handling for full basket | Add bagel to the basket | +| 2,5 | Customer | RemoveBagel(Bagel bagel) Include Exception handling when an item that does not exist in the basket is attempted removed | Remove bagel from basket | +| 6 | Customer | ComputeCost(List<>) | | +| 4 | Manager | ChangeCapacity(int capacity) | Change the capacity of baskets | +| | Bagel | | | +| | Order | | | \ No newline at end of file diff --git a/exercise.sln b/exercise.sln index 0efb5453..132b6c01 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 From 40e5e286afb483953b17ee3199ec008ee41469f3 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 12:53:15 +0200 Subject: [PATCH 02/16] Add bagel test --- exercise.main/Customer.cs | 12 ++++++++++++ exercise.main/IProduct.cs | 13 +++++++++++++ exercise.main/Manager.cs | 12 ++++++++++++ exercise.tests/UnitTest1.cs | 15 ++++++++++----- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 exercise.main/Customer.cs create mode 100644 exercise.main/IProduct.cs create mode 100644 exercise.main/Manager.cs diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs new file mode 100644 index 00000000..7d9269ac --- /dev/null +++ b/exercise.main/Customer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Customer + { + } +} diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs new file mode 100644 index 00000000..5d54a9c4 --- /dev/null +++ b/exercise.main/IProduct.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public interface IProduct + { + double Price { get; set; } + } +} diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs new file mode 100644 index 00000000..6e7b5108 --- /dev/null +++ b/exercise.main/Manager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Manager + { + } +} diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 7bdb8968..736773e7 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -2,14 +2,19 @@ namespace exercise.tests; public class Tests { - [SetUp] - public void Setup() - { - } + //[SetUp] + //public void Setup() + //{ + //} [Test] - public void Test1() + public void TestAddBagelToBasket() { + Bagel bagel = new Bagel(); + Basket basket = new Basket(); + Customer customer = new Customer(); + customer.AddProduct(bagel); + Assert.That(basket.Count > 1); Assert.Pass(); } } \ No newline at end of file From ac016014d0fb31f61a2dde7724a4b7b5553613e7 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 14:00:18 +0200 Subject: [PATCH 03/16] Passed AddBagelTest --- exercise.main/Bagel.cs | 18 ++++++++++++++++ exercise.main/Basket.cs | 31 ++++++++++++++++++++++++++++ exercise.main/Customer.cs | 15 ++++++++++++++ exercise.main/IProduct.cs | 4 +++- exercise.tests/UnitTest1.cs | 5 +++-- exercise.tests/exercise.tests.csproj | 4 ++++ 6 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 exercise.main/Bagel.cs create mode 100644 exercise.main/Basket.cs diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs new file mode 100644 index 00000000..0c80839d --- /dev/null +++ b/exercise.main/Bagel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Bagel : IProduct + { + //public double Price { get; set; } + //public string Variant { get; set; } + + public Bagel() + { + } + } +} diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..417c2d6c --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + private List_basket { get; } + private static int _capacity { get; set; } = 3; + + public Basket() + { + _basket = new List(); + } + + public void AddProduct(IProduct product) + { + _basket.Add(product); + } + + public int Count() + { + return _basket.Count; + } + + public List GetBasket { get { return _basket; } } + } +} diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 7d9269ac..795efc21 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -8,5 +8,20 @@ namespace exercise.main { public class Customer { + private Basket _basket { get; set; } + + public Customer() + { + _basket = new Basket(); + } + + public void AddProduct(IProduct product) + { + _basket.AddProduct(product); + } + + public Basket GetBasket { get { return _basket; } } } + + } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 5d54a9c4..c1a6f8c0 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -6,8 +6,10 @@ namespace exercise.main { + public interface IProduct { - double Price { get; set; } + //double Price { get; set; } + //string Variant { get; set; } } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 736773e7..7412b474 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -1,3 +1,5 @@ +using exercise.main; + namespace exercise.tests; public class Tests @@ -11,10 +13,9 @@ public class Tests public void TestAddBagelToBasket() { Bagel bagel = new Bagel(); - Basket basket = new Basket(); Customer customer = new Customer(); customer.AddProduct(bagel); - Assert.That(basket.Count > 1); + Assert.That(customer.GetBasket.Count() > 0); 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 @@ + + + + From 1b14b0860e90f3af1948ac0706ce7c9492095065 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 15:23:29 +0200 Subject: [PATCH 04/16] Remove Bagel test Created --- exercise.main/Bagel.cs | 20 ++++++++++++++++---- exercise.main/Basket.cs | 3 ++- exercise.main/Customer.cs | 1 + exercise.main/IProduct.cs | 5 +++-- exercise.tests/UnitTest1.cs | 14 +++++++++++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 0c80839d..36044861 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -8,11 +8,23 @@ namespace exercise.main { public class Bagel : IProduct { - //public double Price { get; set; } - //public string Variant { get; set; } - - public Bagel() + public Dictionary _prices = new Dictionary() + { + {"Onion", 0.49}, + {"Plain", 0.39}, + {"Everything", 0.49}, + {"Sesame", 0.49}, + }; + public double Price { get; set; } + public string Name { get; set; } + public string Variant { get; set; } + + public Bagel(string variant) { + Name = "Bagel"; + Variant = variant; + Price = _prices[variant]; + } } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 417c2d6c..695bf593 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -17,10 +17,11 @@ public Basket() } public void AddProduct(IProduct product) - { + { _basket.Add(product); } + public int Count() { return _basket.Count; diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 795efc21..07672632 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -20,6 +20,7 @@ public void AddProduct(IProduct product) _basket.AddProduct(product); } + public Basket GetBasket { get { return _basket; } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index c1a6f8c0..afd08b87 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -9,7 +9,8 @@ namespace exercise.main public interface IProduct { - //double Price { get; set; } - //string Variant { get; set; } + double Price { get; set; } + string Name { get; set; } + string Variant { get; set; } } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 7412b474..23b3e48a 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -12,10 +12,22 @@ public class Tests [Test] public void TestAddBagelToBasket() { - Bagel bagel = new Bagel(); + Bagel bagel = new Bagel("Onion"); Customer customer = new Customer(); customer.AddProduct(bagel); Assert.That(customer.GetBasket.Count() > 0); Assert.Pass(); } + + [Test] + public void TestRemoveBagelFromBasket() + { + Bagel bagel = new Bagel("Onion"); + Customer customer = new Customer(); + customer.AddProduct(bagel); + Assert.That(customer.GetBasket.Count() > 0); + customer.RemoveProduct(bagel); + Assert.That(customer.GetBasket.Count() < 1); + Assert.Pass(); + } } \ No newline at end of file From d38facfe2ce4e01e70b0c19644444d53d617b206 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 15:24:36 +0200 Subject: [PATCH 05/16] remove bagel test passed --- exercise.main/Basket.cs | 4 ++++ exercise.main/Customer.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 695bf593..0b3b40ed 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -21,6 +21,10 @@ public void AddProduct(IProduct product) _basket.Add(product); } + public void RemoveProduct(IProduct product) + { + _basket.Remove(product); + } public int Count() { diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 07672632..aaec67d6 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -20,6 +20,10 @@ public void AddProduct(IProduct product) _basket.AddProduct(product); } + public void RemoveProduct(IProduct product) + { + _basket.RemoveProduct(product); + } public Basket GetBasket { get { return _basket; } } } From ee8aa9cb00ebd01101461d2cd300b816f6e1bee3 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 16:15:13 +0200 Subject: [PATCH 06/16] Change basket capacity test --- exercise.main/Bagel.cs | 3 +++ exercise.main/Basket.cs | 13 ++++++++++--- exercise.main/Manager.cs | 5 +++++ exercise.tests/UnitTest1.cs | 27 +++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 36044861..37b31c10 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -18,12 +18,15 @@ public class Bagel : IProduct public double Price { get; set; } public string Name { get; set; } public string Variant { get; set; } + + public int _fillingPrice; public Bagel(string variant) { Name = "Bagel"; Variant = variant; Price = _prices[variant]; + _fillingPrice = 0; } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 0b3b40ed..833db0c5 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -8,8 +8,8 @@ namespace exercise.main { public class Basket { - private List_basket { get; } - private static int _capacity { get; set; } = 3; + private List _basket { get; } + public static int Capacity { get; set; } = 3; public Basket() { @@ -18,7 +18,14 @@ public Basket() public void AddProduct(IProduct product) { - _basket.Add(product); + if (_basket.Count() == Capacity) + { + throw new InvalidOperationException("Basket capacity full - you can not add more items"); + } + else + { + _basket.Add(product); + } } public void RemoveProduct(IProduct product) diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 6e7b5108..a70391ab 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -8,5 +8,10 @@ namespace exercise.main { public class Manager { + public Manager() + { + } + + } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 23b3e48a..42539bb5 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -30,4 +30,31 @@ public void TestRemoveBagelFromBasket() Assert.That(customer.GetBasket.Count() < 1); Assert.Pass(); } + + [Test] + public void TestBasketCapacity() + { + Bagel bagel1 = new Bagel("Onion"); + Bagel bagel2 = new Bagel("Plain"); + Bagel bagel3 = new Bagel("Everything"); + Bagel bagel4 = new Bagel("Sesame"); + Customer customer = new Customer(); + customer.AddProduct(bagel1); + customer.AddProduct(bagel2); + customer.AddProduct(bagel3); + //customer.AddProduct(bagel4); + Assert.Throws(() => customer.AddProduct(bagel4)); + //Assert.That(); + } + + [Test] + + public void TestManagerCapacityChange() + { + Customer customer = new Customer(); + Assert.That(customer.GetBasket.Count() == 3); + Manager manager = new Manager(); + manager.ChangeBasketCapacity(4); + Assert.That(customer.GetBasket.Count() == 4); + } } \ No newline at end of file From 25215099aaa4f5ad5d2c5733639a27c9c93479b6 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Mon, 11 Aug 2025 16:28:23 +0200 Subject: [PATCH 07/16] Capacity change test passed --- exercise.main/Basket.cs | 2 +- exercise.main/Manager.cs | 5 ++++- exercise.tests/UnitTest1.cs | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 833db0c5..0c7d654d 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -9,7 +9,7 @@ namespace exercise.main public class Basket { private List _basket { get; } - public static int Capacity { get; set; } = 3; + public static int Capacity = 3; public Basket() { diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index a70391ab..29c9430b 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -12,6 +12,9 @@ public Manager() { } - + public void ChangeBasketCapacity(int newCapacity) + { + Basket.Capacity = newCapacity; + } } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 42539bb5..60b13e9b 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -51,10 +51,11 @@ public void TestBasketCapacity() public void TestManagerCapacityChange() { - Customer customer = new Customer(); - Assert.That(customer.GetBasket.Count() == 3); + Assert.That(Basket.Capacity == 3); Manager manager = new Manager(); manager.ChangeBasketCapacity(4); - Assert.That(customer.GetBasket.Count() == 4); + Assert.That(Basket.Capacity == 4); + + } } \ No newline at end of file From 8eb195777cc49da0ea57dd195fff73556dd156ee Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 08:51:51 +0200 Subject: [PATCH 08/16] Invalid remove test --- exercise.main/Bagel.cs | 21 ++++++++---------- exercise.main/ProductCatalog.cs | 38 +++++++++++++++++++++++++++++++++ exercise.tests/UnitTest1.cs | 25 +++++++++++++++------- 3 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 exercise.main/ProductCatalog.cs diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 37b31c10..3e0f850b 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -8,25 +8,22 @@ namespace exercise.main { public class Bagel : IProduct { - public Dictionary _prices = new Dictionary() - { - {"Onion", 0.49}, - {"Plain", 0.39}, - {"Everything", 0.49}, - {"Sesame", 0.49}, - }; public double Price { get; set; } public string Name { get; set; } public string Variant { get; set; } public int _fillingPrice; - public Bagel(string variant) + public Bagel(string SKU) { - Name = "Bagel"; - Variant = variant; - Price = _prices[variant]; - _fillingPrice = 0; + //Name = "Bagel"; + //Variant = variant; + //Price = _prices[variant]; + //_fillingPrice = 0; + var info = ProductCatalog.GetProductInfo(SKU); + Price = info.Price; + Name = info.Name; + Variant = info.Variant; } } diff --git a/exercise.main/ProductCatalog.cs b/exercise.main/ProductCatalog.cs new file mode 100644 index 00000000..59d42da4 --- /dev/null +++ b/exercise.main/ProductCatalog.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public static class ProductCatalog + { + private static readonly Dictionary _products = new() + { + { "BGLO", ("Bagel", 0.49, "Onion") }, + { "BGLP", ("Bagel", 0.39, "Plain") }, + { "BGLE", ("Bagel", 0.49, "Everything") }, + { "BGLS", ("Bagel", 0.49, "Sesame") }, + { "COFB", ("Coffee", 0.99, "Black") }, + { "COFW", ("Coffee", 1.19, "White") }, + { "COFC", ("Coffee", 1.29, "Capuccino") }, + { "COFL", ("Coffee", 1.29, "Latte") }, + { "FILB", ("Filling", 0.12, "Bacon") }, + { "FILE", ("Filling", 0.12, "Egg") }, + { "FILC", ("Filling", 0.12, "Cheese") }, + { "FILX", ("Filling", 0.12, "Cream Cheese") }, + { "FILS", ("Filling", 0.12, "Smoked Salmon") }, + { "FILH", ("Filling", 0.12, "Ham") } + }; + + public static (string Name, double Price, string Variant) GetProductInfo(string code) + { + if (_products.TryGetValue(code, out var product)) + { + return product; + } + throw new KeyNotFoundException($"Product code '{code}' not found"); + } + } +} diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 60b13e9b..512effab 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -1,4 +1,5 @@ using exercise.main; +using System.Buffers.Text; namespace exercise.tests; @@ -12,7 +13,7 @@ public class Tests [Test] public void TestAddBagelToBasket() { - Bagel bagel = new Bagel("Onion"); + Bagel bagel = new Bagel("BGLO"); Customer customer = new Customer(); customer.AddProduct(bagel); Assert.That(customer.GetBasket.Count() > 0); @@ -22,7 +23,7 @@ public void TestAddBagelToBasket() [Test] public void TestRemoveBagelFromBasket() { - Bagel bagel = new Bagel("Onion"); + Bagel bagel = new Bagel("BGLO"); Customer customer = new Customer(); customer.AddProduct(bagel); Assert.That(customer.GetBasket.Count() > 0); @@ -34,10 +35,10 @@ public void TestRemoveBagelFromBasket() [Test] public void TestBasketCapacity() { - Bagel bagel1 = new Bagel("Onion"); - Bagel bagel2 = new Bagel("Plain"); - Bagel bagel3 = new Bagel("Everything"); - Bagel bagel4 = new Bagel("Sesame"); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + Bagel bagel3 = new Bagel("BGLE"); + Bagel bagel4 = new Bagel("BGLS"); Customer customer = new Customer(); customer.AddProduct(bagel1); customer.AddProduct(bagel2); @@ -48,14 +49,22 @@ public void TestBasketCapacity() } [Test] - public void TestManagerCapacityChange() { Assert.That(Basket.Capacity == 3); Manager manager = new Manager(); manager.ChangeBasketCapacity(4); Assert.That(Basket.Capacity == 4); + } - + [Test] + public void TestRemoveInvalidItem() + { + Customer customer = new Customer(); + Bagel bagel = new Bagel("BGLO"); + Assert.Throws(() => customer.RemoveProduct(bagel)); + } + + } \ No newline at end of file From 09724da07e90f6e047940c3bda715ff5a04f7699 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 08:53:11 +0200 Subject: [PATCH 09/16] Passed invalid remove test --- exercise.main/Basket.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 0c7d654d..94bc6eee 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -31,6 +31,14 @@ public void AddProduct(IProduct product) public void RemoveProduct(IProduct product) { _basket.Remove(product); + if (_basket.Contains(product)) + { + _basket.Remove(product); + } + else + { + throw new InvalidOperationException("Product does not exist in basket"); + } } public int Count() From eb0845469f11912cce61f0e678f7149bd5e5ebd4 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 08:57:57 +0200 Subject: [PATCH 10/16] Compute basket cost test --- exercise.tests/UnitTest1.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 512effab..049c002a 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -66,5 +66,22 @@ public void TestRemoveInvalidItem() } + [Test] + public void TestComputeBasketCost() + { + Customer customer = new Customer(); + Bagel bagel1 = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLP"); + Bagel bagel3 = new Bagel("BGLE"); + Bagel bagel4 = new Bagel("BGLS"); + customer.AddProduct(bagel1); + customer.AddProduct(bagel2); + customer.AddProduct(bagel3); + customer.AddProduct(bagel4); + double expectedPrice = 1.86d; + Assert.That(expectedPrice, Is.EqualTo(customer.BasketCost())); + + + } } \ No newline at end of file From 24e01b1638ba363968f7d3479eb4050ac3511dec Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 10:07:36 +0200 Subject: [PATCH 11/16] bagel price --- exercise.main/Basket.cs | 8 +++++++- exercise.main/Customer.cs | 5 +++++ exercise.tests/UnitTest1.cs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 94bc6eee..90fcded7 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -30,7 +30,7 @@ public void AddProduct(IProduct product) public void RemoveProduct(IProduct product) { - _basket.Remove(product); + //_basket.Remove(product); if (_basket.Contains(product)) { _basket.Remove(product); @@ -41,6 +41,12 @@ public void RemoveProduct(IProduct product) } } + public double ComputeCost() + { + return _basket.Sum(x => x.Price); + + } + public int Count() { return _basket.Count; diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index aaec67d6..becca345 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -25,6 +25,11 @@ public void RemoveProduct(IProduct product) _basket.RemoveProduct(product); } + public double BasketCost() + { + return _basket.ComputeCost(); + } + public Basket GetBasket { get { return _basket; } } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 049c002a..f7d3d015 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -73,15 +73,22 @@ public void TestComputeBasketCost() Bagel bagel1 = new Bagel("BGLO"); Bagel bagel2 = new Bagel("BGLP"); Bagel bagel3 = new Bagel("BGLE"); - Bagel bagel4 = new Bagel("BGLS"); + //Bagel bagel4 = new Bagel("BGLS"); customer.AddProduct(bagel1); customer.AddProduct(bagel2); customer.AddProduct(bagel3); - customer.AddProduct(bagel4); - double expectedPrice = 1.86d; + //customer.AddProduct(bagel4); + double expectedPrice = 1.37d; Assert.That(expectedPrice, Is.EqualTo(customer.BasketCost())); + } - + [Test] + public void TestBagelCostBeforeAdd() + { + Customer customer = new Customer(); + Bagel bagel = new Bagel("BGLO"); + double expectedBagelPrice = 0.49d; + Assert.That(expectedBagelPrice, Is.EqualTo(bagel.Price)); } } \ No newline at end of file From 19bed6c82b3a9fd1ce8b19d35e68d40e3583cd74 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 10:16:48 +0200 Subject: [PATCH 12/16] Filling price test passed --- exercise.main/Bagel.cs | 8 ++++++++ exercise.main/Filling.cs | 23 +++++++++++++++++++++++ exercise.tests/UnitTest1.cs | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 exercise.main/Filling.cs diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 3e0f850b..38aaf7dd 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -13,6 +13,8 @@ public class Bagel : IProduct public string Variant { get; set; } public int _fillingPrice; + + public List fillings; public Bagel(string SKU) { @@ -24,7 +26,13 @@ public Bagel(string SKU) Price = info.Price; Name = info.Name; Variant = info.Variant; + fillings = new List(); + + } + public void AddFilling(Filling filling) + { + fillings.Add(filling); } } } diff --git a/exercise.main/Filling.cs b/exercise.main/Filling.cs new file mode 100644 index 00000000..f7c47ca7 --- /dev/null +++ b/exercise.main/Filling.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Filling : IProduct + { + public double Price { get; set; } + public string Name { get; set; } + public string Variant { get; set; } + + public Filling(string SKU) + { + var info = ProductCatalog.GetProductInfo(SKU); + Price = info.Price; + Name = info.Name; + Variant = info.Variant; + } + } +} diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index f7d3d015..3877f8e4 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -91,4 +91,20 @@ public void TestBagelCostBeforeAdd() Assert.That(expectedBagelPrice, Is.EqualTo(bagel.Price)); } + [Test] + public void TestAddFillingsToBagel() + { + Bagel bagel = new Bagel("BGLO"); + Filling bacon = new Filling("FILB"); + bagel.AddFilling(bacon); + Assert.That(bagel.fillings.Contains(bacon)); + } + + [Test] + public void TestFillingPrice() + { + Filling bacon = new Filling("FILB"); + Assert.That(bacon.Price, Is.EqualTo(0.12)); + } + } \ No newline at end of file From f4716e21ba0535910009b4d7ce07e8f27a20a4f2 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 10:22:20 +0200 Subject: [PATCH 13/16] Invalid item test passed --- exercise.tests/UnitTest1.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 3877f8e4..c75c3213 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -107,4 +107,16 @@ public void TestFillingPrice() Assert.That(bacon.Price, Is.EqualTo(0.12)); } + [Test] + public void TestInvalidItem() + { + //Filling bacon = new Filling("FILA"); + + //Bagel bagel = new Bagel("BGLZ"); + + Assert.Throws(() => new Bagel("BGLZ")); + Assert.Throws(() => new Filling("AAAA")); + + } + } \ No newline at end of file From 5b7155f9a67c3d96378fa5b197a5641e617e3f95 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 10:27:40 +0200 Subject: [PATCH 14/16] Corrected domain-model --- domain-model.md | 16 ++++++++-------- exercise.main/Bagel.cs | 2 +- exercise.main/Coffee.cs | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 exercise.main/Coffee.cs diff --git a/domain-model.md b/domain-model.md index a10c2e24..b42fec4e 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,8 +1,8 @@ -| User stories | Classes | Methods | Output/Function | -|--------------|-----------|--------------------------------------------------------------------------------------------------------------------------|--------------------------------| -| 1,3 | Customer | AddBagel(Bagel bagel) Include Exception handling for full basket | Add bagel to the basket | -| 2,5 | Customer | RemoveBagel(Bagel bagel) Include Exception handling when an item that does not exist in the basket is attempted removed | Remove bagel from basket | -| 6 | Customer | ComputeCost(List<>) | | -| 4 | Manager | ChangeCapacity(int capacity) | Change the capacity of baskets | -| | Bagel | | | -| | Order | | | \ No newline at end of file +| User stories | Classes | Methods | Considerations | Output/Function | +|--------------|-----------|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------| +| 1,3,7,10 | Customer | AddProduct(IProduct product) (1) | Exception handling for full basket (3) Exception handling for invalid product (10) Inform customer of the price before adding (7) | Add product to costumers basket | +| 2,5 | Customer | RemoveProduct(IProduct product) (2) | Exception handling for nonexistent item (5) | Remove product from customers basket | +| 6 | Customer | ComputeCost(List basket) (6) | | Compute the total cost of the items in the basket | +| 4 | Manager | ChangeCapacity(int capacity) (4) | | Change the capacity of baskets | +| 8,9 | Bagel | AddFilling(Bagel filling) (8) | Inform customer about the price of a filling (9) | Add fillings to a Bagel | +| | Basket | AddProduct(IProduct product) | | Add product to the basket instance | | | \ No newline at end of file diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 38aaf7dd..00f82d3d 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -12,7 +12,7 @@ public class Bagel : IProduct public string Name { get; set; } public string Variant { get; set; } - public int _fillingPrice; + public double _fillingPrice; public List fillings; diff --git a/exercise.main/Coffee.cs b/exercise.main/Coffee.cs new file mode 100644 index 00000000..c03b51d6 --- /dev/null +++ b/exercise.main/Coffee.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + internal class Coffee + { + public double Price { get; set; } + public string Name { get; set; } + public string Variant { get; set; } + + public Coffee(string SKU) + { + var info = ProductCatalog.GetProductInfo(SKU); + Price = info.Price; + Name = info.Name; + Variant = info.Variant; + } + } +} From 390953ab03ef2da2c8a434c8a6464ad6bbe17cd1 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Tue, 12 Aug 2025 15:20:59 +0200 Subject: [PATCH 15/16] Discount extension --- exercise.main/Bagel.cs | 10 ++++-- exercise.main/Basket.cs | 55 ++++++++++++++++++++++++++++-- exercise.main/Coffee.cs | 4 +-- exercise.main/Customer.cs | 2 +- exercise.main/Filling.cs | 2 +- exercise.main/IProduct.cs | 2 +- exercise.main/ProductCatalog.cs | 32 +++++++++--------- exercise.tests/UnitTest1.cs | 60 +++++++++++++++++++++++++++++++-- 8 files changed, 138 insertions(+), 29 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 00f82d3d..9aa56c4e 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -8,13 +8,13 @@ namespace exercise.main { public class Bagel : IProduct { - public double Price { get; set; } + public decimal Price { get; set; } public string Name { get; set; } public string Variant { get; set; } - public double _fillingPrice; + public decimal _fillingPrice { get; set; } = 0; - public List fillings; + public List fillings { get; set; } public Bagel(string SKU) { @@ -33,6 +33,10 @@ public Bagel(string SKU) public void AddFilling(Filling filling) { fillings.Add(filling); + //_fillingPrice += filling.Price; + Price += filling.Price; } + + public List GetFillings() {return fillings;} } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 90fcded7..21a0dca8 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -41,10 +42,60 @@ public void RemoveProduct(IProduct product) } } - public double ComputeCost() + public decimal ComputeCost() { - return _basket.Sum(x => x.Price); + //return _basket.Sum(x => x.Price) - this.ComputeDiscounts(); + var info = this.ComputeDiscounts(); + decimal total = info.Discounts + info.RemainingItems.Sum(x => x.Price); + return total; + } + + public (decimal Discounts, List RemainingItems) ComputeDiscounts() + { + List bagels = _basket.Where(x => x is Bagel).OrderBy(v => v.Price).ToList(); + List coffees = _basket.Where(x => x is Coffee).OrderBy(v => v.Price).ToList(); + + decimal sixBagels = 0m; + decimal twelveBagels = 0m; + decimal coffeeBagels = 0m; + + int remainingBagels = 0; + int mod = bagels.Count % 12; + + if (bagels.Count > 11) + { + // USe list List.RemoveRange() starting at zero + int val = bagels.Count - mod; + twelveBagels = val * 3.99m / (12m); + bagels.RemoveRange(0,val); + } + if (mod > 5) + { + sixBagels = 2.49m; + remainingBagels = mod - 6; + bagels.RemoveRange(0, 6); + } + else + { + remainingBagels = mod; + } + + foreach (IProduct coffee in coffees) + { + if (coffee.Variant == "Black" && remainingBagels > 0) + { + coffeeBagels += 1.25m; + remainingBagels--; + bagels.RemoveAt(0); + //coffees.Remove(coffee); + coffee.Price = 0m; + } + } + + decimal discounts = twelveBagels + sixBagels + coffeeBagels; + List remainingItems = bagels.Concat(coffees).ToList(); + return (discounts, remainingItems); } public int Count() diff --git a/exercise.main/Coffee.cs b/exercise.main/Coffee.cs index c03b51d6..b70a2cad 100644 --- a/exercise.main/Coffee.cs +++ b/exercise.main/Coffee.cs @@ -6,9 +6,9 @@ namespace exercise.main { - internal class Coffee + public class Coffee : IProduct { - public double Price { get; set; } + public decimal Price { get; set; } public string Name { get; set; } public string Variant { get; set; } diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index becca345..ad171fac 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -25,7 +25,7 @@ public void RemoveProduct(IProduct product) _basket.RemoveProduct(product); } - public double BasketCost() + public decimal BasketCost() { return _basket.ComputeCost(); } diff --git a/exercise.main/Filling.cs b/exercise.main/Filling.cs index f7c47ca7..775e604b 100644 --- a/exercise.main/Filling.cs +++ b/exercise.main/Filling.cs @@ -8,7 +8,7 @@ namespace exercise.main { public class Filling : IProduct { - public double Price { get; set; } + public decimal Price { get; set; } public string Name { get; set; } public string Variant { get; set; } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index afd08b87..5bff776e 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -9,7 +9,7 @@ namespace exercise.main public interface IProduct { - double Price { get; set; } + decimal Price { get; set; } string Name { get; set; } string Variant { get; set; } } diff --git a/exercise.main/ProductCatalog.cs b/exercise.main/ProductCatalog.cs index 59d42da4..f8009df7 100644 --- a/exercise.main/ProductCatalog.cs +++ b/exercise.main/ProductCatalog.cs @@ -8,25 +8,25 @@ namespace exercise.main { public static class ProductCatalog { - private static readonly Dictionary _products = new() + private static readonly Dictionary _products = new() { - { "BGLO", ("Bagel", 0.49, "Onion") }, - { "BGLP", ("Bagel", 0.39, "Plain") }, - { "BGLE", ("Bagel", 0.49, "Everything") }, - { "BGLS", ("Bagel", 0.49, "Sesame") }, - { "COFB", ("Coffee", 0.99, "Black") }, - { "COFW", ("Coffee", 1.19, "White") }, - { "COFC", ("Coffee", 1.29, "Capuccino") }, - { "COFL", ("Coffee", 1.29, "Latte") }, - { "FILB", ("Filling", 0.12, "Bacon") }, - { "FILE", ("Filling", 0.12, "Egg") }, - { "FILC", ("Filling", 0.12, "Cheese") }, - { "FILX", ("Filling", 0.12, "Cream Cheese") }, - { "FILS", ("Filling", 0.12, "Smoked Salmon") }, - { "FILH", ("Filling", 0.12, "Ham") } + { "BGLO", ("Bagel", 0.49m, "Onion") }, + { "BGLP", ("Bagel", 0.39m, "Plain") }, + { "BGLE", ("Bagel", 0.49m, "Everything") }, + { "BGLS", ("Bagel", 0.49m, "Sesame") }, + { "COFB", ("Coffee", 0.99m, "Black") }, + { "COFW", ("Coffee", 1.19m, "White") }, + { "COFC", ("Coffee", 1.29m, "Capuccino") }, + { "COFL", ("Coffee", 1.29m, "Latte") }, + { "FILB", ("Filling", 0.12m, "Bacon") }, + { "FILE", ("Filling", 0.12m, "Egg") }, + { "FILC", ("Filling", 0.12m, "Cheese") }, + { "FILX", ("Filling", 0.12m, "Cream Cheese") }, + { "FILS", ("Filling", 0.12m, "Smoked Salmon") }, + { "FILH", ("Filling", 0.12m, "Ham") } }; - public static (string Name, double Price, string Variant) GetProductInfo(string code) + public static (string Name, decimal Price, string Variant) GetProductInfo(string code) { if (_products.TryGetValue(code, out var product)) { diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index c75c3213..971484c5 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -78,7 +78,7 @@ public void TestComputeBasketCost() customer.AddProduct(bagel2); customer.AddProduct(bagel3); //customer.AddProduct(bagel4); - double expectedPrice = 1.37d; + decimal expectedPrice = 1.37m; Assert.That(expectedPrice, Is.EqualTo(customer.BasketCost())); } @@ -87,7 +87,7 @@ public void TestBagelCostBeforeAdd() { Customer customer = new Customer(); Bagel bagel = new Bagel("BGLO"); - double expectedBagelPrice = 0.49d; + decimal expectedBagelPrice = 0.49m; Assert.That(expectedBagelPrice, Is.EqualTo(bagel.Price)); } @@ -104,7 +104,7 @@ public void TestAddFillingsToBagel() public void TestFillingPrice() { Filling bacon = new Filling("FILB"); - Assert.That(bacon.Price, Is.EqualTo(0.12)); + Assert.That(bacon.Price, Is.EqualTo(0.12m)); } [Test] @@ -119,4 +119,58 @@ public void TestInvalidItem() } + [Test] + public void TestSomething() + { + Customer customer = new Customer(); + Bagel bagel = new Bagel("BGLO"); + Filling bacon = new Filling("FILB"); + bagel.AddFilling(bacon); + customer.AddProduct(bagel); + Assert.That(customer.BasketCost(), Is.EqualTo(0.61m)); + + } + + [Test] + public void TestDiscounts() + { + Customer customer = new Customer(); + Manager manager = new Manager(); + manager.ChangeBasketCapacity(50); + for (int i = 0; i < 12; i++) + { + customer.AddProduct(new Bagel("BGLO")); + } + Assert.That(customer.BasketCost(), Is.EqualTo(3.99m)); + + for (int i = 0; i < 6; i++) + { + customer.AddProduct(new Bagel("BGLO")); + } + Assert.That(customer.BasketCost(), Is.EqualTo(6.48m)); + + Customer customer2 = new Customer(); + for (int i = 0; i < 12; i++) + { + customer2.AddProduct(new Bagel("BGLS")); + } + customer2.AddProduct(new Bagel("BGLP")); + customer2.AddProduct(new Bagel("BGLP")); + Console.WriteLine(customer2.BasketCost()); + + Assert.That(customer2.BasketCost(), Is.EqualTo(4.97m)); + + customer2.AddProduct(new Coffee("COFB")); + + Assert.That(customer2.BasketCost(), Is.EqualTo(5.73m)); + + for (int i = 0; i < 6; i++) + { + customer2.AddProduct(new Bagel("BGLS")); + } + Assert.That(customer2.BasketCost(), Is.EqualTo(8.22m)); + + manager.ChangeBasketCapacity(3); + } + } \ No newline at end of file From b81937437e8dc82bd2d474580c44fbc9c0d4daaf Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Wed, 13 Aug 2025 15:50:56 +0200 Subject: [PATCH 16/16] Made receipt pretty --- exercise.main/Bagel.cs | 4 +-- exercise.main/Basket.cs | 55 ++++++++++++++++++++++++++++++++++++- exercise.main/Customer.cs | 5 ++++ exercise.tests/UnitTest1.cs | 36 +++++++++++++++++++++--- 4 files changed, 93 insertions(+), 7 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 9aa56c4e..39c50c69 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -34,9 +34,9 @@ public void AddFilling(Filling filling) { fillings.Add(filling); //_fillingPrice += filling.Price; - Price += filling.Price; + //Price += filling.Price; } - public List GetFillings() {return fillings;} + public List GetFillings() { return fillings; } } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 21a0dca8..3c53b043 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -10,6 +10,7 @@ namespace exercise.main public class Basket { private List _basket { get; } + private List _bagelFillings { get; } = new List(); public static int Capacity = 3; public Basket() @@ -25,6 +26,11 @@ public void AddProduct(IProduct product) } else { + if (product is Bagel) + { + Bagel bagel = (Bagel)product; + bagel.GetFillings().ForEach(x => _bagelFillings.Add(x)); + } _basket.Add(product); } } @@ -46,7 +52,7 @@ public decimal ComputeCost() { //return _basket.Sum(x => x.Price) - this.ComputeDiscounts(); var info = this.ComputeDiscounts(); - decimal total = info.Discounts + info.RemainingItems.Sum(x => x.Price); + decimal total = info.Discounts + info.RemainingItems.Sum(x => x.Price) + _bagelFillings.Sum(x => x.Price); return total; } @@ -98,6 +104,53 @@ public decimal ComputeCost() return (discounts, remainingItems); } + public string GetReceipt() + { + StringBuilder sb = new StringBuilder(); + Dictionary productCount = new(); + foreach (IProduct item in _basket) + { + if (productCount.ContainsKey(item.Variant)) + { + int val = productCount[item.Variant].count + 1; + decimal price = productCount[item.Variant].priceTotal; + productCount[item.Variant] = (item.Name, val, price+item.Price); + } + else + { + productCount[item.Variant] = (item.Name, 1, item.Price); + } + } + int totalWidth = 30; + string title = "~~~ Bob's Bagels ~~~"; + string time = DateTime.Now.ToString(); + string end = "Thank you for your order!"; + + sb.AppendFormat("{0," + (((totalWidth - title.Length) / 2) + title.Length) + "}", title); + sb.AppendLine(); + sb.AppendLine(); + sb.AppendFormat("{0," + (((totalWidth - time.Length) / 2) + time.Length) + "}", time); + sb.AppendLine(); + sb.AppendLine(); + sb.AppendLine(new String('-', 30)); + sb.AppendLine(); + //sb.AppendLine(); + + foreach (var item in productCount) + { + sb.AppendFormat("{0,-20}{1,-5}{2,-5}", item.Key, item.Value.count, item.Value.priceTotal); + sb.AppendLine(); + } + + sb.AppendLine(); + sb.AppendLine(new String('-', 30)); + sb.AppendLine(); + sb.AppendFormat("{0," + (((totalWidth - end.Length) / 2) + end.Length) + "}", end); + + return sb.ToString(); + } + + public int Count() { return _basket.Count; diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index ad171fac..9bc4a539 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -30,6 +30,11 @@ public decimal BasketCost() return _basket.ComputeCost(); } + public string GetReceipt() + { + return _basket.GetReceipt(); + } + public Basket GetBasket { get { return _basket; } } } diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs index 971484c5..975fb059 100644 --- a/exercise.tests/UnitTest1.cs +++ b/exercise.tests/UnitTest1.cs @@ -154,23 +154,51 @@ public void TestDiscounts() { customer2.AddProduct(new Bagel("BGLS")); } - customer2.AddProduct(new Bagel("BGLP")); + Bagel bagel = new Bagel("BGLP"); + bagel.AddFilling(new Filling("FILB")); + customer2.AddProduct(bagel); customer2.AddProduct(new Bagel("BGLP")); Console.WriteLine(customer2.BasketCost()); - Assert.That(customer2.BasketCost(), Is.EqualTo(4.97m)); + Assert.That(customer2.BasketCost(), Is.EqualTo(5.09m)); customer2.AddProduct(new Coffee("COFB")); - Assert.That(customer2.BasketCost(), Is.EqualTo(5.73m)); + Assert.That(customer2.BasketCost(), Is.EqualTo(5.85m)); for (int i = 0; i < 6; i++) { customer2.AddProduct(new Bagel("BGLS")); } - Assert.That(customer2.BasketCost(), Is.EqualTo(8.22m)); + Assert.That(customer2.BasketCost(), Is.EqualTo(8.34m)); manager.ChangeBasketCapacity(3); } + [Test] + public void TestReceipt() + { + Customer customer = new Customer(); + Manager manager = new Manager(); + manager.ChangeBasketCapacity(50); + for (int i = 0; i < 2; i++) + { + customer.AddProduct(new Bagel("BGLO")); + } + for (int i = 0; i < 12; i++) + { + customer.AddProduct(new Bagel("BGLP")); + } + for (int i = 0; i < 6; i++) + { + customer.AddProduct(new Bagel("BGLE")); + } + for (int i = 0; i < 3; i++) + { + customer.AddProduct(new Coffee("COFB")); + } + + Console.WriteLine(customer.GetReceipt()); + } + } \ No newline at end of file