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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# Mono auto generated files
mono_crash.*

# Jetbrains Project Files
.idea/

# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
Binary file added csharp-tdd-oop-bobs-bagels.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions csharp-tdd-oop-bobs-bagels.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions domain_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Core ##
| Methods/Properties | Scenario | Outputs |
|-----------------------------------------------------|---------------------------------------------------------------------------|--------------------------------------------------------------|
| Basket.AddBagel(Bagel bagel) | add specific type of bagel, should notify when full | A notification if full |
| Basket.RemoveBagel(Bagel bagel) | remove a bagel from the basket, should notify if the bagel does not exist | A notification if bagel does not exist |
| Basket.AdjustCapacity(int capacity) | change the capacity of the basket | None |
| Basket.GetTotalCost() | get the total cost of all bagels in the basket | The total cost of all bagels in the basket |
| Bagel.SetFilling(BagelFilling filling) | change filling of the bagel | None |
| BagelFilling.GetCost() | get the cost of the filling | The cost of the filling |

8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/Bacon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class Bacon : BagelFilling
{
public override string Name() => "Bacon";
public override string Abbreviation() => "FILB";
public override decimal Cost() => new(0.12);
}
9 changes: 9 additions & 0 deletions exercise.main/BagelFillings/BagelFilling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace exercise.main.BagelFillings;

public abstract class BagelFilling
{
public string Type => "Filling";
public abstract string Name();
public abstract string Abbreviation();
public abstract decimal Cost();
}
8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/Cheese.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class Cheese : BagelFilling
{
public override string Name() => "Cheese";
public override string Abbreviation() => "FILC";
public override decimal Cost() => new(0.12);
}
8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/CreamCheese.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class CreamCheese : BagelFilling
{
public override string Name() => "CreamCheese";
public override string Abbreviation() => "FILX";
public override decimal Cost() => new(0.12);
}
8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/Egg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class Egg : BagelFilling
{
public override string Name() => "Egg";
public override string Abbreviation() => "FILE";
public override decimal Cost() => new(0.12);
}
8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/Ham.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class Ham : BagelFilling
{
public override string Name() => "Ham";
public override string Abbreviation() => "FILH";
public override decimal Cost() => new(0.12);
}
8 changes: 8 additions & 0 deletions exercise.main/BagelFillings/SmokedSalmon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace exercise.main.BagelFillings;

public class SmokedSalmon : BagelFilling
{
public override string Name() => "SmokedSalmon";
public override string Abbreviation() => "FILS";
public override decimal Cost() => new(0.12);
}
30 changes: 30 additions & 0 deletions exercise.main/Bagels/Bagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using exercise.main.BagelFillings;

namespace exercise.main.Bagels;

public abstract class Bagel
{
public static string Type => "Bagel";
public BagelFilling Filling => bagelFilling;
public abstract string Name();
public abstract string Abbreviation();

protected BagelFilling bagelFilling;
protected decimal cost;

protected Bagel(BagelFilling bagelFilling, decimal cost)
{
this.bagelFilling = bagelFilling;
this.cost = cost;
}

public void SetFilling(BagelFilling filling)
{
bagelFilling = filling;
}

public decimal GetTotalCost()
{
return cost + Filling.Cost();
}
}
13 changes: 13 additions & 0 deletions exercise.main/Bagels/EverythingBagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using exercise.main.BagelFillings;

namespace exercise.main.Bagels;

public class EverythingBagel : Bagel
{
public override string Name() => "Everything";
public override string Abbreviation() => "BGLP";

public EverythingBagel(BagelFilling bagelFilling) : base(bagelFilling, new decimal(0.49))
{
}
}
13 changes: 13 additions & 0 deletions exercise.main/Bagels/OnionBagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using exercise.main.BagelFillings;

namespace exercise.main.Bagels;

public class OnionBagel : Bagel
{
public override string Name() => "Plain";
public override string Abbreviation() => "BGLP";

public OnionBagel(BagelFilling bagelFilling) : base(bagelFilling, new decimal(0.49))
{
}
}
13 changes: 13 additions & 0 deletions exercise.main/Bagels/PlainBagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using exercise.main.BagelFillings;

namespace exercise.main.Bagels;

public class PlainBagel : Bagel
{
public override string Name() => "Plain";
public override string Abbreviation() => "BGLP";

public PlainBagel(BagelFilling bagelFilling) : base(bagelFilling, new decimal(0.39))
{
}
}
13 changes: 13 additions & 0 deletions exercise.main/Bagels/SesameBagel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using exercise.main.BagelFillings;

namespace exercise.main.Bagels;

public class SesameBagel : Bagel
{
public override string Name() => "Sesame";
public override string Abbreviation() => "BGLP";

public SesameBagel(BagelFilling bagelFilling) : base(bagelFilling, new decimal(0.49))
{
}
}
53 changes: 53 additions & 0 deletions exercise.main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using exercise.main.BagelFillings;
using exercise.main.Bagels;

namespace exercise.main;

public class Basket
{
public int Count => _contents.Count;

private readonly List<Bagel> _contents = new();
private int _maxCapacity;

public Basket(int maxCapacity)
{
_maxCapacity = maxCapacity;
}

public void AddBagel(Bagel bagel)
{
if (_contents.Count < _maxCapacity)
{
_contents.Add(bagel);
}
else
{
Console.WriteLine("Basket is at max capacity!");
}
}

public void RemoveBagel(Bagel bagel)
{
if (!_contents.Remove(bagel))
{
Console.WriteLine("Could not find bagel to remove!");
}
}

public void AdjustCapacity(int capacity)
{
_maxCapacity = capacity;
}

public decimal GetTotalCost()
{
decimal cost = 0;
foreach (var bagel in _contents)
{
cost += bagel.GetTotalCost();
}

return cost;
}
}
3 changes: 3 additions & 0 deletions exercise.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
extension3.md = extension3.md
extension4.md = extension4.md
README.md = README.md
domain_model.md = domain_model.md
csharp-tdd-oop-bobs-bagels.drawio.png = csharp-tdd-oop-bobs-bagels.drawio.png
csharp-tdd-oop-bobs-bagels.drawio.svg = csharp-tdd-oop-bobs-bagels.drawio.svg
EndProjectSection
EndProject
Global
Expand Down
38 changes: 38 additions & 0 deletions exercise.tests/BagelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Diagnostics;
using exercise.main.BagelFillings;
using exercise.main.Bagels;

namespace exercise.tests;

public class Tests
{
[Test]
public void SetFillingTest()
{
// Arrange
BagelFilling expected = new Cheese();
Bagel bagel = new EverythingBagel(new Bacon());

// Act
bagel.SetFilling(expected);

// Assert
Debug.Assert(bagel.Filling == expected);
}

[Test]
public void GetTotalCostTest()
{
// Arrange
BagelFilling filling = new Cheese();
Bagel bagel = new EverythingBagel(filling);

const decimal EXPECTED_TOTAL = (decimal)0.61;

// Act
decimal totalCost = bagel.GetTotalCost();

// Assert
Debug.Assert(totalCost == EXPECTED_TOTAL);
}
}
83 changes: 83 additions & 0 deletions exercise.tests/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Diagnostics;
using exercise.main;
using exercise.main.BagelFillings;
using exercise.main.Bagels;

namespace exercise.tests;

public class BasketTests
{
[Test]
public void AddBagelTest()
{
// Arrange
Basket basket = new Basket(1);
Bagel bagel = new EverythingBagel(new Cheese());


// Act
basket.AddBagel(bagel);
basket.AddBagel(bagel);

// Assert
Debug.Assert(basket.Count == 1);
}

[Test]
public void RemoveBagelTest()
{
// Arrange
Basket basket = new Basket(2);
Bagel bagel = new EverythingBagel(new Cheese());

basket.AddBagel(bagel);

// Act
basket.RemoveBagel(bagel);
basket.RemoveBagel(bagel);

// Assert
Debug.Assert(basket.Count == 0);
}

[Test]
public void AdjustCapacityTest()
{
// Arrange
Basket basket = new Basket(0);
Bagel bagel = new EverythingBagel(new Cheese());

basket.AddBagel(bagel);

// Act
basket.AdjustCapacity(1);
basket.AddBagel(bagel);

// Assert
Debug.Assert(basket.Count == 1);
}

[Test]
public void GetTotalCostTest()
{
// Arrange
Basket basket = new Basket(3);
Bagel bagel1 = new EverythingBagel(new Cheese());
Bagel bagel2 = new OnionBagel(new CreamCheese());
Bagel bagel3 = new SesameBagel(new Egg());

basket.AddBagel(bagel1);
basket.AddBagel(bagel2);
basket.AddBagel(bagel3);

const decimal EXPECTED_TOTAL = (decimal)1.83;

// Act
decimal totalCost = basket.GetTotalCost();

// Assert
Debug.Assert(totalCost == EXPECTED_TOTAL);
}


}
15 changes: 0 additions & 15 deletions exercise.tests/UnitTest1.cs

This file was deleted.

Loading