Skip to content

Commit

Permalink
Add integration test for new overload
Browse files Browse the repository at this point in the history
This test ensures that the projection configuration actually works.
The inline projection is configured to automatically delete the
document upon receiving a deletion event.
  • Loading branch information
Xzelsius committed Oct 16, 2023
1 parent 4ea941f commit 35572dc
Showing 1 changed file with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,53 @@ public class inline_aggregation_with_custom_projection_configuration : OneOffCon
[Fact]
public void does_call_custom_projection_configuration()
{
var configureProjection = Substitute.For<Action<SingleStreamProjection<QuestParty>>>();
var configureProjection = Substitute.For<Action<SingleStreamProjection<TodoAggregate>>>();

StoreOptions(_ =>
{
_.Projections.Snapshot<QuestParty>(SnapshotLifecycle.Inline, configureProjection);
_.Projections.Snapshot<TodoAggregate>(SnapshotLifecycle.Inline, configureProjection);
});

configureProjection.Received(1).Invoke(Arg.Any<SingleStreamProjection<QuestParty>>());
configureProjection.Received(1).Invoke(Arg.Any<SingleStreamProjection<TodoAggregate>>());
}

[Fact]
public void does_delete_document_upon_deleted_event()
{
StoreOptions(_ =>
{
_.Projections.Snapshot<TodoAggregate>(SnapshotLifecycle.Inline, configureProjection: p =>
{
p.DeleteEvent<TodoDeleted>();
});
});

var todoId = Guid.NewGuid();
theSession.Events.StartStream<TodoAggregate>(todoId, new TodoCreated(todoId, "Write code"));
theSession.SaveChanges();

// Make sure the document has been created
theSession.Load<TodoAggregate>(todoId).ShouldNotBeNull();

// Append the delete
theSession.Events.Append(todoId, new TodoDeleted(todoId));
theSession.SaveChanges();

// Make sure the document now has been deleted
theSession.Load<TodoAggregate>(todoId).ShouldBeNull();
}
}

public record TodoCreated(Guid Id, string Task);
public record TodoDeleted(Guid Id);

public class TodoAggregate
{
public Guid Id { get; set; }
public string Task { get; set; }

public static TodoAggregate Create(TodoCreated created) => new()
{
Task = created.Task
};
}

0 comments on commit 35572dc

Please sign in to comment.