From 6bf85fe70cdb34dc341c979d259afcae07840adf Mon Sep 17 00:00:00 2001 From: Dennis Rizah Nordvi Osmani Date: Wed, 14 Aug 2024 11:26:43 +0200 Subject: [PATCH] done with domain and tdd exercise --- domain-model.md | 14 ++++- tdd-domain-modelling.CSharp.Main/Basket.cs | 31 +++++++++++ .../BasketTests.cs | 53 +++++++++++++++++++ 3 files changed, 97 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..ed00e89 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,13 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `Supermarket` | `Cart(Dictionary items)` | If items in the cart | int | +| + + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `Supermarket` | `Receipt(Dictionary items)` | If items in the dictionary | String | +| | | If there are no items | "" | + diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..2c2a46e --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,31 @@ +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 + { + + private readonly Dictionary _items = new Dictionary(); + + public bool add(string product, int price) + { + if (_items.ContainsKey(product)) + { + return false; + } + + _items.Add(product, price); + return true; + + } + + public int total() + { + return _items.Values.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..9e52442 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,53 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTests +{ + [Test] + public void TestAdd() + { + Basket basket = new Basket(); + + string item = "milk"; + int value = 10; + bool added = true; + + bool result = basket.add(item, value); + + Assert.That(result == added); + } + + + [Test] + public void TestTotal() + { + Basket basket = new Basket(); + + string item1 = "makrell"; + string item2 = "leverpostei"; + string item3 = "ost"; + + int value1 = 23; + int value2 = 15; + int value3 = 117; + + int expected = 155; + + basket.add(item1, value1); + basket.add(item2, value2); + basket.add(item3, value3); + + int result = basket.total(); + + Assert.That(result == expected); + } + } +}