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.
Clone this repository to your machine, compile and test it:
git clone https://github.com/whyseco/tdd-kata.git
cd tdd-kata
./build.sh
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.
- .NET Core / Standard
- xUnit
- Moq
Build a Domain from tests using DDD Building Blocks like Aggregate Roots, Entities and Value Objects with the help of kata-initial
folder files.
- Account, TransactionCollection, Credit, Debit.
- Customer, AccountCollection.
- Amount, Name, SSN
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;
}
}
- It is important that an Aggregate is not coupled to another aggregate.
- Value Objects are immutable.
- Entities have Ids.
- Aggregate are Entities that control the transaction consistency.