We designed the Finance Domain using Aggregate Roots, Entities and Value Objects and we covered the uses cases with Unit Tests, run them in your first time here. The Domain and Unit Tests projects were implemented with .NET, the classes are as closed as possible.
π Compiling from source
Clone this repository to your machine, compile and test it:
git clone -b kata-initial https://github.com/ivanpaulovich/ddd-tdd-rich-domain-model-dojo-kata.git kata-initial
cd kata-initial
./build.sh
π· Use cases
This project was designed do cover the following use cases and requirements:
- The customer can register a new account.
- Allow to deposit into an existing account.
- Allow to withdraw from an existing account.
- Accounts can be closed only if they have zero balance.
- Accounts does not allow to withdraw more than the current account balance.
- Allow to get the account details.
- Allow to get the customer details.
π The Domain Model
π» Tech stuff
- .NET Core / Standard
- xUnit
- Moq
π½ Kata
Build a Domain from tests using DDD Building Blocks like Aggregate Roots, Entities and Value Objects with the help of kata-initial
folder files.
π½ Are expected a Model with Two Aggregates
- Account, TransactionCollection, Credit, Debit.
- Customer, AccountCollection.
- Amount, Name, SSN
π½ Create a Test Class for every object
π½ Start with the Value Objects like Name, SSN or Amount
public class NameTests
{
[Fact]
public void Empty_Name_Should_Be_Created()
{
//
// Arrange
string empty = string.Empty;
//
// Act and Assert
Assert.Throws<NameShouldNotBeEmptyException>(
() => new Name(empty));
}
[Fact]
public void Full_Name_Shoud_Be_Created()
{
//
// Arrange
string valid = "Ivan Paulovich";
//
// Act
Name name = new Name(valid);
//
// Assert
Assert.Equal(new Name(valid), name);
}
}
public sealed class Name
{
private string _text;
public Name(string text)
{
if (string.IsNullOrWhiteSpace(text))
throw new NameShouldNotBeEmptyException("The 'Name' field is required");
_text = text;
}
public override bool Equals(object obj)
{
return ((Name)obj)._text == _text;
}
}
π½ Continue to design the Model with the Customer and Account aggregates
- It is important that an Aggregate is not strongly coupled to another aggregate.
- Value Objects are immutable.
- Entities have Ids and behaviors.
- Aggregate Roots control the transaction consistency.
π½ What did your learn?
- Have you learned how to implement Value Objects?
- Were you able to identify the Aggregate Root boundaries?