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

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.

| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------|---------|
| ShopManager | totalCostItems(List<Item> basket) | Basketcontains items | int |
| | | Basket is empty | 0 |

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.


| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|---------------------------------|------------------|
| ShopManager | `getUserReceipt(List<Item> basket)` | Basket has items | List<Item> |
| | | Basket is empty | "Basket is empty"|



As a user,
So I can find a specific cohort,
I want to search a list of all cohorts by a cohort name.

| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------|---------|
| `CohortManager` | `search(List<string> cohorts, string name)` | If name is in list | true |
| | | If name is not in list | false |

As a supermarket shopper,
So that I can restock my cupboards,
I want to add products into my basket.

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.

| Classes | Members | Methods | Scenario | Outputs |
|----------|-----------------------------------------------------------------------|--------------------------------------|------------------------------------------------------------|---------|
| `Basket` | `Dictionary<string, int> items` (key is product name, value is price) | `AddItem(string product, int price)` | Item with the provided name *is not* already in the basket | true |
| | | | Item with the provided name *is* already in the basket | false |
| | | `TotalBasketCost()` | Total value of items in basket | int |




1 change: 1 addition & 0 deletions exercise2.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ I'd like to be able to know the total cost of items in my basket.
| `Basket` | `HashMap<String, int> items` (key is product name, value is price) | `add(String product, int price)` | Item with the provided name *is not* already in the basket | true |
| | | | Item with the provided name *is* already in the basket | false |
| | | `total()` | | int |

44 changes: 44 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
public class Basket
{



public Dictionary<string, int> Items { get; set; } = new Dictionary<string, int>();


public bool AddItem(string name, int value)
{
if (Items.ContainsKey(name))
{
return false;
} else
{
this.Items.Add(name, value);
return true;
}

}

public int TotalBasketCost()
{

int totalcost = 0;
foreach (var item in Items)
{
totalcost += item.Value;
}

return totalcost;
}

}
}
51 changes: 51 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Main;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
[TestFixture]
public class BasketTest
{
[TestCase("Banana", 2)]
public void AddItemTest(string product, int price)
{
//arrange
Basket basket = new Basket();

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

//assert
Assert.AreEqual(basket.Items.Count, 1);


}

[TestCase()]
public void TotalBasketCostTest()
{
//arrange
Basket basket = new Basket();


basket.AddItem("Banana", 2);
basket.AddItem("Apple", 3);
basket.AddItem("Coca cola", 6);


//act
int totalcost = basket.TotalBasketCost();

//assert
Assert.IsTrue(totalcost == 11);

}
}
}
4 changes: 2 additions & 2 deletions tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace tdd_domain_modelling.CSharp.Test
public class CohortManagerTest
{
[Test]
public void FirstTest()
public void searchCohort()
{
CohortManager core = new CohortManager();

}
}
}