We will look next at a simple example of implementation using event sourcing. We'll start with our Twitter example, and start writing some tests.
First, let's create a user and check the event store for the right events, in pseudocode:
TEST_CASE("Create User"){
EventStore eventStore;
...
auto alexId = createUser("alexboly", eventStore);
...
CHECK_EQ(lastEvent, expectedEvent);
}
We need a few things to compile this test. First, an event store that can store events, but how do we express an event that can be stored? We need some kind of data structure that can hold property names and values. The simplest one is a map<string, string> structure that will map the names of properties to their values. To see it in action, let's create the event structure for CreateUser:
auto makeCreateUserEvent = [](const...