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
34 changes: 33 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
#Domain Models In Here
<span style="font-size:0.5em;">Story</span>
<br />
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.


<span style="font-size:0.5em;">Model</span>
<br />
| Classes | Methods | Scenario | Outputs |
|-----------------|-----------------------------------------------------------------------------------------|-------------------------------|---------------------------|
| `SuperMarket` | `itemInBasket(string itemName, decimal itemPrice, Dictionary<string,int> receipt)` | Item is in not in the basket | true |
| | | | |
| | `itemInBasket(Dictionary<string,int> receipt)` | Item is not in the basket | false |
| | | | |
| | `putItemInBasket(Dictionary<string,int> receipt, bool isItemInBasket)` | | |
| | | | |
| | `costCalculate(Dictionary<string,int> receipt)` | | Total cost (int total) |
| | | | |
<br />
<span style="font-size:0.5em;">Story</span>
<br />
As an organized individual,
So that I can evaluate my shopping habits,
I'd like to see an itemized receipt that includes the name and price of the products
I bought as well as the quantity, and a total cost of my basket.

<span style="font-size:0.5em;">Model</span>
<br />
| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------------------|---------------------------------------------------------|---------------------------|
| `SuperMarket` | `showReceipt(Dictionary<string,int> receipt, int total)`| Print items with their costs, and total cost at the end | Printed receipt on console|
| | | | |
35 changes: 35 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@


namespace tdd_domain_modelling.CSharp.Test
{
public class Basket
{
private Dictionary<string, decimal> _items = new Dictionary<string, decimal>();
private decimal _total = 0;


public bool Add(string item, decimal price)
{
if (_items.ContainsKey(item))
{

return false;
}
else
{
_items.Add(item, price);
return true;
}
}

public decimal Total()
{
foreach (int value in _items.Values)
{
_total += value;
}

return _total;
}
}
}
44 changes: 44 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;


namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class BasketTests
{
[TestCase("Bread", 0.99, true)]
[TestCase("Kinder Surprise", 0.99, false)]
public void TestAdd(string item, decimal price, bool isItemPresent)
{
//arrange
Basket basket = new Basket();

basket.Add("Apple 100g", 2.49m);
basket.Add("Carrot 100g", 1.99m);
basket.Add("Kinder Surprise", 0.99m);


//act
bool result1 = basket.Add(item, price);

//assert
Assert.AreEqual(isItemPresent, result1);

}
[TestCase(9)]
public void TestTotal(decimal expected)
{
//arrange
Basket basket = new Basket();
basket.Add("Apple 100g", 2);
basket.Add("Carrot 100g", 3);
basket.Add("Kinder Surprise", 4);
//act
decimal result = basket.Total();

//assert
Assert.IsTrue(result == expected);
}
}
}
2 changes: 2 additions & 0 deletions tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class CohortManagerTest
public void FirstTest()
{
CohortManager core = new CohortManager();


}
}
}