I am using GivenWhenThenTestFixture with AbstractAnnotatedAggregateRoot successfully for most cases.
One Aggregate changes per one Command (one Transaction) - I am following DDD principles.
There are some cases, when to handle one Command, I need two Aggregates to act with eachother.
Consider following example:
One Aggregate (A1) is being changed (produces events).
Another (A2) is used as a Factory for some Policies that are used as closures to A1 method (and based on that, A1 generates some additional Events). But A2’s state is not being changed!
In Command Handler, there are two Repositories - one for A1 and another for A2.
Now I want to test that Command.
What I can do now is to setup a fixture for A1, and inject a mocked repository for A2 with an instance of A2 prepared manually (by invoking methods on object).
This may be ok, but involves using mocks in domain test (which I don’t consider as a good practice), or using read side (which is even worse, since invariants should be in the model on the write side, because it is consistent).
It also mixes given-when-then approach based on events with manual Aggregate manipulation.
What I would like to have is to specify “given” events for A1 and “given” events for A2, and then send my Command as “when” and then as “then” specify expected events for A1 and expect A2 not to change at all.
Something similar to fixture for sagas.
Do you have any suggestions?