diff --git a/domain-model.md b/domain-model.md index 653f474..f30fc60 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,33 @@ -#Domain Models In Here \ No newline at end of file +Story +
+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. + + +Model +
+| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------------------------------------------------------|-------------------------------|---------------------------| +| `SuperMarket` | `itemInBasket(string itemName, decimal itemPrice, Dictionary receipt)` | Item is in not in the basket | true | +| | | | | +| | `itemInBasket(Dictionary receipt)` | Item is not in the basket | false | +| | | | | +| | `putItemInBasket(Dictionary receipt, bool isItemInBasket)` | | | +| | | | | +| | `costCalculate(Dictionary receipt)` | | Total cost (int total) | +| | | | | +
+Story +
+As an organized individual, +So that I can evaluate my shopping habits, +I'd like to see an itemized receipt that includes the name and price of the products +I bought as well as the quantity, and a total cost of my basket. + +Model +
+| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------------------|---------------------------------------------------------|---------------------------| +| `SuperMarket` | `showReceipt(Dictionary receipt, int total)`| Print items with their costs, and total cost at the end | Printed receipt on console| +| | | | | \ 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..fc56b2c --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,35 @@ + + +namespace tdd_domain_modelling.CSharp.Test +{ + public class Basket + { + private Dictionary _items = new Dictionary(); + private decimal _total = 0; + + + public bool Add(string item, decimal price) + { + if (_items.ContainsKey(item)) + { + + return false; + } + else + { + _items.Add(item, price); + return true; + } + } + + public decimal Total() + { + foreach (int value in _items.Values) + { + _total += value; + } + + return _total; + } + } +} \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..214dfa5 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTests + { + [TestCase("Bread", 0.99, true)] + [TestCase("Kinder Surprise", 0.99, false)] + public void TestAdd(string item, decimal price, bool isItemPresent) + { + //arrange + Basket basket = new Basket(); + + basket.Add("Apple 100g", 2.49m); + basket.Add("Carrot 100g", 1.99m); + basket.Add("Kinder Surprise", 0.99m); + + + //act + bool result1 = basket.Add(item, price); + + //assert + Assert.AreEqual(isItemPresent, result1); + + } + [TestCase(9)] + public void TestTotal(decimal expected) + { + //arrange + Basket basket = new Basket(); + basket.Add("Apple 100g", 2); + basket.Add("Carrot 100g", 3); + basket.Add("Kinder Surprise", 4); + //act + decimal result = basket.Total(); + + //assert + Assert.IsTrue(result == expected); + } + } +} \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs index 56f3873..7b324a0 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -10,6 +10,8 @@ public class CohortManagerTest public void FirstTest() { CohortManager core = new CohortManager(); + + } } } \ No newline at end of file