protected override void Context()
        {
            _committed = new[]
            {
                BuildCommitStub(2, 1, _eventsPerCommit), // 1-2
                BuildCommitStub(4, 2, _eventsPerCommit), // 3-4
                BuildCommitStub(6, 3, _eventsPerCommit), // 5-6 <-- asked up to this one
                BuildCommitStub(8, 4, _eventsPerCommit)  // 7-8
            };

            // the persistence returns all the data in the stream
            A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, MinRevision, MaxRevision)).Returns(_committed);
            A.CallTo(() => Persistence.Commit(A <CommitAttempt> ._))
            .ReturnsLazily((CommitAttempt attempt) => new Commit(
                               attempt.BucketId,
                               attempt.StreamId,
                               attempt.StreamRevision,
                               attempt.CommitId,
                               attempt.CommitSequence,
                               attempt.CommitStamp,
                               0,
                               attempt.Headers,
                               attempt.Events));

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, MinRevision, MaxRevision);
        }
Esempio n. 2
0
 protected override Task Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, SystemTimeProvider);
     Stream.Add(new EventMessage()
     {
         Body = "body"
     });
     return(Stream.CommitChanges(Guid.NewGuid()));
 }
        protected override void Context()
        {
            _committed        = new[] { BuildCommitStub(1, 1, 1) };
            _dupliateCommitId = _committed[0].CommitId;

            A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, 0, int.MaxValue)).Returns(_committed);

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, 0, int.MaxValue);
        }
 protected override void Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence);
     Stream.Add(new EventMessage()
     {
         Body = "body"
     });
     Stream.CommitChanges(Guid.NewGuid());
 }
        protected override Task Context()
        {
            _committed        = new[] { BuildCommitStub(1, 1, 1) };
            _dupliateCommitId = _committed[0].CommitId;

            A.CallTo(() => Persistence.GetFromAsync(BucketId, StreamId, 0, int.MaxValue)).Returns(_committed);

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, 0, int.MaxValue, CancellationToken.None);
            return(Task.CompletedTask);
        }
		public virtual async Task<IEventStream> OpenStream(string bucketId, string streamId, int minRevision, int maxRevision)
        {
            maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;

            Logger.Debug(Resources.OpeningStreamAtRevision, streamId, bucketId, minRevision, maxRevision);

			var stream = new OptimisticEventStream(bucketId, streamId, this, _systemTimeProvider);
			await stream.Initialize(minRevision, maxRevision);
            return stream;
        }
Esempio n. 7
0
        public virtual async Task <IEventStream> OpenStream(string bucketId, string streamId, int minRevision, int maxRevision)
        {
            maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;

            Logger.Debug(Resources.OpeningStreamAtRevision, streamId, bucketId, minRevision, maxRevision);

            var stream = new OptimisticEventStream(bucketId, streamId, this, _systemTimeProvider);
            await stream.Initialize(minRevision, maxRevision);

            return(stream);
        }
Esempio n. 8
0
        protected override async Task Context()
        {
            _committed        = new[] { BuildCommitStub(1, 1, 1) };
            _dupliateCommitId = _committed[0].CommitId;

            //A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, 0, int.MaxValue)).Returns(_committed.AsAsyncEnumerable());
            Persistence.GetFrom(BucketId, StreamId, 0, int.MaxValue).Returns(_committed.AsAsyncEnumerable());

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, SystemTimeProvider);
            await Stream.Initialize(0, int.MaxValue);
        }
        protected override void Context()
        {
            _committed          = new[] { BuildCommitStub(1, 1, 1) };
            _discoveredOnCommit = new[] { BuildCommitStub(3, 2, 2) };

            A.CallTo(() => Persistence.Commit(A <CommitAttempt> ._)).Throws(new ConcurrencyException());
            A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, StreamRevision, int.MaxValue)).Returns(_committed);
            A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, StreamRevision + 1, int.MaxValue)).Returns(_discoveredOnCommit);

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, StreamRevision, int.MaxValue);
            Stream.Add(_uncommitted);
        }
Esempio n. 10
0
        protected override void Context()
        {
            _committed        = new[] { BuildCommitStub(1, 1, 1) };
            _dupliateCommitId = _committed[0].CommitId;

            Persistence
            .Setup(x => x.GetFrom(Bucket.Default, StreamId, 0, int.MaxValue))
            .Returns(_committed);

            Stream = new OptimisticEventStream(
                StreamId, Persistence.Object, 0, int.MaxValue);
        }
        protected override Task Context()
        {
            _committed          = new[] { BuildCommitStub(1, 1, 1) };
            _discoveredOnCommit = new[] { BuildCommitStub(3, 2, 2) };

            A.CallTo(() => Persistence.CommitAsync(A <CommitAttempt> ._, A <CancellationToken> ._)).Throws(new ConcurrencyException());
            A.CallTo(() => Persistence.GetFromAsync(BucketId, StreamId, StreamRevision, int.MaxValue)).Returns(_committed);
            A.CallTo(() => Persistence.GetFromAsync(BucketId, StreamId, StreamRevision + 1, int.MaxValue)).Returns(_discoveredOnCommit);

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, StreamRevision, int.MaxValue, CancellationToken.None);
            Stream.Add(_uncommitted);
            return(Task.CompletedTask);
        }
Esempio n. 12
0
        public virtual async Task <IEventStream> OpenStream(ISnapshot snapshot, int maxRevision)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
            maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;

            var stream = new OptimisticEventStream(
                snapshot.BucketId, snapshot.StreamId, this, _systemTimeProvider);
            await stream.Initialize(snapshot, maxRevision);

            return(stream);
        }
Esempio n. 13
0
        protected override void Context()
        {
            _committed          = new[] { BuildCommitStub(1, 1, 1) };
            _discoveredOnCommit = new[] { BuildCommitStub(3, 2, 2) };

            Persistence
            .Setup(x => x.Commit(It.IsAny <CommitAttempt>()))
            .Throws(new ConcurrencyException());
            Persistence
            .Setup(x => x.GetFrom(Bucket.Default, StreamId, StreamRevision, int.MaxValue))
            .Returns(_committed);
            Persistence
            .Setup(x => x.GetFrom(Bucket.Default, StreamId, StreamRevision + 1, int.MaxValue))
            .Returns(_discoveredOnCommit);

            Stream = new OptimisticEventStream(StreamId, Persistence.Object, StreamRevision, int.MaxValue);
            Stream.Add(_uncommitted);
        }
Esempio n. 14
0
        protected override async Task Context()
        {
            _committed          = new[] { BuildCommitStub(1, 1, 1) };
            _discoveredOnCommit = new[] { BuildCommitStub(3, 2, 2) };

            //A.CallTo(() => Persistence.Commit(A<CommitAttempt>._)).Throws(new ConcurrencyException());
            //A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, StreamRevision, int.MaxValue)).Returns(_committed.AsAsyncEnumerable());
            //A.CallTo(() => Persistence.GetFrom(BucketId, StreamId, StreamRevision + 1, int.MaxValue)).Returns(_discoveredOnCommit.AsAsyncEnumerable());

            Persistence
            .When(x => x.Commit(Arg.Any <CommitAttempt>()))
            .Do(x => { throw new ConcurrencyException(); });

            Persistence.GetFrom(BucketId, StreamId, StreamRevision, int.MaxValue).Returns(_committed.AsAsyncEnumerable());
            Persistence.GetFrom(BucketId, StreamId, StreamRevision + 1, int.MaxValue).Returns(_discoveredOnCommit.AsAsyncEnumerable());

            Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, SystemTimeProvider);
            await Stream.Initialize(StreamRevision, int.MaxValue);

            Stream.Add(_uncommitted);
            //await Stream.CommitChanges(Guid.NewGuid());
        }
Esempio n. 15
0
 protected override void Because()
 {
     Stream = new OptimisticEventStream(StreamId, Persistence.Object, MinRevision, MaxRevision);
 }
 protected override Task Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, MinRevision, MaxRevision, CancellationToken.None);
     return(Task.CompletedTask);
 }
Esempio n. 17
0
 protected override void Because()
 {
     Stream = new OptimisticEventStream(StreamId, Persistence.Object, 0, int.MaxValue);
 }
Esempio n. 18
0
 protected override async Task Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, SystemTimeProvider);
     await Stream.Initialize(0, int.MaxValue);
 }
Esempio n. 19
0
 protected override Task Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, SystemTimeProvider);
     Stream.Initialize(MinRevision, MaxRevision).Wait();
     return(Task.FromResult(true));
 }
 protected override void Because()
 {
     Stream = new OptimisticEventStream(BucketId, StreamId, Persistence, 0, int.MaxValue);
 }
		public virtual async Task<IEventStream> OpenStream(ISnapshot snapshot, int maxRevision)
        {
            if (snapshot == null)
            {
                throw new ArgumentNullException("snapshot");
            }

            Logger.Debug(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision);
            maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision;

			var stream = new OptimisticEventStream(
				snapshot.BucketId, snapshot.StreamId, this, _systemTimeProvider);
			await stream.Initialize(snapshot, maxRevision);
			return stream;
        }