Skip to content

Commit

Permalink
added some other variations
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaNitschke committed Oct 6, 2023
1 parent f1910b5 commit 839709b
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,65 @@ async Task<TDetail> CreateFromEvents<TAggregate, TEvent, TDetail>(IEnumerable<TE
}
}

[Fact]
public async Task projection_updates_with_save_strategy_variation_1b_generics_version()
{
StoreOptions(c =>
{
c.Projections.Add<WeeklyFoodTrackerDetailsProjection>(ProjectionLifecycle.Inline);
});

var streamId = Guid.NewGuid();
var events = new List<WeeklyFoodTrackerEvent>();
events.Add(new WeekStarted(streamId));
events.Add(new ApplesBought(streamId, 1));
events.Add(new BananasBought(streamId, 8));

var weekDetails = await CreateFromEvents<WeeklyFoodTracker, WeeklyFoodTrackerEvent, WeeklyFoodTrackerDetails>(events.ToArray());
weekDetails.ShouldNotBeNull();
weekDetails.Apples.ShouldBe(1);
weekDetails.Bananas.ShouldBe(8);

async Task<TDetail> CreateFromEvents<TAggregate, TEvent, TDetail>(TEvent[] events)
where TEvent : IAggregateStreamEvent
where TAggregate : class
{
if (!events.Any()) throw new InvalidOperationException("Must have at least one event");
var id = events.First().Id;
await using var session = theStore.LightweightSession();
session.Events.StartStream<TAggregate>(id, events);
await session.SaveChangesAsync();
return await session.LoadAsync<TDetail>(id) ?? throw new Exception("Should not be null)");
}
}

[Fact]
public async Task projection_updates_with_save_strategy_variation_1c_generics_version()
{
StoreOptions(c =>
{
c.Projections.Add<WeeklyFoodTrackerDetailsProjection>(ProjectionLifecycle.Inline);
});

var streamId = Guid.NewGuid();
var weekDetails = await CreateFromEvents<WeeklyFoodTracker, WeeklyFoodTrackerEvent, WeeklyFoodTrackerDetails>(new WeekStarted(streamId), new ApplesBought(streamId, 1), new BananasBought(streamId, 8));
weekDetails.ShouldNotBeNull();
weekDetails.Apples.ShouldBe(1);
weekDetails.Bananas.ShouldBe(8);

async Task<TDetail> CreateFromEvents<TAggregate, TEvent, TDetail>(params TEvent[] events)
where TEvent : IAggregateStreamEvent
where TAggregate : class
{
if (!events.Any()) throw new InvalidOperationException("Must have at least one event");
var id = events.First().Id;
await using var session = theStore.LightweightSession();
session.Events.StartStream<TAggregate>(id, events);
await session.SaveChangesAsync();
return await session.LoadAsync<TDetail>(id) ?? throw new Exception("Should not be null)");
}
}

[Fact]
public async Task projection_updates_with_save_strategy_variation_2_generics_version()
{
Expand Down

0 comments on commit 839709b

Please sign in to comment.