public async Task Create_should_create_events() { var command = new CreateComment { Text = "text1" }; var result = await sut.ExecuteAsync(CreateCommentsCommand(command)); result.ShouldBeEquivalent(EntityCreatedResult.Create(command.CommentId, 0)); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { Version = 0 }); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { CreatedComments = new List <Comment> { new Comment(command.CommentId, LastEvents.ElementAt(0).Headers.Timestamp(), command.Actor, "text1") }, Version = 0 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentCreated { CommentId = command.CommentId, Text = command.Text }) ); }
public async Task Update_should_create_events_and_update_state() { var createCommand = new CreateComment { Text = "text1" }; var updateCommand = new UpdateComment { Text = "text2", CommentId = createCommand.CommentId }; await sut.ExecuteAsync(CreateCommentsCommand(createCommand)); var result = await sut.ExecuteAsync(CreateCommentsCommand(updateCommand)); result.ShouldBeEquivalent(new EntitySavedResult(1)); sut.GetCommentsAsync(-1).Result.Should().BeEquivalentTo(new CommentsResult { CreatedComments = new List <Comment> { new Comment(createCommand.CommentId, LastEvents.ElementAt(0).Headers.Timestamp(), createCommand.Actor, "text2") }, Version = 1 }); sut.GetCommentsAsync(0).Result.Should().BeEquivalentTo(new CommentsResult { UpdatedComments = new List <Comment> { new Comment(createCommand.CommentId, LastEvents.ElementAt(0).Headers.Timestamp(), createCommand.Actor, "text2") }, Version = 1 }); LastEvents .ShouldHaveSameEvents( CreateCommentsEvent(new CommentUpdated { CommentId = createCommand.CommentId, Text = updateCommand.Text }) ); }