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
6 changes: 5 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#Domain Models In Here
#Domain Models In Here
| Classes | Methods | Scenario | Outputs |
|-----------------|-----------------------|----------------------------|----------|
| `Cart` | `total()` | Return total value of cart | double |
| | `receipt()` | Return detailed receipt | string |
35 changes: 35 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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, int> _prices = new Dictionary<string, int>();
private List<string> _items = new List<string>();

public List<string> Items { get { return _items; } }
public Boolean Add(string product, int price)
{
if (!_items.Contains(product))
{
_items.Add(product);
_prices.Add(product, price);
return true;
}
else
{
{ _items.Add(product); return false; }
}

}

public int Total()
{
return _items.Select(p => _prices[p]).ToArray().Sum();
}
}
}
88 changes: 88 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;
using System.Xml.Linq;

namespace tdd_domain_modelling.CSharp.Test
{
public class BasketTest
{
[Test]
public void ShouldNotBeEmpty()
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
basket.Add("Milk", 5);

// 3. Verify
Assert.That(basket.Items.Count > 0);
}

[Test]
public void ShouldReturnTrue()
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
Boolean added = basket.Add("Milk", 5);

// 3. Verify
Assert.That(added);
}

[Test]
public void ShouldReturnFalse()
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
basket.Add("Milk", 5);
Boolean added = basket.Add("Milk", 5);

// 3. Verify
Assert.That(!added);
}

[Test]
public void ShouldReturnTotal()
{
// 1. Set up
Basket basket = new Basket();

// 2. Execute
basket.Add("Milk", 5);
basket.Add("Sugar", 7);
basket.Add("Egg", 4);

// 3. Verify
Assert.That(basket.Total() == 16);
}
[Test]
public void ShouldReturnTotalDuplicate()
{
// 1. Set up
Basket basket = new Basket();

// 2.
basket.Add("Sugar", 7);
basket.Add("Milk", 5);
basket.Add("Milk", 5);
basket.Add("Sugar", 7);
basket.Add("Egg", 4);

// 3. Verify
Assert.That(basket.Total() == 28);
}

}
}