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

========================================================================
USER STORY:
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.

DOMAIN MODEL:
Classes Methods Scenario Outputs
Checkout CalculateTotalSum(List<Items> itemsScanned) Calculate total sum of items scanned on checkout float/double

=================================================================================================================================================
USER STORY:
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.

DOMAIN MODEL:
Classes Methods Scenario Outputs
Checkout Receipt(List<Items> itemsBought, List<Items> itemsScanned) Display information about bought items and items currently in basket Items (Object)

========================================================================
49 changes: 49 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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
{
private Dictionary<string, int> _items = new Dictionary<string, int>();

public Basket()
{

}

public bool Add(string product, int price)
{
// Check if item is already in basket/items hashmap
if (!_items.ContainsKey(product))
{
_items.Add(product, price);
return true;
}

return false;
}

public int Total()
{
int total = 0;

if (_items.Count == 0)
{
return total;
}

// Calculate total sum of basket/items hashmap
foreach (var item in _items) {
total += item.Value;
}

return total;
}

public Dictionary<string, int> Items { get { return _items; } }
}
}
4 changes: 4 additions & 0 deletions tdd-domain-modelling.CSharp.Main/CohortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ namespace tdd_domain_modelling.CSharp.Main
{
public class CohortManager
{
public CohortManager()
{

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

namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class BasketTests
{
[TestCase("Banana", 50)]
public void AddNewItemToBasket(string productName, int productPrice)
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
basket.Add(productName, productPrice);

// 3. Verify
Assert.IsTrue(basket.Items.ContainsKey(productName));

}

[Test]
public void TryAddingExistingItemToBasket()
{
// 1. Set up
Basket basket = new Basket();
basket.Add("Banana", 50);

// 2. Execute
bool result = basket.Add("Banana", 50);

// 3. Verify
Assert.IsFalse(result);

}

[Test]
public void CalculateCostOfItemsInBasket()
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
basket.Add("Banana", 50);
basket.Add("Pear", 40);
basket.Add("Grape", 30);

int result = basket.Total();

// 3. Verify
Assert.IsTrue(result == 120);
}
}
}