Rich Domain with DDD patterns and TDD (.NET Core / Standard)
Switch branches/tags
Clone or download
Latest commit 7effc59 Sep 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build build Aug 14, 2018
docs docs Jul 23, 2018
src/Finance.Domain Refactoring Sep 1, 2018
test/Finance.Domain.Tests Unit Tests added Sep 9, 2018
.gitattributes language Aug 14, 2018
.gitignore Refactoring Jun 17, 2018
Finance.sln Coverage Jun 17, 2018
LICENSE Initial commit Jun 16, 2018
README.md docs Sep 4, 2018
appveyor.yml Coverage Jun 17, 2018
codecov.sh Coverage Jun 17, 2018
coverage.xml Coverage Jun 17, 2018

README.md

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?