Skip to content

Commit

Permalink
Add equivalent stream key tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elexisvenator authored and oskardudycz committed Oct 19, 2023
1 parent 59b6124 commit 1065a98
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/events/projections/ioc.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ProductProjection : CustomProjection<Product, Guid>
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/Projections/projections_with_IoC_services.cs#L148-L186' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_productprojection' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/Projections/projections_with_IoC_services.cs#L149-L187' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_productprojection' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Now, we *want* to use this projection at runtime within Marten, and need to register the projection
Expand All @@ -78,7 +78,7 @@ using var host = await Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
})
.StartAsync();
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/Projections/projections_with_IoC_services.cs#L26-L44' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_registering_projection_built_by_services' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/Projections/projections_with_IoC_services.cs#L27-L45' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_registering_projection_built_by_services' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Note that we're having to explicitly specify the projection lifecycle for the projection used within
Expand Down
4 changes: 3 additions & 1 deletion docs/events/querying.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public class fetching_stream_state: IntegrationContext
{
var state = theSession.Events.FetchStreamState(theStreamId);

state.ShouldNotBeNull();
state.Id.ShouldBe(theStreamId);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
Expand All @@ -189,6 +190,7 @@ public class fetching_stream_state: IntegrationContext
{
var state = await theSession.Events.FetchStreamStateAsync(theStreamId);

state.ShouldNotBeNull();
state.Id.ShouldBe(theStreamId);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
Expand Down Expand Up @@ -228,7 +230,7 @@ public class fetching_stream_state: IntegrationContext
}
}
```
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/fetching_stream_state.cs#L85-L160' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_fetching_stream_state' title='Start of snippet'>anchor</a></sup>
<sup><a href='https://github.com/JasperFx/marten/blob/master/src/EventSourcingTests/fetching_stream_state.cs#L86-L163' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_fetching_stream_state' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Furthermore, `StreamState` contains metadata for when the stream was created, `StreamState.Created`, and when the stream was last updated, `StreamState.LastTimestamp`.
Expand Down
82 changes: 82 additions & 0 deletions src/EventSourcingTests/fetching_stream_state.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using EventSourcingTests.Projections;
using Marten;
using Marten.Events;
using Marten.Schema.Identity;
using Marten.Testing.Harness;
using Shouldly;
Expand Down Expand Up @@ -106,6 +107,7 @@ public void can_fetch_the_stream_version_and_aggregate_type()
{
var state = theSession.Events.FetchStreamState(theStreamId);

state.ShouldNotBeNull();
state.Id.ShouldBe(theStreamId);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
Expand All @@ -118,6 +120,7 @@ public async Task can_fetch_the_stream_version_and_aggregate_type_async()
{
var state = await theSession.Events.FetchStreamStateAsync(theStreamId);

state.ShouldNotBeNull();
state.Id.ShouldBe(theStreamId);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
Expand Down Expand Up @@ -158,3 +161,82 @@ public async Task can_fetch_the_stream_events_through_batch_query()
}

#endregion

public class fetching_stream_state_string_id: IntegrationContext
{
private string theStreamKey;

public fetching_stream_state_string_id(DefaultStoreFixture fixture) : base(fixture)
{
}

protected override Task fixtureSetup()
{
UseStreamIdentity(StreamIdentity.AsString);

var joined = new MembersJoined { Members = new[] { "Rand", "Matt", "Perrin", "Thom" } };
var departed = new MembersDeparted { Members = new[] { "Thom" } };

theStreamKey = Guid.NewGuid().ToString();
theSession.Events.StartStream<Quest>(theStreamKey, joined, departed);
return theSession.SaveChangesAsync();
}

[Fact]
public void can_fetch_the_stream_version_and_aggregate_type()
{
var state = theSession.Events.FetchStreamState(theStreamKey);

state.ShouldNotBeNull();
state.Key.ShouldBe(theStreamKey);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
state.LastTimestamp.ShouldNotBe(DateTimeOffset.MinValue);
state.Created.ShouldNotBe(DateTimeOffset.MinValue);
}

[Fact]
public async Task can_fetch_the_stream_version_and_aggregate_type_async()
{
var state = await theSession.Events.FetchStreamStateAsync(theStreamKey);

state.ShouldNotBeNull();
state.Key.ShouldBe(theStreamKey);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
state.LastTimestamp.ShouldNotBe(DateTimeOffset.MinValue);
state.Created.ShouldNotBe(DateTimeOffset.MinValue);
}

[Fact]
public async Task can_fetch_the_stream_version_through_batch_query()
{
var batch = theSession.CreateBatchQuery();

var stateTask = batch.Events.FetchStreamState(theStreamKey);

await batch.Execute();

var state = await stateTask;

state.Key.ShouldBe(theStreamKey);
state.Version.ShouldBe(2);
state.AggregateType.ShouldBe(typeof(Quest));
state.LastTimestamp.ShouldNotBe(DateTimeOffset.MinValue);
}

[Fact]
public async Task can_fetch_the_stream_events_through_batch_query()
{
var batch = theSession.CreateBatchQuery();

var eventsTask = batch.Events.FetchStream(theStreamKey);

await batch.Execute();

var events = await eventsTask;

events.Count.ShouldBe(2);
}
}

0 comments on commit 1065a98

Please sign in to comment.