public void ChangeName(string name) { var @event = new UserNameUpdated(Id, name); Enqueue(@event); Apply(@event); }
public void AggregateStream_ShouldReturnSpecifiedVersionOfTheStream() { var streamId = Guid.NewGuid(); var userCreated = new UserCreated(streamId, "John Doe"); var userNameUpdated = new UserNameUpdated(streamId, "Adam Smith"); var userNameUpdatedAgain = new UserNameUpdated(streamId, "Michael Newman"); eventStore.AppendEvent <User>(streamId, userCreated); eventStore.AppendEvent <User>(streamId, userNameUpdated); eventStore.AppendEvent <User>(streamId, userNameUpdatedAgain); var aggregateAtVersion1 = eventStore.AggregateStream <User>(streamId, 1); aggregateAtVersion1.Id.Should().Be(streamId); aggregateAtVersion1.Name.Should().Be(userCreated.UserName); aggregateAtVersion1.Version.Should().Be(1); var aggregateAtVersion2 = eventStore.AggregateStream <User>(streamId, 2); aggregateAtVersion2.Id.Should().Be(streamId); aggregateAtVersion2.Name.Should().Be(userNameUpdated.UserName); aggregateAtVersion2.Version.Should().Be(2); var aggregateAtVersion3 = eventStore.AggregateStream <User>(streamId, 3); aggregateAtVersion3.Id.Should().Be(streamId); aggregateAtVersion3.Name.Should().Be(userNameUpdatedAgain.UserName); aggregateAtVersion3.Version.Should().Be(3); }
public HostState Apply(UserNameUpdated data) { var user = Users.First(u => u.Id == data.UserId); return(new HostState( Users.Replace(user, user.SetName(data.Name)), Messages )); }
void Apply(UserNameUpdated @event) { databaseConnection.Execute( @"UPDATE UserDashboards SET UserName = @UserName WHERE Id = @UserId", @event ); }
public void AggregateStream_ShouldReturnObjectWithStateBasedOnEvents() { var streamId = Guid.NewGuid(); var userCreated = new UserCreated(streamId, "John Doe"); var userNameUpdated = new UserNameUpdated(streamId, "Adam Smith"); eventStore.AppendEvent <User>(streamId, userCreated); eventStore.AppendEvent <User>(streamId, userNameUpdated); var aggregate = eventStore.AggregateStream <User>(streamId); aggregate.Id.Should().Be(streamId); aggregate.Name.Should().Be(userNameUpdated.UserName); aggregate.Version.Should().Be(2); }
public void GetEvents_ShouldReturnAppendedEvents() { var streamId = Guid.NewGuid(); var userCreated = new UserCreated(streamId, "John Doe"); var userNameUpdated = new UserNameUpdated(streamId, "Adam Smith"); eventStore.AppendEvent <User>(streamId, userCreated); eventStore.AppendEvent <User>(streamId, userNameUpdated); var events = eventStore.GetEvents(streamId); events.Cast <object>().Should().HaveCount(2); events.OfType <UserCreated>().Should().Contain( e => e.UserId == userCreated.UserId && e.UserName == userCreated.UserName); events.OfType <UserNameUpdated>().Should().Contain( e => e.UserId == userNameUpdated.UserId && e.UserName == userNameUpdated.UserName); }
public void Apply(UserNameUpdated @event) { Name = @event.UserName; }
public void Apply(UserNameUpdated @event, UserDashboard item) { item.UserName = @event.UserName; }
public void Apply(UserNameUpdated @event) { throw new NotImplementedException("TODO"); }