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

| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------------------------------------|---------------------------------------------------------|
| `Basket` | `Add(string name, int price)` | If item doesn't exist, add to the list of items | add item to Tuple<string name, int price, int quantity> |
| | | If item does exist, update the quantity of item item | update the quantity of similar item in Tuple |
| | `Total()` | If basket is empty, return 0 | 0 |
| | | If basket has items, calculate the cost of all items | int sum |
| `CashRegister` | `TotalCost(Basket basket)` | Calculate the summed up cost of all items in basket | int sum |


| Classes | Methods | Scenario | Outputs |
|-----------------|--------------------------------|------------------------------------------------------------------------------------------------------------|----------------|
| `Basket` | `ListItems()` | If basket is empty, return empty string | string.Empty() |
| `Basket` | | If basket has items, return string listing every item's name, price, and quantity in a receipt format | string |
| `CashRegister` | `PrintReceipt(Basket basket)` | Calls ListItems() and Total() from basket to create a string for the full receipt | string |
34 changes: 34 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_domain_modelling.CSharp.Main
{
public class Basket
{
Dictionary<string, int> items = new Dictionary<string, int>();

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

public int Total()
{
int sum = 0;
foreach (var item in items)
{
sum += item.Value;
}
return sum;
}
}
}
66 changes: 66 additions & 0 deletions tdd-domain-modelling.CSharp.Test/SupermarketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using NUnit.Framework;
using System.Diagnostics.CodeAnalysis;
using tdd_domain_modelling.CSharp.Main;

namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class SupermarketTests
{
[Test]
public void AddCupboardsTests()
{
//arrange
Basket basket = new Basket();
string name = "Cupboard";
int price = 12;
bool expected = true;

//act
bool result = basket.Add(name, price);

//assert
Assert.That(result, Is.EqualTo(expected));
}

[Test]
public void AddDuplicateCupboardsTests()
{
//arrange
Basket basket = new Basket();
string name = "Cupboard";
int price = 12;
bool expected = false;

//act
basket.Add(name, price);
bool result = basket.Add(name, price);

//assert
Assert.That(result, Is.EqualTo((bool)expected));
}

[Test]
public void TotalCostTest()
{
//arrange
Basket basket = new Basket();
string name1 = "Coffee Mug";
int price1 = 8;
string name2 = "Cupboard";
int price2 = 12;
string name3 = "Cat Food";
int price3 = 20;
int expected = 40;

//act
basket.Add(name1, price1);
basket.Add(name2, price2);
basket.Add(name3, price3);
int result = basket.Total();

//assert
Assert.That(result, Is.EqualTo(expected));
}
}
}