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
29 changes: 28 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
#Domain Models In Here
#Domain Models In Here

```
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.
```

```
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 Item
- Properties
string name;
double price;

Class Basket
- Properties
List<Item> items;
- Methods
double GetTotal();
returns total cost of items in basket.
List<string> PrintReceipt();
returns a list of all the items in the basket, and their quantities. And the total cost.
37 changes: 37 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_domain_modelling
{
public class Basket
{
public Dictionary<string, int> _items;

public Basket()
{
_items = new Dictionary<string, int>();
}

public Boolean AddItem(string key, int value)
{
if (!_items.ContainsKey(key)){
_items.Add(key, value);
return true;
}
return false;
}

public int Total()
{
int total = 0;
foreach (KeyValuePair<string, int> item in _items)
{
total += item.Value;
}
return total;
}
}
}
45 changes: 45 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;

namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class BasketTest
{
private Basket _basket;

[SetUp]
public void Setup()
{
_basket = new Basket();
_basket._items.Add("Milk", 2);
}

[Test]
public void TestReturnTrueIfItemIsNotInBasket()
{
Assert.IsTrue(_basket.AddItem("Eggs", 6));
}

[Test]
public void TestReturnFalseIfItemIsInBasket()
{
Assert.IsFalse(_basket.AddItem("Milk", 5));
}

[Test]
public void TestIfItemWasAdded()
{
Assert.IsTrue(_basket._items.ContainsKey("Milk"));
}

[Test]
public void TestTotalCostOfBasket()
{
_basket._items.Add("Eggs", 1);
Assert.AreEqual(3, _basket.Total());
}

}
}