Skip to content

Commit

Permalink
Adding more tests on revision setting of aggregates after quick appen…
Browse files Browse the repository at this point in the history
…d + Inline. Closes GH-3314
  • Loading branch information
jeremydmiller committed Jul 22, 2024
1 parent d012535 commit 1206d8e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,62 @@ public async Task fetch_new_stream_for_writing_Guid_identifier()
document.CCount.ShouldBe(2);
}

[Fact]
public async Task revision_is_updated_after_quick_appending_with_IRevisioned()
{
StoreOptions(opts =>
{
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Inline);
opts.Events.AppendMode = EventAppendMode.Quick;
opts.Events.UseIdentityMapForInlineAggregates = true;
});

var streamId = Guid.NewGuid();

var stream = await theSession.Events.FetchForWriting<SimpleAggregate>(streamId);
stream.Aggregate.ShouldBeNull();
stream.CurrentVersion.ShouldBe(0);

stream.AppendOne(new AEvent());
stream.AppendMany(new BEvent(), new BEvent(), new BEvent());
stream.AppendMany(new CEvent(), new CEvent());

await theSession.SaveChangesAsync();

var document = await theSession.LoadAsync<SimpleAggregate>(streamId);
document.Version.ShouldBe(6);
}

[Fact]
public async Task revision_is_updated_after_quick_appending_with_custom_mapped_version()
{
StoreOptions(opts =>
{
opts.Projections.Snapshot<SimpleAggregate2>(SnapshotLifecycle.Inline).Metadata(m =>
{
m.Revision.MapTo(x => x.Version);
});

opts.Events.AppendMode = EventAppendMode.Quick;
opts.Events.UseIdentityMapForInlineAggregates = true;
});

var streamId = Guid.NewGuid();

var stream = await theSession.Events.FetchForWriting<SimpleAggregate2>(streamId);
stream.Aggregate.ShouldBeNull();
stream.CurrentVersion.ShouldBe(0);

stream.AppendOne(new AEvent());
stream.AppendMany(new BEvent(), new BEvent(), new BEvent());
stream.AppendMany(new CEvent(), new CEvent());

await theSession.SaveChangesAsync();

var document = await theSession.LoadAsync<SimpleAggregate2>(streamId);
document.Version.ShouldBe(6);
}

[Fact]
public async Task fetch_new_stream_for_writing_Guid_identifier_exception_handling()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Marten.Events;
using Marten.Exceptions;
using Marten.Metadata;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;
Expand Down Expand Up @@ -344,36 +345,52 @@ await Should.ThrowAsync<ConcurrencyException>(async () =>
});
}

}

public class SimpleAggregate : IRevisioned
{
// This will be the aggregate version
public int Version { get; set; }

public Guid Id { get; set; }

/* TODO on Tuesday
1. Happy path append to existing stream
2. Sad path append to existing stream w/ optimistic concurrency check
3. Happy path while providing version
4. Sad path quickly while providing version
5. Sad path while providing version between starting and committing
6. Switch to Inline!
public int ACount { get; set; }
public int BCount { get; set; }
public int CCount { get; set; }
public int DCount { get; set; }
public int ECount { get; set; }

public void Apply(AEvent _)
{
ACount++;
}

public void Apply(BEvent _)
{
BCount++;
}

public void Apply(CEvent _)
{
CCount++;
}

*/
public void Apply(DEvent _)
{
DCount++;
}

public void Apply(EEvent _)
{
ECount++;
}
}

public class SimpleAggregate

public class SimpleAggregate2
{
// This will be the aggregate version
public long Version { get; set; }

public int Version { get; set; }

public Guid Id { get; set; }

Expand Down

0 comments on commit 1206d8e

Please sign in to comment.