From 188a382b834139c83274d435a6d002344528b3eb Mon Sep 17 00:00:00 2001 From: Malte Date: Wed, 14 Aug 2024 11:50:19 +0200 Subject: [PATCH] done --- domain-model.md | 13 ++++- tdd-domain-modelling.CSharp.Main/Basket.cs | 39 +++++++++++++++ .../BasketTests.cs | 50 +++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 tdd-domain-modelling.CSharp.Main/Basket.cs create mode 100644 tdd-domain-modelling.CSharp.Test/BasketTests.cs diff --git a/domain-model.md b/domain-model.md index 653f474..5e8b3fc 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,12 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +First Domain Model +| Classes | Methods | Scenario | Outputs | +|-----------------|----------------------------------------------|----------------------|-------------------| +| `Cashier` | `scanItems(Dictionary basket)` | if List is populated | Sum of item.Value | + +Second Domain Model +| Classes | Methods | Scenario | Outputs | +|-----------------|-------------------------------------------------|------------------------|---------------------------------------------| +| `Cashier` | `printReciept(Dictionary basket)` | if List is populated | Returns tupleList with name, cost, quantity | +| `Cashier` | `totalCost(IList> list)` | if List is populated | Sum of item.Value | diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..7fd835c --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling.CSharp.Main +{ + public class Basket + { + public Dictionary wares = new Dictionary { + { "apple", 5 }, + { "milk", 10 }, + { "egg", 2 }, + { "steak", 20 }, + }; + private Dictionary basket = new Dictionary(); + + public bool add(string name) + { + if (wares.ContainsKey(name) && !basket.ContainsKey(name)) { + basket.Add(name, wares.GetValueOrDefault(name)); + return true; + } + return false; + + } + + public int total() + { + int sum = 0; + foreach (var item in basket) + { + sum += item.Value; + } + return sum; + } + } +} diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..86e9b01 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,50 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTest + { + [Test] + public void AddOneItemTest() + { + Basket basket = new Basket(); + bool added = basket.add("apple"); + + Assert.IsTrue(added); + } + + [Test] + public void AddTwoItemTest() + { + Basket basket = new Basket(); + bool added = basket.add("apple"); + added = basket.add("milk"); + + Assert.IsTrue(added); + } + + [Test] + public void AddDuplicateItemTest() + { + Basket basket = new Basket(); + bool added = basket.add("apple"); + added = basket.add("apple"); + + Assert.IsTrue(!added); + } + + [Test] + public void CheckTotalCostTest() + { + Basket basket = new Basket(); + bool added = basket.add("apple"); + added = basket.add("milk"); + added = basket.add("steak"); + + Assert.IsTrue(added); + Assert.That(basket.total() == 35); + } + } +} \ No newline at end of file