From db9a162a5bfd499ac1fe3a05080b7853989a52c8 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Wed, 21 Feb 2024 10:50:55 -0600 Subject: [PATCH] Test just to prove that projected documents dont' accidentally get optimistic concurrency from the policy. Closes GH-2978 --- ...stic_concurrency_event_with_that_policy.cs | 29 +++++++++++++++++++ ...nPolicy.cs => ProjectionDocumentPolicy.cs} | 4 +-- src/Marten/StoreOptions.cs | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/EventSourcingTests/Bugs/Bug_2978_aggregate_projection_documents_are_not_optimistic_concurrency_event_with_that_policy.cs rename src/Marten/Events/Projections/{AsyncProjectionVersionPolicy.cs => ProjectionDocumentPolicy.cs} (84%) diff --git a/src/EventSourcingTests/Bugs/Bug_2978_aggregate_projection_documents_are_not_optimistic_concurrency_event_with_that_policy.cs b/src/EventSourcingTests/Bugs/Bug_2978_aggregate_projection_documents_are_not_optimistic_concurrency_event_with_that_policy.cs new file mode 100644 index 0000000000..f3fe61f616 --- /dev/null +++ b/src/EventSourcingTests/Bugs/Bug_2978_aggregate_projection_documents_are_not_optimistic_concurrency_event_with_that_policy.cs @@ -0,0 +1,29 @@ +using EventSourcingTests.Aggregation; +using Marten; +using Marten.Events.Projections; +using Marten.Testing.Documents; +using Marten.Testing.Harness; +using Shouldly; +using Xunit; + +namespace EventSourcingTests.Bugs; + +public class Bug_2978_aggregate_projection_documents_are_not_optimistic_concurrency_event_with_that_policy : BugIntegrationContext +{ + [Fact] + public void override_the_optimistic_concurrency_on_projected_document() + { + StoreOptions(opts => + { + opts.Policies.AllDocumentsEnforceOptimisticConcurrency(); + opts.Projections.Add(ProjectionLifecycle.Async); + }); + + var mapping = theStore.Options.Storage.MappingFor(typeof(MyAggregate)); + mapping.UseNumericRevisions.ShouldBeTrue(); + mapping.UseOptimisticConcurrency.ShouldBeFalse(); + + theStore.Options.Storage.MappingFor(typeof(Target)) + .UseOptimisticConcurrency.ShouldBeTrue(); + } +} diff --git a/src/Marten/Events/Projections/AsyncProjectionVersionPolicy.cs b/src/Marten/Events/Projections/ProjectionDocumentPolicy.cs similarity index 84% rename from src/Marten/Events/Projections/AsyncProjectionVersionPolicy.cs rename to src/Marten/Events/Projections/ProjectionDocumentPolicy.cs index a1566c5eec..4c443e4423 100644 --- a/src/Marten/Events/Projections/AsyncProjectionVersionPolicy.cs +++ b/src/Marten/Events/Projections/ProjectionDocumentPolicy.cs @@ -3,9 +3,9 @@ namespace Marten.Events.Projections; /// -/// Just adds a suffix to the document alias of a projected aggregate +/// Makes several modifications to the documents of projections /// -internal class AsyncProjectionVersionPolicy : IDocumentPolicy +internal class ProjectionDocumentPolicy : IDocumentPolicy { public void Apply(DocumentMapping mapping) { diff --git a/src/Marten/StoreOptions.cs b/src/Marten/StoreOptions.cs index 11b9d533a3..1f8bac5e3e 100644 --- a/src/Marten/StoreOptions.cs +++ b/src/Marten/StoreOptions.cs @@ -58,7 +58,7 @@ internal INpgsqlDataSourceFactory NpgsqlDataSourceFactory private readonly IList _policies = new List { - new VersionedPolicy(), new SoftDeletedPolicy(), new TrackedPolicy(), new TenancyPolicy(), new AsyncProjectionVersionPolicy() + new VersionedPolicy(), new SoftDeletedPolicy(), new TrackedPolicy(), new TenancyPolicy(), new ProjectionDocumentPolicy() }; ///