Check for the existence of AR

Our model the Employ can have several contracts during its life in a Company.
We need to know the first time and Employ get a Contract because we need to collect the date (and other things).
Theese contracts are imported from the external HR software.
What is the correct way to check if en employ is already into the application?

Side notes: the AR is event sourced and the first time the app will be on production historical events will be batch imported from HR so I'm afraid that leveraging on reading query model can be dangerous for the eventually consistence.

Thanks.

Hi Pietro,

you should use a query model to find out if an aggregate already exists. If it doesn’t send a command to create it. That may fail (because of eventual consistency), but in that case, an Aggregate will have been created and you can just continue sending your updates.

Cheers,

Allard

Ok, it sounds good.
But to test it with given-when-then I'very to mock the query repository isn't it? And I should test either when the repository is aligned and the case when it isn't already aligned.
The evens output should be the same right?

Thanks

Yes, if you use a query repository, you will have to mock it in the test fixture.
The events are different in both cases, because in the first you also expect the “created” event.

Cheers,

Allard