Im trying to test an Aggregate and would like to assert the events outside of the fixture and perhaps even use Hamcrest to evaluate?
An example of using timestamps
fixture.given()
.when(new UserCreateCommand("1","test@bob.com"))
.expectEvents(new UserCreatedEvent("1","test@bob.com");
The fixture allows me to easily test equality, e.g. the command produces exactly this event, its not so easy if I wanted to say introduce a Timestamp of when the event was created for example
fixture.given()
.when(new UserCreateCommand("1","test@bob.com"))
.expectEvents(new UserCreatedEvent("1","test@bob.com", LocalDateTime.now());
This expectation will never work as the LocalDateTime.now() will never be precisely equal to the timestamp generated in the aggregate.
I could simply include the Timestamp in the command payload, but feel a preference to handle inside the Aggregate to ensure a consistent way of generating this timestamps.
Is there a way to retrieve the Event out of the fixture to assert independently of the fixture e.g.
UserCreatedEvent uce = fixture.given()
.when(new UserCreateCommand("1","test@bob.com"))
.extractEvent(UserCreatedEvent.class)
This would then allow me to use other assertion libraries also like hamcrest for example:
e.g.
assertThat(uce.getCreatedAt(), is(greaterThanOrEqualto(LocalDateTime.now().minusSeconds(1);