-
Notifications
You must be signed in to change notification settings - Fork 39
/
serializer_test.go
57 lines (46 loc) · 1.08 KB
/
serializer_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
package eventsource_test
import (
"testing"
"github.com/altairsix/eventsource"
"github.com/stretchr/testify/assert"
)
type EntitySetName struct {
eventsource.Model
Name string
}
func TestJSONSerializer(t *testing.T) {
event := EntitySetName{
Model: eventsource.Model{
ID: "123",
Version: 456,
},
Name: "blah",
}
serializer := eventsource.NewJSONSerializer(event)
record, err := serializer.MarshalEvent(event)
assert.Nil(t, err)
assert.NotNil(t, record)
v, err := serializer.UnmarshalEvent(record)
assert.Nil(t, err)
found, ok := v.(*EntitySetName)
assert.True(t, ok)
assert.Equal(t, &event, found)
}
func TestJSONSerializer_MarshalAll(t *testing.T) {
event := EntitySetName{
Model: eventsource.Model{
ID: "123",
Version: 456,
},
Name: "blah",
}
serializer := eventsource.NewJSONSerializer(event)
history, err := serializer.MarshalAll(event)
assert.Nil(t, err)
assert.NotNil(t, history)
v, err := serializer.UnmarshalEvent(history[0])
assert.Nil(t, err)
found, ok := v.(*EntitySetName)
assert.True(t, ok)
assert.Equal(t, &event, found)
}