forked from jetbasrawi/go.cqrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
105 lines (74 loc) · 2.15 KB
/
command_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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 (
"math/rand"
. "gopkg.in/check.v1"
)
var _ = Suite(&CommandSuite{})
type CommandSuite struct{}
type SomeCommand struct {
Item string
Count int
}
func NewSomeCommandMessage(id string) *CommandDescriptor {
ev := &SomeCommand{Item: NewUUID(), Count: rand.Intn(100)}
return NewCommandMessage(id, ev)
}
type SomeOtherCommand struct {
OrderID string
}
func NewSomeOtherCommandMessage(id string) *CommandDescriptor {
ev := &SomeOtherCommand{id}
return NewCommandMessage(id, ev)
}
type ErrorCommand struct {
Message string
}
func (s *CommandSuite) TestNewCommandMessage(c *C) {
id := NewUUID()
cmd := &SomeCommand{Item: "Some String", Count: 43}
cm := NewCommandMessage(id, cmd)
c.Assert(cm.id, Equals, id)
c.Assert(cm.command, Equals, cmd)
c.Assert(cm.headers, NotNil)
}
func (s *CommandSuite) TestShouldGetTypeOfCommand(c *C) {
sc := &SomeCommand{"Some String", 42}
cm := &CommandDescriptor{command: sc}
typeString := cm.CommandType()
c.Assert(typeString, Equals, "SomeCommand")
}
func (s *CommandSuite) TestShouldGetHeaders(c *C) {
cmd := &SomeCommand{"Some data", 456}
cm := NewCommandMessage(NewUUID(), cmd)
cm.headers["a"] = "b"
h := cm.Headers()
c.Assert(h, DeepEquals, cm.headers)
}
func (s *CommandSuite) TestShouldGetCommand(c *C) {
cmd := &SomeCommand{"Some data", 456}
cm := NewCommandMessage(NewUUID(), cmd)
got := cm.Command()
c.Assert(got, DeepEquals, cm.command)
}
func (s *CommandSuite) TestAddHeaderInt(c *C) {
cmd := &SomeCommand{"Some data", 456}
cm := NewCommandMessage(NewUUID(), cmd)
cm.SetHeader("a", 3)
c.Assert(cm.headers["a"], Equals, 3)
}
func (s *CommandSuite) TestAddHeaderString(c *C) {
cmd := &SomeCommand{"Some data", 456}
cm := NewCommandMessage(NewUUID(), cmd)
cm.SetHeader("a", "abc")
c.Assert(cm.headers["a"], Equals, "abc")
}
func (s *CommandSuite) TestAddHeaderStruct(c *C) {
cmd := &SomeCommand{"Some data", 456}
cm := NewCommandMessage(NewUUID(), cmd)
cm.SetHeader("a", cmd)
c.Assert(cm.headers["a"], DeepEquals, cmd)
}