diff --git a/domain-model.md b/domain-model.md index 653f474..c237081 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,27 @@ -#Domain Models In Here \ No newline at end of file +# Domain Models In Here + +## User Story 1: +``` +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. +``` + +### Domain Model: +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------|--------------------------------------|---------| +| `Supermarket` | `findTotalCost(List products)` | Sum up list cost of list of products | int | + + +## User Story 2: +``` +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. +``` + +### Domain Model: +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------|-------------------------|---------------| +| `Supermarket` | `getReceipt(List products)` | Giving list of products | Console ouput | diff --git a/tdd-domain-modelling.CSharp.Main/Supermarket.cs b/tdd-domain-modelling.CSharp.Main/Supermarket.cs new file mode 100644 index 0000000..dc2ad0f --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Supermarket.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling.CSharp.Main +{ + public class Supermarket + { + private Dictionary _basket = new Dictionary(); + public Dictionary basket { get { return _basket; } } + + public bool Add(string product, int price) + { + if (basket.ContainsKey(product)) + { + return false; + } + basket.Add(product, price); + return true; + } + + public int GetTotalPrices() + { + if (basket.Count == 0) + { + return 0; + } + return basket.Values.Sum(x => x); + } + } +} diff --git a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs new file mode 100644 index 0000000..060b5cd --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs @@ -0,0 +1,57 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class SupermarketTest + { + [TestCase("Apple", 12, true)] + [TestCase("Banana", 5, true)] + [TestCase("Coffee", 8, true)] + public void TestAddNewProductInBasket(string product, int price, bool expectedBasketAddResult) + { + //Arrange + Supermarket customer = new Supermarket(); + + //Act + bool actualBasketAddResult = customer.Add(product, price); + + //Assert + Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); + } + + [TestCase("Apple", 12, false)] + [TestCase("Banana", 5, false)] + [TestCase("Coffee", 8, false)] + public void TestAddExistingProductInBasket(string product, int price, bool expectedBasketAddResult) + { + //Arrange + Supermarket customer = new Supermarket(); + customer.Add(product, price); + + //Act + bool actualBasketAddResult = customer.Add(product, price); + + //Assert + Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult)); + } + + [Test] + public void TestTotalCostOfProductsInBasket() + { + //Arrange + Supermarket customer = new Supermarket(); + customer.Add("Apple", 30); + customer.Add("Coffee", 20); + customer.Add("Cheese", 70); + int expectedTotalCost = 120; + + //Act + int actualTotalCost = customer.GetTotalPrices(); + + //Assert + Assert.That(expectedTotalCost, Is.EqualTo(actualTotalCost)); + } + } +} \ No newline at end of file