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
25 changes: 22 additions & 3 deletions exercise1.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ Here is how one might design a domain model for the above user story:
> **Time to analyse**
>
> Evaluate the user story and the domain model above. What assumptions did the developer have to make and what would you do differently?
> The List in Methods could have been concisting of Objects instead of string. The output is of boolean value.
> The user could have wanted the whoule course if it was a object with other attributes.
> Name of class could be different. You would not necessary have to pass the list of cohorts as well as the string.
>
> Create your own domain model for the user story above, try to come up with a different solution than the model provided. You can use a table like the one above, a spreadsheet, pen and paper, whatever you'd like. Share your work in your cohorts classroom channel when you're done.

>
>
| Classes | Methods | Scenario | Outputs |
|-----------------|---------------------------------------------|------------------------|---------|
| `CohortManager` | `find(List<Cohort> cohorts, String name) `| If name is in list |Cohort c |
| | | If name is not in list |Exception|
### Exercise

Follow the same process as above to translate these two user stories into domain models.
Expand All @@ -36,17 +44,28 @@ 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 |
|-----------------|---------------------------------------------|------------------------|--------- |
| `Supermarket ` | `double Sum(List<double> products)` | Sum prices together | double sum|

```
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 | Members |Methods | Scenario | Outputs |
|-----------------|----------------------|-------------------------|------------------------|------------|
|`Product` | `string code, double price, int quantity`| | | |
|`Reciept` |`List<Product> prods` |`double SumOfProducts() `|Add prods.price * prods.quantity | return sum |




- Add your domain models as images to the project, or in the `domain-model.md` file.

- Your model doesn't have to look like the example provided in this file. If you
feel like you need more or less columns, feel free to go with that.
There is no "right way" to do this kind of thing, we're just
designing a system to make our lives easier when it comes to the coding part.
designing a system to make our lives easier when it comes to the coding part.
38 changes: 38 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace td_domain_modelling.CSharp.Main
{
public class Basket
{
private Dictionary<string, int> _items = new Dictionary<string, int>();

public Basket()
{

}

public bool Add(string product, int price)
{
_items.Add(product, price);

return _items.Count > 0 ? true : false;
}

public int Total()
{
return _items.Values.Sum();
}

public Dictionary<string, int> items { get { return _items; } set { _items = value; } }


}
}




38 changes: 38 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketClassTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using NUnit.Framework;
using td_domain_modelling.CSharp.Main;

namespace tdd_domain_modelling.CSharp.Test
{
public class BasketClassTests
{
[Test]
public void shouldAddProductToBasket()
{
// Setup
Basket b = new Basket();

// Execute
bool added = b.Add("Coca cola", 22);

// Verify
Assert.That(added, Is.True);
Assert.That(b.items != null, Is.True);
}

[Test]
public void shouldReturnPriceForProductsInBasket()
{
// Setup
Basket b = new Basket();
b.Add("Coca cola", 22);
b.Add("Urge", 22);

//Execute
int sum = b.Total();

// Verify
Assert.That(sum == 44);
}
}

}