-
-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for LiveStreamAggregation code file generation
- Loading branch information
1 parent
04c50bd
commit 074ee67
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/Projections/CodeGeneration/ProjectionCodeGenerationTests.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 System; | ||
using System.Linq; | ||
using JasperFx.CodeGeneration; | ||
using JasperFx.Core.Reflection; | ||
using Marten; | ||
using Marten.Events.Aggregation; | ||
using Marten.Events.Projections; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace EventSourcingTests.Projections.CodeGeneration; | ||
|
||
public class ProjectionCodeGenerationTests | ||
{ | ||
[Fact] | ||
public void Snapshot_GeneratesCodeFile() | ||
{ | ||
var options = new StoreOptions(); | ||
options.Connection("Dummy"); | ||
|
||
// Given | ||
options.Projections.Snapshot<Something>(SnapshotLifecycle.Inline); | ||
|
||
// When | ||
var store = new DocumentStore(options); | ||
|
||
// Then | ||
store.Events.As<ICodeFileCollection>().BuildFiles() | ||
.OfType<SingleStreamProjection<Something>>() | ||
.ShouldHaveSingleItem(); | ||
} | ||
|
||
|
||
[Fact] | ||
public void LiveStreamAggregation_GeneratesCodeFile() | ||
{ | ||
var options = new StoreOptions(); | ||
options.Connection("Dummy"); | ||
|
||
// Given | ||
options.Projections.LiveStreamAggregation<Something>(); | ||
|
||
// When | ||
var store = new DocumentStore(options); | ||
|
||
// Then | ||
store.Events.As<ICodeFileCollection>().BuildFiles() | ||
.OfType<SingleStreamProjection<Something>>() | ||
.ShouldHaveSingleItem(); | ||
} | ||
|
||
public record SomethingHappened(Guid SomethingId, string SomethingSomething); | ||
|
||
public record SomethingDifferentHappened(Guid SomethingId, string SomethingSomething); | ||
|
||
public record Something(Guid Id, string SomethingSomething) | ||
{ | ||
public static Something Create(SomethingHappened @event) => | ||
new Something(@event.SomethingId, @event.SomethingSomething); | ||
|
||
public Something Apply(SomethingHappened @event) => | ||
this with { SomethingSomething = @event.SomethingSomething }; | ||
} | ||
} |