Exemplo n.º 1
0
func (s *AppTestSuite) TestDomainObjectCanBeBuildFromHistory(c *C) {
	// The id of our event source that we will rebuild from history.
	sourceId, _ := sourcing.ParseEventSourceId("0791d279-664d-458e-bf60-567ade140832")

	// The full history for the User domain object
	history := []sourcing.Event{
		// It was first created
		events.UserCreated{
			Username: "******",
		},
		// Then the username was changed
		events.UsernameChanged{
			OldUsername: "******",
			NewUsername: "******",
		},
	}

	// Create a new User domain object from history
	user := domain.NewUserFromHistory(sourceId, history)

	// It should not have the initial state.
	c.Assert(user.Username, Not(Equals), "pjvds")

	// It should have the latest state.
	c.Assert(user.Username, Equals, "wwwouter")
}
Exemplo n.º 2
0
func (s *AppTestSuite) BenchmarkRebuildUserFromHistory(c *C) {
	// The full history for the User domain object
	sourceId, _ := sourcing.ParseEventSourceId("0791d279-664d-458e-bf60-567ade140832")

	// The full history for the User domain object
	history := []sourcing.Event{
		// It was first created
		events.UserCreated{
			Username: "******",
		},
		// Then the username was changed
		events.UsernameChanged{
			OldUsername: "******",
			NewUsername: "******",
		},
	}

	for i := 0; i < c.N; i++ {
		// Create a new User domain object from history
		domain.NewUserFromHistory(sourceId, history)
	}
}