diff --git a/domain-model.md b/domain-model.md index 653f474..5fb105e 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,28 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +``` +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. +``` + +``` +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. +``` + +Class Item +- Properties + string name; + double price; + +Class Basket +- Properties + List items; +- Methods + double GetTotal(); + returns total cost of items in basket. + List PrintReceipt(); + returns a list of all the items in the basket, and their quantities. And the total cost. \ 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..2b6ad67 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling +{ + public class Basket +{ + public Dictionary _items; + + public Basket() + { + _items = new Dictionary(); + } + + public Boolean AddItem(string key, int value) + { + if (!_items.ContainsKey(key)){ + _items.Add(key, value); + return true; + } + return false; + } + + public int Total() + { + int total = 0; + foreach (KeyValuePair item in _items) + { + total += item.Value; + } + return total; + } +} +} diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..740e880 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,45 @@ +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTest + { + private Basket _basket; + + [SetUp] + public void Setup() + { + _basket = new Basket(); + _basket._items.Add("Milk", 2); + } + + [Test] + public void TestReturnTrueIfItemIsNotInBasket() + { + Assert.IsTrue(_basket.AddItem("Eggs", 6)); + } + + [Test] + public void TestReturnFalseIfItemIsInBasket() + { + Assert.IsFalse(_basket.AddItem("Milk", 5)); + } + + [Test] + public void TestIfItemWasAdded() + { + Assert.IsTrue(_basket._items.ContainsKey("Milk")); + } + + [Test] + public void TestTotalCostOfBasket() + { + _basket._items.Add("Eggs", 1); + Assert.AreEqual(3, _basket.Total()); + } + + } +} \ No newline at end of file