diff --git a/domain-model.md b/domain-model.md index 653f474..4e361a9 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,26 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here +EXERCISE 1: +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. + +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. + +Class Shopper + +PROPERTIES: +double totalCost +double itemCost +string itemName + +Dictionary items + +METHODS: +double addCosts(totalCost, itemCost) +returns: +totalCost + +List createReceipt (Dictionary items, double totalCost) +return: +receipt (First index contains totalCost) \ 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..2a8a9e5 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,28 @@ +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 + { + int totalCost; + public Dictionary items = new Dictionary(); + public bool addItem(string name, int price) + { + if (items.ContainsKey(name)) + { + return false; + } + items[name] = price; + totalCost += price; + return true; + } + public int total() + { + return totalCost; + } + } +} diff --git a/tdd-domain-modelling.CSharp.Main/CohortManager.cs b/tdd-domain-modelling.CSharp.Main/CohortManager.cs index 6a5669c..4b4b529 100644 --- a/tdd-domain-modelling.CSharp.Main/CohortManager.cs +++ b/tdd-domain-modelling.CSharp.Main/CohortManager.cs @@ -8,5 +8,13 @@ namespace tdd_domain_modelling.CSharp.Main { public class CohortManager { + public bool search(List cohorts, String name) + { + foreach(var cohort in cohorts) + { + if(cohort == name) return true; + } + return false; + } } } diff --git a/tdd-domain-modelling.CSharp.Main/Program.cs b/tdd-domain-modelling.CSharp.Main/Program.cs index 3751555..ecbb05a 100644 --- a/tdd-domain-modelling.CSharp.Main/Program.cs +++ b/tdd-domain-modelling.CSharp.Main/Program.cs @@ -1,2 +1,6 @@ // See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +//Console.WriteLine("Hello, World!"); + +using tdd_domain_modelling.CSharp.Main; +// "Cheese" 60, "Milk" 10, "Eggs" 30, "Potatoes" 15, "Onions" 20 +Basket basket = new Basket(); \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/BasketTest.cs b/tdd-domain-modelling.CSharp.Test/BasketTest.cs new file mode 100644 index 0000000..e58b564 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTest.cs @@ -0,0 +1,43 @@ +using NUnit.Framework; +using System; +using System.Collections; +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 BasketTest + { + [TestCase("Cheese", 60)] + [TestCase("Milk", 10)] + [TestCase("Eggs", 30)] + [TestCase("Potatoes", 15)] + [TestCase("Onions", 20)] + public void testAddToBasket(string item, int price) + { + //Setup + Basket basket = new Basket(); + //Execute + basket.addItem(item, price); + //Verify, if the item in the dictionary with the provided key has the same price as the given item it has been properly added. + Assert.That(basket.items[item].Equals(price)); + } + [Test] + public void testGetTotal() + { + //Setup + Basket basket = new Basket(); + basket.addItem("Milk", 10); + basket.addItem("Potatoes", 15); + basket.addItem("Onions", 20); + //Execute + int total= basket.total(); + //Verify + Assert.That(total.Equals(45)); + } + } +} diff --git a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs index 56f3873..3cc66e1 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -6,10 +6,17 @@ namespace tdd_domain_modelling.CSharp.Test [TestFixture] public class CohortManagerTest { - [Test] - public void FirstTest() + [TestCase("Name1", true)] + [TestCase("Name4", false)] + public void FirstTest(string name, bool expectedResult) { + List cohorts = new List(); + cohorts.Add("Name1"); + cohorts.Add("Name2"); + cohorts.Add("Name3"); CohortManager core = new CohortManager(); + bool result = core.search(cohorts, name); + Assert.That(result, Is.EqualTo(expectedResult)); } } } \ No newline at end of file