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

## User Story 1:
```
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 |
|-----------------|-----------------------------------------|--------------------------------------|---------|
| `Supermarket` | `findTotalCost(List<Product> products)` | Sum up list cost of list of products | int |


## User Story 2:
```
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 |
|-----------------|-----------------------------------------|-------------------------|---------------|
| `Supermarket` | `getReceipt(List<Product> products)` | Giving list of products | Console ouput |
33 changes: 33 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Supermarket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_domain_modelling.CSharp.Main
{
public class Supermarket
{
private Dictionary<string, int> _basket = new Dictionary<string, int>();
public Dictionary<string, int> basket { get { return _basket; } }

public bool Add(string product, int price)
{
if (basket.ContainsKey(product))
{
return false;
}
basket.Add(product, price);
return true;
}

public int GetTotalPrices()
{
if (basket.Count == 0)
{
return 0;
}
return basket.Values.Sum(x => x);
}
}
}
57 changes: 57 additions & 0 deletions tdd-domain-modelling.CSharp.Test/SupermarketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;

namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class SupermarketTest
{
[TestCase("Apple", 12, true)]
[TestCase("Banana", 5, true)]
[TestCase("Coffee", 8, true)]
public void TestAddNewProductInBasket(string product, int price, bool expectedBasketAddResult)
{
//Arrange
Supermarket customer = new Supermarket();

//Act
bool actualBasketAddResult = customer.Add(product, price);

//Assert
Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult));
}

[TestCase("Apple", 12, false)]
[TestCase("Banana", 5, false)]
[TestCase("Coffee", 8, false)]
public void TestAddExistingProductInBasket(string product, int price, bool expectedBasketAddResult)
{
//Arrange
Supermarket customer = new Supermarket();
customer.Add(product, price);

//Act
bool actualBasketAddResult = customer.Add(product, price);

//Assert
Assert.That(expectedBasketAddResult, Is.EqualTo(actualBasketAddResult));
}

[Test]
public void TestTotalCostOfProductsInBasket()
{
//Arrange
Supermarket customer = new Supermarket();
customer.Add("Apple", 30);
customer.Add("Coffee", 20);
customer.Add("Cheese", 70);
int expectedTotalCost = 120;

//Act
int actualTotalCost = customer.GetTotalPrices();

//Assert
Assert.That(expectedTotalCost, Is.EqualTo(actualTotalCost));
}
}
}