Coder Social home page Coder Social logo

itfenom / ddd-tdd-rich-domain-model-dojo-kata Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ivanpaulovich/ddd-tdd-rich-domain-model-dojo-kata

0.0 0.0 0.0 269 KB

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

Home Page: https://paulovich.net

License: Apache License 2.0

C# 100.00%

ddd-tdd-rich-domain-model-dojo-kata's Introduction

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?

ddd-tdd-rich-domain-model-dojo-kata's People

Contributors

ivanpaulovich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.