public void Fetching_from_given_id_should_return_commit_with_given_id_and_newer()
        {
            var streamId     = Guid.NewGuid();
            var firstCommit  = streamId.BuildAttempt();
            var secondCommit = firstCommit.BuildNextAttempt();
            var thirdCommit  = secondCommit.BuildNextAttempt();

            _sut.Commit(firstCommit);
            _sut.Commit(secondCommit);
            _sut.Commit(thirdCommit);

            var all    = _sut.Fetch(0, 100).ToList();
            var second = all[all.Count - 2];

            second.CommitId.Should().Be(secondCommit.CommitId);

            var secondAndLater = _sut.Fetch((long)second.Headers["SequentialId"], 100).ToList();

            secondAndLater.Count.Should().Be(2);
            second = secondAndLater[0];
            second.CommitId.Should().Be(secondCommit.CommitId);
        }
        public IEnumerable <IProcessingElement> Fetch(string pipelineName, int maxCount)
        {
            if (_lastCommitSequentialId == EmtpySequentialIdValue)
            {
                _lastCommitSequentialId = _streamStore.GetLastProcessedSequentialNumber(pipelineName);
            }
            var commits = _streamStore.Fetch(_lastCommitSequentialId, maxCount);

            foreach (var commit in commits)
            {
                var thisCommitSequentialId = (long)commit.Headers["SequentialId"];
                if (_firstCommitFetched && _lastCommitSequentialId == thisCommitSequentialId)
                {
                    continue;
                }
                _lastCommitSequentialId = thisCommitSequentialId;
                foreach (EventMessage eventMessage in commit.Events)
                {
                    var storedEvent = (StoredEvent)eventMessage.Body;
                    yield return(new SourcedEventProcessingElement(storedEvent.Convert(commit.StreamId)));
                }
                _firstCommitFetched = true;
            }
        }