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
37 changes: 36 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
#Domain Models In Here
```
As a user,
So I can find a specific cohort,
I want to search a list of all cohorts by a cohort name.
```


Class: CohortManager
Method: FindCohort(string name)
Scenario: name is a substring of cohort name. Return: list of cohort names that name is a substing of
Scenario: name is not a substring of any cohort. Return: Empty list

```
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.
```

Class: ShoppingCart. Method: double CalculateTotal()
Class: Item. Method: double GetPrice()
Scenario: There are a number of items in the cartList. Out: CalculateTotal()

```
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.
```

Class: Checkout. Method: GetReceipt()
Class: Item. Method: GetName()
Class: Shopper. Method: AddReceit(receit). Method: GetReceits()
Scenario: The shopper buys something. Void: Shopper.AddReceit(Checkout.GetReceit())
Scenario: The shopper wants to look at their reciets. Out: Shopper.GetReceits()


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
{
private Dictionary<string,double> _items;

public Basket()
{
_items = new Dictionary<string,double>();
}

public void Add(string product, double price)
{
if (_items.ContainsKey(product))
{
_items[product] += price;
}
else
{
_items.Add(product, price);
}
}

public bool Contains(string product)
{
return _items.ContainsKey(product);
}

public double Sum()
{
return _items.Values.Sum();
}
}
}
47 changes: 47 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using tdd_domain_modelling.CSharp.Main;

namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class BasketTests
{
[Test]
public void BasketAddItem()
{
//arrange
Basket basket = new Basket();
string product = "Deodorant";
int price = 100;

//act
basket.Add(product, price);

//assert
Assert.That(basket.Contains(product), Is.True);

}

[Test]
public void BasketSumItems()
{
//arrange
Basket basket = new Basket();
basket.Add("Deodorant", 100);
basket.Add("Deodorant", 100);
basket.Add("Cat", 50.50);

//act
double sum = basket.Sum();

//assert
Assert.That(sum, Is.EqualTo(250.50));
}
}
}