Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Domain Model.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -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<Item> Items { get; set; }

public Basket()
{
Items = new List<Item>();
}


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;
}


}
}
9 changes: 8 additions & 1 deletion tdd-domain-modelling.CSharp.Main/CohortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
namespace tdd_domain_modelling.CSharp.Main
{
public class CohortManager
{
{
public bool search(List<string> list, string name)
{


return list.Contains(name);
}

}
}
58 changes: 58 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
26 changes: 26 additions & 0 deletions tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,35 @@ namespace tdd_domain_modelling.CSharp.Test
public class CohortManagerTest
{
[Test]

public void FirstTest()
{
CohortManager core = new CohortManager();

List<string> list = new List<string>()
{
"Jacob",
"Pia",
"Nikolaj"
};

bool testResult = core.search(list, "Jacob");
Assert.IsTrue(testResult);
}
[Test]
public void SecondTest()
{
CohortManager core = new CohortManager();

List<string> list = new List<string>()
{
"Jacob",
"Pia",
"Nikolaj"
};

bool testResult = core.search(list, "Klaus");
Assert.IsFalse(testResult);
}
}
}