Exemplo n.º 1
0
 private void SetupReadStreamForwards(string streamId)
 {
     StreamStoreMock.As <IReadonlyStreamStore>()
     .Setup(
         streamStore => streamStore.ReadStreamForwards(streamId, It.IsAny <int>(), It.IsAny <int>(),
                                                       It.IsAny <bool>(),
                                                       It.IsAny <CancellationToken>())
         )
     .ReturnsAsync(new ReadStreamPage(
                       streamId,
                       PageReadStatus.Success,
                       0,
                       0,
                       0,
                       0,
                       ReadDirection.Forward,
                       true,
                       (_, __) => Task.FromResult(new ReadStreamPage(streamId, PageReadStatus.Success, 0, 0, 0, 0,
                                                                     ReadDirection.Forward, true)),
                       new[]
     {
         new StreamMessage(streamId, Guid.NewGuid(), 0, 0, DateTime.UtcNow, nameof(TestEvent),
                           JsonSerializer.Serialize(new Dictionary <string, object> {
             { Constants.VersionKey, 0 }
         }),
                           JsonSerializer.Serialize(new TestEvent(Guid.NewGuid())))
     }
                       ));
 }
Exemplo n.º 2
0
        public async Task ShouldGetLastVersionWhenReplaying()
        {
            // Act
            await Sut.ReplayProjectionFrom(StreamId, 0, (o, token) => Task.CompletedTask,
                                           CancellationToken.None).ConfigureAwait(false);

            // Assert
            StreamStoreMock.As <IReadonlyStreamStore>().Verify(streamStore => streamStore.ReadStreamBackwards(
                                                                   It.Is <StreamId>(streamId => streamId.Value == ReplayManagerTestsFixture.StreamId),
                                                                   StreamVersion.End,
                                                                   It.IsAny <int>(),
                                                                   It.IsAny <bool>(),
                                                                   It.IsAny <CancellationToken>()),
                                                               Times.Once);
        }
        public ConnectedProjectionsStreamStoreSubscriptionTests()
        {
            _fixture = new Fixture();

            _streamStoreMock = new StreamStoreMock();
            _commandBusMock  = new Mock <IConnectedProjectionsCommandBus>();

            var loggerFactory = new FakeLoggerFactory();

            _loggerMock = loggerFactory.ResolveLoggerMock <ConnectedProjectionsStreamStoreSubscription>();

            _sut = new ConnectedProjectionsStreamStoreSubscription(
                _streamStoreMock.Object,
                _commandBusMock.Object,
                loggerFactory);
        }
Exemplo n.º 4
0
 protected void SetupReadStreamBackwards(string streamId, int lastStreamVersion = ExpectedVersion.NoStream)
 {
     StreamStoreMock.As <IReadonlyStreamStore>()
     .Setup(
         streamStore => streamStore.ReadStreamBackwards(streamId, StreamVersion.End, 1, true,
                                                        It.IsAny <CancellationToken>())
         )
     .ReturnsAsync(new ReadStreamPage(
                       streamId,
                       PageReadStatus.Success,
                       0,
                       0,
                       lastStreamVersion,
                       0,
                       ReadDirection.Backward,
                       true));
 }
Exemplo n.º 5
0
        public async Task ShouldReadTheStreamFromCheckpoint()
        {
            // Arrange
            const long checkpoint = 10;

            SetupReadAllForwards();

            // Act
            await Sut.ReplayProjectionFrom(checkpoint, (o, token) => Task.CompletedTask,
                                           cancellationToken : CancellationToken.None).ConfigureAwait(false);

            // Assert
            StreamStoreMock.As <IReadonlyStreamStore>().Verify(streamStore => streamStore.ReadAllForwards(
                                                                   checkpoint,
                                                                   It.IsAny <int>(),
                                                                   It.IsAny <bool>(),
                                                                   CancellationToken.None),
                                                               Times.Once);
        }
Exemplo n.º 6
0
        public async Task ShouldReadTheStreamFromCheckpoint()
        {
            // Arrange
            const int checkpoint = 10;

            SetupReadStreamBackwards(StreamId, 100);

            // Act
            await Sut.ReplayProjectionFrom(StreamId, checkpoint, (o, token) => Task.CompletedTask,
                                           CancellationToken.None).ConfigureAwait(false);

            // Assert
            StreamStoreMock.As <IReadonlyStreamStore>().Verify(streamStore => streamStore.ReadStreamForwards(
                                                                   It.Is <StreamId>(streamId => streamId.Value == StreamId),
                                                                   checkpoint,
                                                                   It.IsAny <int>(),
                                                                   It.IsAny <bool>(),
                                                                   It.IsAny <CancellationToken>()),
                                                               Times.Once);
        }
Exemplo n.º 7
0
 protected void SetupReadAllForwards()
 {
     StreamStoreMock.As <IReadonlyStreamStore>().Setup(streamStore =>
                                                       streamStore.ReadAllForwards(It.IsAny <long>(), It.IsAny <int>(), It.IsAny <bool>(),
                                                                                   It.IsAny <CancellationToken>()))
     .ReturnsAsync(new ReadAllPage(
                       Position.Start,
                       Position.Start + 1,
                       true,
                       ReadDirection.Forward,
                       (_, __) => Task.FromResult(new ReadAllPage(Position.Start, Position.Start + 1, true,
                                                                  ReadDirection.Forward, null)),
                       new[]
     {
         new StreamMessage("Stream Message", Guid.NewGuid(), 0, 0, DateTime.UtcNow, nameof(TestEvent),
                           JsonSerializer.Serialize(new Dictionary <string, object> {
             { Constants.VersionKey, 0 }
         }),
                           JsonSerializer.Serialize(new TestEvent(Guid.NewGuid())))
     }
                       ));
 }