Class: Sequent::Test::CommandHandlerHelpers::FakeEventStore

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/test/command_handler_helpers.rb

Instance Method Summary collapse

Constructor Details

#initializeFakeEventStore

Returns a new instance of FakeEventStore.



40
41
42
43
44
# File 'lib/sequent/test/command_handler_helpers.rb', line 40

def initialize
  @event_streams = {}
  @all_events = {}
  @stored_events = []
end

Instance Method Details

#commit_events(_, streams_with_events) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/sequent/test/command_handler_helpers.rb', line 60

def commit_events(_, streams_with_events)
  streams_with_events.each do |event_stream, events|
    serialized = serialize_events(events)
    @event_streams[event_stream.aggregate_id] = event_stream
    @all_events[event_stream.aggregate_id] ||= []
    @all_events[event_stream.aggregate_id] += serialized
    @stored_events += serialized
  end
end

#find_event_stream(aggregate_id) ⇒ Object



52
53
54
# File 'lib/sequent/test/command_handler_helpers.rb', line 52

def find_event_stream(aggregate_id)
  @event_streams[aggregate_id]
end

#given_events(events) ⇒ Object



70
71
72
73
# File 'lib/sequent/test/command_handler_helpers.rb', line 70

def given_events(events)
  commit_events(nil, to_event_streams(events))
  @stored_events = []
end

#load_events(aggregate_id) ⇒ Object



46
47
48
49
50
# File 'lib/sequent/test/command_handler_helpers.rb', line 46

def load_events(aggregate_id)
  event_stream = @event_streams[aggregate_id]
  return nil unless event_stream
  [event_stream, deserialize_events(@all_events[aggregate_id])]
end

#stored_eventsObject



56
57
58
# File 'lib/sequent/test/command_handler_helpers.rb', line 56

def stored_events
  deserialize_events(@stored_events)
end

#stream_exists?(aggregate_id) ⇒ Boolean

Returns:



75
76
77
# File 'lib/sequent/test/command_handler_helpers.rb', line 75

def stream_exists?(aggregate_id)
  @event_streams.has_key?(aggregate_id)
end