-
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a failing test for a bug with inline lifecycle and using fetc…
…hForWriting
- Loading branch information
1 parent
941f64c
commit 80d10be
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/EventSourcingTests/Bugs/Bug_fetch_for_writing_cache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Marten.Events; | ||
using Marten.Events.Aggregation; | ||
using Marten.Events.Projections; | ||
using Marten.Schema; | ||
using Marten.Testing.Harness; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace EventSourcingTests.Bugs; | ||
|
||
public class Bug_fetch_for_writing_cache: BugIntegrationContext | ||
{ | ||
[Fact] | ||
public async Task Test() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
opts.Projections.Add<TestProjection2>(ProjectionLifecycle.Inline); | ||
opts.Schema | ||
.For<TestAggregate>() | ||
.Identity(x => x.StreamKey); | ||
}); | ||
|
||
var streamKey = Guid.NewGuid().ToString(); | ||
|
||
theSession.Events.StartStream(streamKey, new NamedEvent2("foo")); | ||
await theSession.SaveChangesAsync(); | ||
|
||
var test = await theSession.Events.FetchForWriting<TestAggregate>(streamKey); | ||
test.AppendOne(new NamedEvent2("bar")); | ||
//await theSession.Events.AppendOptimistic(streamKey, new NamedEvent2("bar")); If I commented the two lines above and uncommented this one it works fine | ||
await theSession.SaveChangesAsync(); | ||
|
||
test = await theSession.Events.FetchForWriting<TestAggregate>(streamKey); | ||
Assert.Equal("bar", test.Aggregate.Name); | ||
} | ||
|
||
} | ||
|
||
public record NamedEvent2(string Name); | ||
|
||
public class TestProjection2: SingleStreamProjection<TestAggregate> | ||
{ | ||
public TestAggregate Create(NamedEvent2 @event) | ||
=> new TestAggregate(@event.Name); | ||
|
||
public TestAggregate Apply(NamedEvent2 @event, TestAggregate aggregate) | ||
=> aggregate with { Name = @event.Name }; | ||
} | ||
|
||
public record TestAggregate | ||
{ | ||
public TestAggregate(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
[Identity] | ||
public string StreamKey { get; set; } = null!; | ||
|
||
public string Name { get; set; } = null!; | ||
} |