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

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.

Class Shopper

PROPERTIES:
double totalCost
double itemCost
string itemName

Dictionary<itemName, itemCost> items

METHODS:
double addCosts(totalCost, itemCost)
returns:
totalCost

List<string> createReceipt (Dictionary items, double totalCost)
return:
receipt (First index contains totalCost)
28 changes: 28 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
{
int totalCost;
public Dictionary<string, int> items = new Dictionary<string, int>();
public bool addItem(string name, int price)
{
if (items.ContainsKey(name))
{
return false;
}
items[name] = price;
totalCost += price;
return true;
}
public int total()
{
return totalCost;
}
}
}
8 changes: 8 additions & 0 deletions tdd-domain-modelling.CSharp.Main/CohortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ namespace tdd_domain_modelling.CSharp.Main
{
public class CohortManager
{
public bool search(List<String> cohorts, String name)
{
foreach(var cohort in cohorts)
{
if(cohort == name) return true;
}
return false;
}
}
}
6 changes: 5 additions & 1 deletion tdd-domain-modelling.CSharp.Main/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
//Console.WriteLine("Hello, World!");

using tdd_domain_modelling.CSharp.Main;
// "Cheese" 60, "Milk" 10, "Eggs" 30, "Potatoes" 15, "Onions" 20
Basket basket = new Basket();
43 changes: 43 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
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 BasketTest
{
[TestCase("Cheese", 60)]
[TestCase("Milk", 10)]
[TestCase("Eggs", 30)]
[TestCase("Potatoes", 15)]
[TestCase("Onions", 20)]
public void testAddToBasket(string item, int price)
{
//Setup
Basket basket = new Basket();
//Execute
basket.addItem(item, price);
//Verify, if the item in the dictionary with the provided key has the same price as the given item it has been properly added.
Assert.That(basket.items[item].Equals(price));
}
[Test]
public void testGetTotal()
{
//Setup
Basket basket = new Basket();
basket.addItem("Milk", 10);
basket.addItem("Potatoes", 15);
basket.addItem("Onions", 20);
//Execute
int total= basket.total();
//Verify
Assert.That(total.Equals(45));
}
}
}
11 changes: 9 additions & 2 deletions tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ namespace tdd_domain_modelling.CSharp.Test
[TestFixture]
public class CohortManagerTest
{
[Test]
public void FirstTest()
[TestCase("Name1", true)]
[TestCase("Name4", false)]
public void FirstTest(string name, bool expectedResult)
{
List<string> cohorts = new List<string>();
cohorts.Add("Name1");
cohorts.Add("Name2");
cohorts.Add("Name3");
CohortManager core = new CohortManager();
bool result = core.search(cohorts, name);
Assert.That(result, Is.EqualTo(expectedResult));
}
}
}