Skip to content

Commit

Permalink
Revision should be the one of the last event when folding at end of s…
Browse files Browse the repository at this point in the history
…tream
  • Loading branch information
thinkbeforecoding authored and thefringeninja committed Aug 17, 2021
1 parent 7c5e886 commit 0b689e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/EventStore.Client.Streams/EventStoreClient.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,27 @@ public async ValueTask<FoldResult<T>> FoldStreamAsync<T,E>(
Stream = ReadReq.Types.Options.Types.StreamOptions.FromStreamNameAndRevision(streamName, revision),
Count = long.MaxValue
}

};
if (readReq.Options.Filter == null) {
readReq.Options.NoFilter = new Empty();
}

readReq.Options.UuidOption = new ReadReq.Types.Options.Types.UUIDOption { Structured = new Empty() };

var call =
var call =
_client.Read(readReq,
EventStoreCallOptions.Create(Settings, operationOptions, userCredentials, cancellationToken))
.ResponseStream.ReadAllAsync().GetAsyncEnumerator();


var hasNext = await call.MoveNextAsync(cancellationToken).ConfigureAwait(false);

var rev =
hasNext && call.Current.ContentCase == ReadResp.ContentOneofCase.StreamNotFound
? StreamRevision.None
: StreamRevision.FromStreamPosition(revision);
: hasNext
? StreamRevision.FromStreamPosition(revision)
: StreamRevision.FromStreamPosition(revision-1);

while(hasNext) {
if (call.Current.ContentCase == ReadResp.ContentOneofCase.Event) {
Expand Down
2 changes: 1 addition & 1 deletion test/EventStore.Client.Streams.Tests/fold_stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ await _fixture.Client.AppendToStreamAsync(streamName, StreamState.NoStream,
new List<StreamPosition>());


var expected = StreamRevision.FromInt64(pos);
var expected = StreamRevision.FromInt64(pos-1);
Assert.Equal(expected, result.Revision);
}

Expand Down

0 comments on commit 0b689e5

Please sign in to comment.