diff --git a/domain-model.md b/domain-model.md index 653f474..9bc4888 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,19 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +Class Item + + - string itemName + - double price + + +class Basket + + PROPERTIES + - public List items; + + + METHODS + - public bool addItemsToBasket(string itemName, double price) + - public double totalCosts + - List printReceipt string, prints each itemName, price and quantity of item & total price + \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..4472136 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,40 @@ +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 items = new Dictionary(); + + public Basket() + { + + } + + public bool addItemsToBasket(string itemName, double price) + { + // if itemName is not in items Dicionary, add itemName and Price to items Dicionary + if (!items.ContainsKey(itemName)) + { + items.Add(itemName, price); + return true; + } + return false; + } + + + public double TotalCostsBasket() + { + double totalCosts = 0; + foreach (var item in items) + { + totalCosts += item.Value; + } + return totalCosts; + } + } +} diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..77445a6 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTests + { + private Basket _basket; + [SetUp] + + public void Setup() + { + // creates new basket for each test. + _basket = new Basket(); + _basket.addItemsToBasket("Eggs", 1.5d); + _basket.addItemsToBasket("Butter", 1.0d); + _basket.addItemsToBasket("Tomatoes", 2.5d); + } + + + [Test] + public void AddItemsToBasket() + { + // execute add items to basket + bool addedItems = _basket.addItemsToBasket("Milk", 2d); + + // check if added items ("Eggs, 1.5d) is in basket -> is true. + Assert.That(addedItems, Is.True); + } + + [Test] + public void TestTotalCostsBasket() + { + double totalCosts = _basket.TotalCostsBasket(); + + Assert.That(totalCosts, Is.EqualTo(5)); + } + } +} \ No newline at end of file