From 35572dceaf798f8d9547b3765748f2e1e0e92407 Mon Sep 17 00:00:00 2001 From: Raphael Strotz Date: Mon, 16 Oct 2023 16:08:24 +0200 Subject: [PATCH] Add integration test for new overload This test ensures that the projection configuration actually works. The inline projection is configured to automatically delete the document upon receiving a deletion event. --- ...on_with_custom_projection_configuration.cs | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs b/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs index 28687d8dbe..fb96ce80b2 100644 --- a/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs +++ b/src/EventSourcingTests/Projections/inline_aggregation_with_custom_projection_configuration.cs @@ -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>>(); + var configureProjection = Substitute.For>>(); StoreOptions(_ => { - _.Projections.Snapshot(SnapshotLifecycle.Inline, configureProjection); + _.Projections.Snapshot(SnapshotLifecycle.Inline, configureProjection); }); - configureProjection.Received(1).Invoke(Arg.Any>()); + configureProjection.Received(1).Invoke(Arg.Any>()); } + + [Fact] + public void does_delete_document_upon_deleted_event() + { + StoreOptions(_ => + { + _.Projections.Snapshot(SnapshotLifecycle.Inline, configureProjection: p => + { + p.DeleteEvent(); + }); + }); + + var todoId = Guid.NewGuid(); + theSession.Events.StartStream(todoId, new TodoCreated(todoId, "Write code")); + theSession.SaveChanges(); + + // Make sure the document has been created + theSession.Load(todoId).ShouldNotBeNull(); + + // Append the delete + theSession.Events.Append(todoId, new TodoDeleted(todoId)); + theSession.SaveChanges(); + + // Make sure the document now has been deleted + theSession.Load(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 + }; }