Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="FSharp.Core" Version="9.0.100" />
<PackageVersion Include="FSharp.SystemTextJson" Version="1.3.13" />
<PackageVersion Include="JasperFx" Version="1.26.0" />
<PackageVersion Include="JasperFx.Events" Version="1.29.0" />
<PackageVersion Include="JasperFx.Events" Version="1.29.1" />
<PackageVersion Include="JasperFx.Events.SourceGenerator" Version="1.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,39 @@ public async Task fetch_for_writing_with_natural_key_with_inline_snapshot()
stream.Aggregate.ShouldNotBeNull();
stream.Aggregate.Key.ShouldBe(aggregateKey);
}

// Regression coverage for https://github.com/JasperFx/marten/issues/4277.
// Self-aggregating aggregate (record) with a static [NaturalKeySource] factory.
public sealed record Bug4277SelfAggregate(Guid Id, [property: NaturalKey] Bug4197AggregateKey Key)
{
[NaturalKeySource]
public static Bug4277SelfAggregate Create(Bug4197AggregateCreatedEvent e)
=> new(e.Id, new Bug4197AggregateKey(e.Key));
}

[Fact]
public async Task fetch_for_writing_with_natural_key_on_self_aggregating_record_with_static_source()
{
StoreOptions(opts =>
{
opts.Projections.Snapshot<Bug4277SelfAggregate>(SnapshotLifecycle.Inline);
});

await using var session = theStore.LightweightSession();

var aggregateId = Guid.NewGuid();
var aggregateKey = new Bug4197AggregateKey("another-key-value");
var e = new Bug4197AggregateCreatedEvent(aggregateId, aggregateKey.Value);

session.Events.StartStream<Bug4277SelfAggregate>(aggregateId, e);
await session.SaveChangesAsync();

// Before the fix, the natural-key lookup row was never written, so this
// FetchForWriting by natural key returned a null aggregate.
var stream = await session.Events.FetchForWriting<Bug4277SelfAggregate, Bug4197AggregateKey>(aggregateKey);

stream.ShouldNotBeNull();
stream.Aggregate.ShouldNotBeNull();
stream.Aggregate.Key.ShouldBe(aggregateKey);
}
}
Loading