diff --git a/Domain Model.PNG b/Domain Model.PNG new file mode 100644 index 0000000..c16fc6e Binary files /dev/null and b/Domain Model.PNG differ diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..11a2f81 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling.CSharp.Main +{ + + public struct Item + { + public string itemName { get; set; } + public int itemPrice { get; set; } + + public Item(string name, int price) + { + itemName = name; + itemPrice = price; + } + } + public class Basket + { + + public List Items { get; set; } + + public Basket() + { + Items = new List(); + } + + + public bool addItem(string item, int price) + { + bool result; + Item temp = new Item(item,price); + + if (Items.Contains(temp) == true) + { + result = false; + } + else + { + Items.Add(temp); + result = true; + } + + return result; + } + public int totalCost() + { + int total = 0; + + foreach (Item item in Items) + { + total += item.itemPrice; + } + + + return total; + } + + + } +} diff --git a/tdd-domain-modelling.CSharp.Main/CohortManager.cs b/tdd-domain-modelling.CSharp.Main/CohortManager.cs index 6a5669c..03db904 100644 --- a/tdd-domain-modelling.CSharp.Main/CohortManager.cs +++ b/tdd-domain-modelling.CSharp.Main/CohortManager.cs @@ -7,6 +7,13 @@ namespace tdd_domain_modelling.CSharp.Main { public class CohortManager - { + { + public bool search(List list, string name) + { + + + return list.Contains(name); + } + } } diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..f6b8c06 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,58 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTests + { + [Test] + public void FirstTest() + { + Basket basket = new Basket(); + + bool addTest = basket.addItem("Milk", 3); + + Assert.IsTrue(addTest); + } + [Test] + public void SecondTest() + { + Basket basket = new Basket(); + + basket.addItem("Milk", 3); + bool addTest = basket.addItem("Milk", 3); + + Assert.IsFalse(addTest); + + } + [Test] + public void ThirdTest() + { + Basket basket = new Basket(); + + basket.addItem("Milk", 3); + + Assert.IsTrue(basket.totalCost() == 3); + } + [Test] + public void FourthTest() + { + Basket basket = new Basket(); + basket.addItem("Milk", 3); + basket.addItem("Flour", 2); + basket.addItem("Egg", 5); + + Assert.IsTrue(basket.totalCost() == 10); + } + [Test] + public void FifthTest() + { + Basket basket = new Basket(); + basket.addItem("Milk", 3); + basket.addItem("Milk", 3); + Assert.IsTrue(basket.totalCost() == 3); + } + + } +} \ 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..facc657 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -7,9 +7,35 @@ namespace tdd_domain_modelling.CSharp.Test public class CohortManagerTest { [Test] + public void FirstTest() { CohortManager core = new CohortManager(); + + List list = new List() + { + "Jacob", + "Pia", + "Nikolaj" + }; + + bool testResult = core.search(list, "Jacob"); + Assert.IsTrue(testResult); + } + [Test] + public void SecondTest() + { + CohortManager core = new CohortManager(); + + List list = new List() + { + "Jacob", + "Pia", + "Nikolaj" + }; + + bool testResult = core.search(list, "Klaus"); + Assert.IsFalse(testResult); } } } \ No newline at end of file