Consider an added benefit of using Event Sourcing as we create unit tests. We can easily specify our tests in the form Given-When-Expect, as follows:
1. Given Events in the past
2. When Aggregate method is called
3. Expect the following Events or an exception
Here’s how it works. Past Events are used to set up the state of an Aggregate at the beginning of the unit test. We then execute the Aggregate method being tested, supplying test arguments and mock implementations of Domain Services as needed. Finally, we assert the expected results by comparing Events produced by an Aggregate with expected Events.
This approach allows us to capture and verify behaviors associated with each Aggregate. At the same time, we ...