Beispiel #1
0
def _when_i_save_new_streams_with_events_to_the_store(context, num_streams):
    num_streams = int(num_streams)
    context.stream_ids = tuple(str(uuid4()) for _ in range(num_streams))
    for stream_id in context.stream_ids:
        events = make_vector(
            Event.generate('EventHappened', version=1),
            Event.generate('EventHappened', version=2),
        )
        context.event_store.save_events(stream_id, events, expected_version=-1)
Beispiel #2
0
def _when_i_save_a_new_stream_with_some_events_to_the_store(context):
    context.stream_id = str(uuid4())
    context.events = make_vector(
        Event.generate('EventHappened', version=1),
        Event.generate('EventHappened', version=2),
    )
    context.event_store.save_events(context.stream_id,
                                    context.events,
                                    expected_version=-1)
Beispiel #3
0
def _generate_dummy_aggregate():
    _aggregate = Aggregate.generate()
    _event = Event.generate('EventHappened')
    _aggregate = _aggregate.apply_event(_event,
                                        committed=True,
                                        apply_map=_apply_map)
    return _aggregate
Beispiel #4
0
def _when_i_save_a_new_stream_with_events_to_the_store(context, num_streams,
                                                       num_events):
    num_streams = int(num_streams)
    num_events = int(num_events)
    context.stream_ids = tuple(str(uuid4()) for _ in range(num_streams))
    for stream_id in context.stream_ids:
        events = tuple(
            Event.generate('SomethingHappened') for _ in range(num_events))
        context.event_store.save_events(stream_id, events)
Beispiel #5
0
def _when_i_apply_a_new_state_changing_domain_event_to_the_aggregate(context):
    context.event = Event.generate('EventHappened')
    _key = context.expected_state_key = 'hello'
    _value = context.expected_state_value = 'world'
    apply_map = pmap({
        'EventHappened':
        lambda agg, *a, **kw: agg.set_state(_key, _value)
    })
    context.aggregate = context.aggregate.apply_event(context.event,
                                                      apply_map=apply_map)
Beispiel #6
0
def _when_i_save_new_event_to_same_stream_with_wrong_expected_version(context):
    context.new_event = Event.generate('NewEventHappened',
                                       version=(len(context.events) + 1))
    try:
        context.event_store.save_events(
            context.stream_id,
            (context.new_event, ),
            0  # Version should be 2
        )
    except RuntimeError as e:
        context.error = e
Beispiel #7
0
def _when_i_apply_a_new_domain_event_to_the_aggregate(context):
    context.event = Event.generate('EventHappened')
    context.aggregate = context.aggregate.apply_event(context.event)
Beispiel #8
0
def _when_i_apply_a_new_event_to_the_aggregate_copy(context):
    context.aggregate_copy = context.aggregate_copy.apply_event(
        Event.generate('EventHappened'))
Beispiel #9
0
def _given_a_new_domain_event(context):
    context.new_event = Event.generate('EventHappened')
Beispiel #10
0
def _given_an_existing_aggregate(context):
    context.events = make_vector(Event.generate('EventHappened'),
                                 Event.generate('EventHappened'))
    _aggregate = Aggregate.generate()
    _aggregate = _aggregate.apply_events(context.events, apply_map=_apply_map)
    context.aggregate = context.repository.save_aggregate(_aggregate)
Beispiel #11
0
def _given_a_new_aggregate_with_uncommitted_events(context):
    context.events = make_vector(Event.generate('EventHappened'),
                                 Event.generate('EventHappened'))
    context.aggregate = Aggregate.generate()
    context.aggregate = context.aggregate.apply_events(context.events,
                                                       apply_map=_apply_map)
Beispiel #12
0
def _when_i_add_a_new_event_to_the_second_stream(context):
    context.event_store.save_events(context.stream_ids[1],
                                    (Event.generate('AnotherEventHappened'), ))
Beispiel #13
0
def _when_i_save_a_new_event_to_the_same_stream(context):
    context.new_event = Event.generate('NewEventHappened',
                                       version=(len(context.events) + 1))
    context.event_store.save_events(context.stream_id, (context.new_event, ),
                                    -2)
Beispiel #14
0
def _when_i_generate_a_new_event(context):
    context.event = Event.generate('EventHappened')