Skip to content

Commit

Permalink
Test just to prove that projected documents dont' accidentally get op…
Browse files Browse the repository at this point in the history
…timistic concurrency from the policy. Closes GH-2978
  • Loading branch information
jeremydmiller committed Feb 21, 2024
1 parent 8093b54 commit db9a162
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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<AllGood>(ProjectionLifecycle.Async);
});

var mapping = theStore.Options.Storage.MappingFor(typeof(MyAggregate));
mapping.UseNumericRevisions.ShouldBeTrue();
mapping.UseOptimisticConcurrency.ShouldBeFalse();

theStore.Options.Storage.MappingFor(typeof(Target))
.UseOptimisticConcurrency.ShouldBeTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Marten.Events.Projections;

/// <summary>
/// Just adds a suffix to the document alias of a projected aggregate
/// Makes several modifications to the documents of projections
/// </summary>
internal class AsyncProjectionVersionPolicy : IDocumentPolicy
internal class ProjectionDocumentPolicy : IDocumentPolicy
{
public void Apply(DocumentMapping mapping)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/StoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal INpgsqlDataSourceFactory NpgsqlDataSourceFactory

private readonly IList<IDocumentPolicy> _policies = new List<IDocumentPolicy>
{
new VersionedPolicy(), new SoftDeletedPolicy(), new TrackedPolicy(), new TenancyPolicy(), new AsyncProjectionVersionPolicy()
new VersionedPolicy(), new SoftDeletedPolicy(), new TrackedPolicy(), new TenancyPolicy(), new ProjectionDocumentPolicy()
};

/// <summary>
Expand Down

0 comments on commit db9a162

Please sign in to comment.