Skip to content

Commit

Permalink
Added test for LiveStreamAggregation code file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Jul 21, 2023
1 parent 04c50bd commit 074ee67
Showing 1 changed file with 64 additions and 0 deletions.
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 };
}
}

0 comments on commit 074ee67

Please sign in to comment.