libkazv
|
We created a fixtures library to provide developers with a way to make mock models with sensible defaults.
All functions lie in the Kazv::Factory
namespace. The header file to include is <testfixtures/factory.hpp>
.
These functions take a ComposedModifier<ModelType>
, where ModelType
is the class of the fixture that you want to create.
A ComposedModifier<ModelType>
is basically a function that takes a ModelType &
and modify it, so you can put a lambda here:
Just as its name suggests, you can compose multiple ComposedModifier
with operator|()
, and they will execute in the sequence in which they are composed:
A ComposedModifier<ModelType>
is an std::function<void(ModelType &)>
but it won't throw when a default-constructed instance is being invoked, instead it would just do nothing, so you can write the following when you do not need any particular tweak:
To make our life easier, we defined some commonly used modifiers. The most generic one is withAttr()
, which takes a pointer to a class member and a value. When invoked, it sets that member to the value provided.
Some modifiers add values to a mapping, for example withRoom()
, withRoomState()
, withRoomTimeline()
, withRoomAccountData()
. They take care of the keys automatically so instead of writing
you can just do