diff --git a/exercise1.md b/exercise1.md index 35588dd..73420c2 100644 --- a/exercise1.md +++ b/exercise1.md @@ -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 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. @@ -36,7 +44,10 @@ 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 products)` | Sum prices together | double sum| + ``` As an organised individual, So that I can evaluate my shopping habits, @@ -44,9 +55,17 @@ I'd like to see an itemised receipt that includes the name and price of the prod 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 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. \ No newline at end of file + designing a system to make our lives easier when it comes to the coding part. diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..f9c59ac --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -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 _items = new Dictionary(); + + 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 items { get { return _items; } set { _items = value; } } + + + } +} + + + + diff --git a/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs b/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs new file mode 100644 index 0000000..13261e2 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs @@ -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); + } + } + +}