forked from jetbasrawi/go.cqrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatcher_test.go
62 lines (45 loc) · 1.72 KB
/
dispatcher_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
// 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 (
"fmt"
. "gopkg.in/check.v1"
)
var _ = Suite(&InternalCommandBusSuite{})
type InternalCommandBusSuite struct {
bus *InMemoryDispatcher
stubhandler *TestCommandHandler
}
func (s *InternalCommandBusSuite) SetUpTest(c *C) {
s.bus = NewInMemoryDispatcher()
s.stubhandler = &TestCommandHandler{}
}
func (s *InternalCommandBusSuite) TestNewInternalCommandBus(c *C) {
bus := NewInMemoryDispatcher()
c.Assert(bus, NotNil)
}
func (s *InternalCommandBusSuite) TestShouldHandleCommand(c *C) {
err := s.bus.RegisterHandler(s.stubhandler, &SomeCommand{})
c.Assert(err, IsNil)
cmd := NewSomeCommandMessage(NewUUID())
err = s.bus.Dispatch(cmd)
c.Assert(err, IsNil)
c.Assert(s.stubhandler.command, Equals, cmd)
}
func (s *InternalCommandBusSuite) TestShouldReturnErrorIfNoHandlerRegisteredForCommand(c *C) {
cmd := NewSomeCommandMessage(NewUUID())
err := s.bus.Dispatch(cmd)
c.Assert(err, DeepEquals, fmt.Errorf("The command bus does not have a handler for commands of type: %s", cmd.CommandType()))
c.Assert(s.stubhandler.command, IsNil)
}
func (s *InternalCommandBusSuite) TestDuplicateHandlerRegistrationReturnsAnError(c *C) {
err := s.bus.RegisterHandler(s.stubhandler, &SomeCommand{}, &SomeCommand{})
c.Assert(err, DeepEquals, fmt.Errorf("Duplicate command handler registration with command bus for command of type: %s",
typeOf(&SomeCommand{"", 0})))
}
func (s *InternalCommandBusSuite) TestCanRegisterMultipleCommandsForTheSameHandler(c *C) {
err := s.bus.RegisterHandler(s.stubhandler, &SomeCommand{}, &SomeOtherCommand{})
c.Assert(err, IsNil)
}