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

Class Item

- string itemName
- double price


class Basket

PROPERTIES
- public List<item> items;


METHODS
- public bool addItemsToBasket(string itemName, double price)
- public double totalCosts
- List printReceipt string, prints each itemName, price and quantity of item & total price

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

public Basket()
{

}

public bool addItemsToBasket(string itemName, double price)
{
// if itemName is not in items Dicionary, add itemName and Price to items Dicionary
if (!items.ContainsKey(itemName))
{
items.Add(itemName, price);
return true;
}
return false;
}


public double TotalCostsBasket()
{
double totalCosts = 0;
foreach (var item in items)
{
totalCosts += item.Value;
}
return totalCosts;
}
}
}
40 changes: 40 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;

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

public void Setup()
{
// creates new basket for each test.
_basket = new Basket();
_basket.addItemsToBasket("Eggs", 1.5d);
_basket.addItemsToBasket("Butter", 1.0d);
_basket.addItemsToBasket("Tomatoes", 2.5d);
}


[Test]
public void AddItemsToBasket()
{
// execute add items to basket
bool addedItems = _basket.addItemsToBasket("Milk", 2d);

// check if added items ("Eggs, 1.5d) is in basket -> is true.
Assert.That(addedItems, Is.True);
}

[Test]
public void TestTotalCostsBasket()
{
double totalCosts = _basket.TotalCostsBasket();

Assert.That(totalCosts, Is.EqualTo(5));
}
}
}