Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace SqlStreamStore
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -380,6 +381,25 @@ public async Task When_read_deleted_stream_backwards_then_should_get_StreamNotFo
}
}

[Theory, InlineData(0), InlineData(1)]
public async Task Can_read_stream_backwards_starting_past_end_of_stream(int fromVersionInclusive)
{
using(var fixture = GetFixture())
{
using(var store = await fixture.GetStreamStore())
{
await store.AppendToStream("stream-1", ExpectedVersion.NoStream, Array.Empty<NewStreamMessage>());

var streamMessagesPage =
await store.ReadStreamBackwards("stream-1", fromVersionInclusive, 1);

streamMessagesPage.Status.ShouldBe(PageReadStatus.Success);
streamMessagesPage.Messages.Length.ShouldBe(0);
streamMessagesPage.IsEnd.ShouldBeTrue();
}
}
}

// ReSharper disable once UnusedMethodReturnValue.Global
public static IEnumerable<object[]> GetReadStreamForwardsTheories()
{
Expand Down
2 changes: 1 addition & 1 deletion src/SqlStreamStore/InMemory/InMemoryStreamStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected override Task<ReadStreamPage> ReadStreamBackwardsInternal(

var messages = new List<StreamMessage>();
var i = fromVersionInclusive == StreamVersion.End ? stream.Messages.Count - 1 : fromVersionInclusive;
while (i >= 0 && count > 0)
while (i < stream.Messages.Count && i >= 0 && count > 0)
{
var inMemorymessage = stream.Messages[i];
StreamMessage message;
Expand Down