shamresh / ddd-tdd-rich-domain-model-dojo-kata

Rich Domain with DDD patterns and TDD (.NET Core / Standard)

Home Page:https://paulovich.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small .NET Standard solution with DDD Building Blocks covered with Unit Tests Build status codecov

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:

  1. The customer can register a new account.
  2. Allow to deposit into an existing account.
  3. Allow to withdraw from an existing account.
  4. Accounts can be closed only if they have zero balance.
  5. Accounts does not allow to withdraw more than the current account balance.
  6. Allow to get the account details.
  7. Allow to get the customer details.

πŸ“ The Domain Model

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?

About

Rich Domain with DDD patterns and TDD (.NET Core / Standard)

https://paulovich.net

License:Apache License 2.0


Languages

Language:C# 100.0%