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

| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------|---------|
| `Supermarket` | `Cart(Dictionary<string, int> items)` | If items in the cart | int |
|


| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------|---------|
| `Supermarket` | `Receipt(Dictionary<string, int> items)` | If items in the dictionary | String |
| | | If there are no items | "" |

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

public bool add(string product, int price)
{
if (_items.ContainsKey(product))
{
return false;
}

_items.Add(product, price);
return true;

}

public int total()
{
return _items.Values.Sum();
}
}
}
53 changes: 53 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using NUnit.Framework;
using System;
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 BasketTests
{
[Test]
public void TestAdd()
{
Basket basket = new Basket();

string item = "milk";
int value = 10;
bool added = true;

bool result = basket.add(item, value);

Assert.That(result == added);
}


[Test]
public void TestTotal()
{
Basket basket = new Basket();

string item1 = "makrell";
string item2 = "leverpostei";
string item3 = "ost";

int value1 = 23;
int value2 = 15;
int value3 = 117;

int expected = 155;

basket.add(item1, value1);
basket.add(item2, value2);
basket.add(item3, value3);

int result = basket.total();

Assert.That(result == expected);
}
}
}