forked from jetbasrawi/go.cqrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventbus_test.go
63 lines (46 loc) · 1.57 KB
/
eventbus_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2016 Jet Basrawi. All rights reserved.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package ycq
import (
. "gopkg.in/check.v1"
)
var _ = Suite(&InternalEventBusSuite{})
type InternalEventBusSuite struct {
bus *InternalEventBus
}
func (s *InternalEventBusSuite) SetUpTest(c *C) {
s.bus = NewInternalEventBus()
}
func (s *InternalEventBusSuite) Test_NewHandlerEventBus(c *C) {
bus := NewInternalEventBus()
c.Assert(bus, NotNil)
}
func (s *InternalEventBusSuite) TestEventBusPublishesEventsToHandlers(c *C) {
h := NewMockEventHandler()
ev := NewTestEventMessage(NewUUID())
s.bus.AddHandler(h, &SomeEvent{})
s.bus.PublishEvent(ev)
c.Assert(h.events[0], Equals, ev)
}
func (s *InternalEventBusSuite) TestRegisterMultipleEventsForHandler(c *C) {
h := NewMockEventHandler()
ev1 := NewEventMessage(NewUUID(), &SomeEvent{Item: "Some Item", Count: 3456}, nil)
ev2 := NewEventMessage(NewUUID(), &SomeOtherEvent{OrderID: NewUUID()}, nil)
s.bus.AddHandler(h, &SomeEvent{}, &SomeOtherEvent{})
s.bus.PublishEvent(ev1)
s.bus.PublishEvent(ev2)
c.Assert(h.events[0], Equals, ev1)
c.Assert(h.events[1], Equals, ev2)
}
// Stubs
type MockEventBus struct {
events []EventMessage
}
func (m *MockEventBus) PublishEvent(event EventMessage) {
m.events = append(m.events, event)
}
func (m *MockEventBus) AddHandler(handler EventHandler, event ...interface{}) {}
func (m *MockEventBus) AddLocalHandler(handler EventHandler) {}
func (m *MockEventBus) AddGlobalHandler(handler EventHandler) {}