From 3762964699f533228e6986a67922c42847c687aa Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 14 Aug 2024 10:56:35 +0200 Subject: [PATCH 1/4] Exercise-1-complete --- domain-model.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/domain-model.md b/domain-model.md index 653f474..c237081 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,27 @@ -#Domain Models In Here \ No newline at end of file +# Domain Models In Here + +## User Story 1: +``` +As a supermarket shopper, +So that I can pay for products at checkout, +I'd like to be able to know the total cost of items in my basket. +``` + +### Domain Model: +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------|--------------------------------------|---------| +| `Supermarket` | `findTotalCost(List products)` | Sum up list cost of list of products | int | + + +## User Story 2: +``` +As an organised individual, +So that I can evaluate my shopping habits, +I'd like to see an itemised receipt that includes the name and price of the products +I bought as well as the quantity, and a total cost of my basket. +``` + +### Domain Model: +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------|-------------------------|---------------| +| `Supermarket` | `getReceipt(List products)` | Giving list of products | Console ouput | From 1fde2433e615f30effefaa87b62b0c19e452505f Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 14 Aug 2024 11:11:53 +0200 Subject: [PATCH 2/4] Exercise-2-part1-complete --- .../Supermarket.cs | 24 +++++++++++++++++++ .../SupermarketTests.cs | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tdd-domain-modelling.CSharp.Main/Supermarket.cs create mode 100644 tdd-domain-modelling.CSharp.Test/SupermarketTests.cs diff --git a/tdd-domain-modelling.CSharp.Main/Supermarket.cs b/tdd-domain-modelling.CSharp.Main/Supermarket.cs new file mode 100644 index 0000000..5511ea7 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Supermarket.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling.CSharp.Main +{ + public class Supermarket + { + private Dictionary _basket = new Dictionary(); + public Dictionary basket { get { return _basket; } } + + public bool Add(string product, int price) + { + if (basket.ContainsKey(product)) + { + return false; + } + basket.Add(product, price); + return true; + } + } +} diff --git a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs new file mode 100644 index 0000000..6a826f9 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs @@ -0,0 +1,24 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class SupermarketTest + { + [TestCase("Apple", 12, true)] + [TestCase("Banana", 5, true)] + [TestCase("Coffee", 8, true)] + public void TestAddNewProductInBasket(string product, int price, bool expectedBasketAddResult) + { + //Arrange + Supermarket customer = new Supermarket(); + + //Act + bool actualBasketAddResult = customer.Add(product, price); + + //Assert + Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); + } + } +} \ No newline at end of file From 3138ed9f05e400e37d1e2687546473abd358f5a1 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 14 Aug 2024 11:15:00 +0200 Subject: [PATCH 3/4] Exercise-2-part2-complete --- .../SupermarketTests.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs index 6a826f9..dff21de 100644 --- a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs +++ b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs @@ -20,5 +20,21 @@ public void TestAddNewProductInBasket(string product, int price, bool expectedBa //Assert Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); } + + [TestCase("Apple", 12, false)] + [TestCase("Banana", 5, false)] + [TestCase("Coffee", 8, false)] + public void TestAddExistingProductInBasket(string product, int price, bool expectedBasketAddResult) + { + //Arrange + Supermarket customer = new Supermarket(); + customer.Add(product, price); + + //Act + bool actualBasketAddResult = customer.Add(product, price); + + //Assert + Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); + } } } \ No newline at end of file From f16c36f9d88858d8ecaac6c83c1558b0b638cd09 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 14 Aug 2024 11:20:46 +0200 Subject: [PATCH 4/4] Exercise-2-part3-complete --- tdd-domain-modelling.CSharp.Main/Supermarket.cs | 9 +++++++++ .../SupermarketTests.cs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tdd-domain-modelling.CSharp.Main/Supermarket.cs b/tdd-domain-modelling.CSharp.Main/Supermarket.cs index 5511ea7..dc2ad0f 100644 --- a/tdd-domain-modelling.CSharp.Main/Supermarket.cs +++ b/tdd-domain-modelling.CSharp.Main/Supermarket.cs @@ -20,5 +20,14 @@ public bool Add(string product, int price) basket.Add(product, price); return true; } + + public int GetTotalPrices() + { + if (basket.Count == 0) + { + return 0; + } + return basket.Values.Sum(x => x); + } } } diff --git a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs index dff21de..060b5cd 100644 --- a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs +++ b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs @@ -36,5 +36,22 @@ public void TestAddExistingProductInBasket(string product, int price, bool expec //Assert Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); } + + [Test] + public void TestTotalCostOfProductsInBasket() + { + //Arrange + Supermarket customer = new Supermarket(); + customer.Add("Apple", 30); + customer.Add("Coffee", 20); + customer.Add("Cheese", 70); + int expectedTotalCost = 120; + + //Act + int actualTotalCost = customer.GetTotalPrices(); + + //Assert + Assert.That(expectedTotalCost, Is.EqualTo(actualTotalCost)); + } } } \ No newline at end of file