-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_sourcing_test.go
64 lines (59 loc) · 1.74 KB
/
event_sourcing_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
package gddd
import (
"fmt"
"testing"
"time"
)
type BookAggregate struct {
AbstractAggregate
Book string `json:"book"`
Price int64 `json:"price"`
CreateTime time.Time `json:"create_time"`
}
type BookCreated struct {
Book string `json:"book"`
Price int64 `json:"price"`
CreateTime time.Time `json:"create_time"`
}
type BookChangedPrice struct {
Price int64 `json:"price"`
}
func Test_handleAggregate(t *testing.T) {
time_, _ := time.Parse("2006-01-02T15:04:05", "2022-01-19T23:59:59")
type args struct {
aggregate Aggregate
event DomainEvent
}
tests := []struct {
name string
args args
}{
{
"BookCreated",
args{
aggregate: &BookAggregate{AbstractAggregate: AbstractAggregate{Id: 1}},
event: &SampleDomainEvent{aggregateId: 1, aggregateName: "book", eventId: 1, eventName: "BookCreated", eventBody: BookCreated{Book: "aa", Price: 2, CreateTime: time.Now().UTC()}},
},
},
{
"BookChangedPrice",
args{
aggregate: &BookAggregate{AbstractAggregate: AbstractAggregate{Id: 1}, Book: "aa", Price: 2, CreateTime: time_},
event: &SampleDomainEvent{aggregateId: 1, aggregateName: "book", eventId: 2, eventName: "BookChangedPrice", eventBody: BookChangedPrice{Price: 3}},
},
},
{
"BookChangedPrice",
args{
aggregate: &BookAggregate{AbstractAggregate: AbstractAggregate{Id: 1}, Book: "aa", Price: 3, CreateTime: time_},
event: &SampleDomainEvent{aggregateId: 1, aggregateName: "book", eventId: 2, eventName: "BookChangedPrice", eventBody: BookChangedPrice{Price: 4}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
handleAppliedDomainEvent(tt.args.aggregate, tt.args.event)
fmt.Println("--", tt.args.aggregate)
})
}
}