Saga testing problem

I’m having some trouble testing a saga and thought that I might get some hints…

It looks like this:

AggregateA -> AEvent
-> Saga starts, associationProperty =
-> Saga sends a list of CreateB commands, for each command it stores (which is generated in the saga, a random string) in a list so that it can later know if all new B’s are created.

AggregateB -> BCreatedEvent
-> Saga handles the event and removes from the list of ids it is waiting for.
-> Saga publishes AllBCreatedEvent if there are no more ids in the list
-> Saga ends if there are no more ids in the list

Now to my problem. The test does not know which ids are generated in the saga when it dispatches CreateB commands, so I can’t check that the right commands are dispatched and I can’t generate the events that the saga should react to to end itself.

Hi Per,

random is a hard thing to predict ;-). In one of my client’s applications, randomness is one of the most important aspects. It’s a card game application, where cards needed to be shuffled.
In that application, we abstracted the random algorithm, so that we could use a different strategy. In production, the random strategy would always be used. However, in tests, we needed a more predictable strategy, so we injected an implementation that would provide hard-coded values when asked for one.

Hope this helps.


Ok, I’ll try to come up with an IdGenerator that can be mocked then. That might be good for other reasons as well. Thanks.