Skip to content

Commit

Permalink
Merge pull request #134 from dogmatiq/dogma-v0.9.0
Browse files Browse the repository at this point in the history
Update to Dogma v0.9.0
  • Loading branch information
jmalloc authored Nov 5, 2020
2 parents fecbfdd + 04461dd commit 067f2d7
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 75 deletions.
1 change: 1 addition & 0 deletions assert/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newTestApp() (
return "<aggregate-instance>"
},
HandleCommandFunc: func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
) {
Expand Down
35 changes: 28 additions & 7 deletions compare/comparator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package compare_test

import (
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/testkit/compare"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -36,30 +37,50 @@ var _ = Describe("type DefaultComparator", func() {
})

Describe("func AggregateRootIsEqual()", func() {
It("returns true if tlues have the same type and value", func() {
It("returns true if the values have the same type and value", func() {
Expect(comparator.AggregateRootIsEqual(
&AggregateRoot{Value: "<foo>"},
&AggregateRoot{Value: "<foo>"},
&AggregateRoot{
AppliedEvents: []dogma.Message{
MessageA1,
},
},
&AggregateRoot{
AppliedEvents: []dogma.Message{
MessageA1,
},
},
)).To(BeTrue())
})

It("returns false if the values have the same type with different values", func() {
Expect(comparator.AggregateRootIsEqual(
&AggregateRoot{Value: "<foo>"},
&AggregateRoot{Value: "<bar>"},
&AggregateRoot{
AppliedEvents: []dogma.Message{
MessageA1,
},
},
&AggregateRoot{
AppliedEvents: []dogma.Message{
MessageA2,
},
},
)).To(BeFalse())
})

It("returns false if the values are different types", func() {
Expect(comparator.AggregateRootIsEqual(
&AggregateRoot{Value: "<foo>"},
&AggregateRoot{
AppliedEvents: []dogma.Message{
"<foo>",
},
},
&struct{ AggregateRoot }{},
)).To(BeFalse())
})
})

Describe("func ProcessRootIsEqual()", func() {
It("returns true if tlues have the same type and value", func() {
It("returns true if the values have the same type and value", func() {
Expect(comparator.ProcessRootIsEqual(
&ProcessRoot{Value: "<foo>"},
&ProcessRoot{Value: "<foo>"},
Expand Down
2 changes: 1 addition & 1 deletion engine/controller/aggregate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *Controller) Handle(
"HandleCommand",
env.Message,
func() {
handler.HandleCommand(s, env.Message)
handler.HandleCommand(r, s, env.Message)
},
)

Expand Down
67 changes: 62 additions & 5 deletions engine/controller/aggregate/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var _ = Describe("type Controller", func() {
It("forwards the message to the handler", func() {
called := false
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
_ dogma.AggregateCommandScope,
m dogma.Message,
) {
Expand All @@ -132,6 +133,7 @@ var _ = Describe("type Controller", func() {

It("returns the recorded events", func() {
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expand Down Expand Up @@ -208,6 +210,25 @@ var _ = Describe("type Controller", func() {
))
})

It("passes a new aggregate root", func() {
handler.HandleCommandFunc = func(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expect(r).To(Equal(&AggregateRoot{}))
}

_, err := ctrl.Handle(
context.Background(),
fact.Ignore,
time.Now(),
command,
)

Expect(err).ShouldNot(HaveOccurred())
})

It("panics if New() returns nil", func() {
handler.NewFunc = func() dogma.AggregateRoot {
return nil
Expand All @@ -227,6 +248,7 @@ var _ = Describe("type Controller", func() {
When("the instance exists", func() {
BeforeEach(func() {
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expand All @@ -241,6 +263,8 @@ var _ = Describe("type Controller", func() {
)

Expect(err).ShouldNot(HaveOccurred())

handler.HandleCommandFunc = nil
})

It("records a fact", func() {
Expand All @@ -258,11 +282,40 @@ var _ = Describe("type Controller", func() {
HandlerName: "<name>",
Handler: handler,
InstanceID: "<instance-C1>",
Root: &AggregateRoot{},
Envelope: command,
Root: &AggregateRoot{
AppliedEvents: []dogma.Message{
MessageE1,
},
},
Envelope: command,
},
))
})

It("passes an aggregate root with historical events applied", func() {
handler.HandleCommandFunc = func(
r dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expect(r).To(Equal(
&AggregateRoot{
AppliedEvents: []dogma.Message{
MessageE1,
},
},
))
}

_, err := ctrl.Handle(
context.Background(),
fact.Ignore,
time.Now(),
command,
)

Expect(err).ShouldNot(HaveOccurred())
})
})

It("provides more context to UnexpectedMessage panics from RouteCommandToInstance()", func() {
Expand Down Expand Up @@ -292,6 +345,7 @@ var _ = Describe("type Controller", func() {

It("provides more context to UnexpectedMessage panics from HandleCommand()", func() {
handler.HandleCommandFunc = func(
dogma.AggregateRoot,
dogma.AggregateCommandScope,
dogma.Message,
) {
Expand Down Expand Up @@ -320,6 +374,7 @@ var _ = Describe("type Controller", func() {

It("provides more context to UnexpectedMessage panics from ApplyEvent() when called with new events", func() {
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expand All @@ -328,7 +383,7 @@ var _ = Describe("type Controller", func() {

handler.NewFunc = func() dogma.AggregateRoot {
return &AggregateRoot{
ApplyEventFunc: func(dogma.Message, interface{}) {
ApplyEventFunc: func(dogma.Message) {
panic(dogma.UnexpectedMessage)
},
}
Expand Down Expand Up @@ -356,6 +411,7 @@ var _ = Describe("type Controller", func() {

It("provides more context to UnexpectedMessage panics from ApplyEvent() when called with historical events", func() {
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
_ dogma.Message,
) {
Expand All @@ -372,7 +428,7 @@ var _ = Describe("type Controller", func() {
handler.HandleCommandFunc = nil
handler.NewFunc = func() dogma.AggregateRoot {
return &AggregateRoot{
ApplyEventFunc: func(dogma.Message, interface{}) {
ApplyEventFunc: func(dogma.Message) {
panic(dogma.UnexpectedMessage)
},
}
Expand Down Expand Up @@ -402,8 +458,9 @@ var _ = Describe("type Controller", func() {
Describe("func Reset()", func() {
BeforeEach(func() {
handler.HandleCommandFunc = func(
_ dogma.AggregateRoot,
s dogma.AggregateCommandScope,
m dogma.Message,
_ dogma.Message,
) {
s.RecordEvent(MessageE1) // record event to create the instance
}
Expand Down
4 changes: 0 additions & 4 deletions engine/controller/aggregate/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func (s *scope) Destroy() {
})
}

func (s *scope) Root() dogma.AggregateRoot {
return s.root
}

func (s *scope) RecordEvent(m dogma.Message) {
if !s.exists {
s.observer.Notify(fact.AggregateInstanceCreated{
Expand Down
Loading

0 comments on commit 067f2d7

Please sign in to comment.