-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathinmemory-eventstreamrepo_test.go
64 lines (51 loc) · 1.63 KB
/
inmemory-eventstreamrepo_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 cqrs_test
import (
"fmt"
"testing"
"github.com/andrewwebber/cqrs"
)
func TestInMemoryEventStreamRepository(t *testing.T) {
typeRegistry := cqrs.NewTypeRegistry()
persistance := cqrs.NewInMemoryEventStreamRepository()
repository := cqrs.NewRepository(persistance, typeRegistry)
hashedPassword, err := GetHashForPassword("$ThisIsMyPassword1")
accountID := "5058e029-d329-4c4b-b111-b042e48b0c5f"
if err != nil {
t.Fatal("Error: ", err)
}
cqrs.PackageLogger().Debugf("Get hash for user...")
cqrs.PackageLogger().Debugf("Create new account...")
account := NewAccount("John", "Snow", "[email protected]", hashedPassword, 0.0)
account.SetID(accountID)
err = account.ChangePassword("$ThisIsANOTHERPassword")
if err != nil {
t.Fatal(err)
}
_, err = repository.Save(account, "correlationID")
if err != nil {
t.Fatal(err)
}
accountFromHistory, err := NewAccountFromHistory(accountID, repository)
if err != nil {
t.Fatal(err)
}
if string(accountFromHistory.PasswordHash) != string(account.PasswordHash) {
t.Fatal("Expected PasswordHash to match")
}
if events, err := persistance.AllIntegrationEventsEverPublished(); err != nil {
t.Fatal(err)
} else {
cqrs.PackageLogger().Debugf(fmt.Sprintf("%+v", events))
}
correlationEvents, err := persistance.GetIntegrationEventsByCorrelationID("correlationID")
if err != nil {
t.Fatal(err)
}
if len(correlationEvents) == 0 {
t.Fatal("Expeced correlation events")
}
cqrs.PackageLogger().Debugf("GetIntegrationEventsByCorrelationID")
for _, correlationEvent := range correlationEvents {
cqrs.PackageLogger().Debugf(fmt.Sprintf("%+v", correlationEvent))
}
}