-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_aggregate.go
More file actions
48 lines (39 loc) · 1.01 KB
/
test_aggregate.go
File metadata and controls
48 lines (39 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ess
// testAggregate is a dummy aggregate used for testing. This type is
// included in the main package, because it is referenced by
// EventStoreTest.
type testAggregate struct {
id string
events EventPublisher
error error
onEvent func(event *Event)
onCommand func(*testAggregate)
}
func newTestAggregateFromCommand(command *Command) Aggregate {
return newTestAggregate(command.Get("id").String())
}
func newTestAggregate(id string) *testAggregate {
return &testAggregate{id: id}
}
func (self *testAggregate) FailWith(err error) *testAggregate {
self.error = err
return self
}
func (self *testAggregate) Id() string {
return self.id
}
func (self *testAggregate) HandleEvent(e *Event) {
if self.onEvent != nil {
self.onEvent(e)
}
}
func (self *testAggregate) HandleCommand(command *Command) error {
if self.onCommand != nil {
self.onCommand(self)
}
return self.error
}
func (self *testAggregate) PublishWith(publisher EventPublisher) Aggregate {
self.events = publisher
return self
}