示例#1
0
            public async Task RunShouldRouteTheMessageIfEndOfMessageIsReached(
                byte[] bytes,
                uint interval,
                int sequenceNumber,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] ISerializer serializer,
                [Frozen, Substitute] IEventRouter router,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var @event = new HelloEvent {
                    HeartbeatInterval = interval
                };
                var message = new GatewayMessage {
                    SequenceNumber = sequenceNumber, Data = @event
                };
                var cancellationToken = new CancellationToken(false);

                serializer.Deserialize <GatewayMessage>(Any <Stream>(), Any <CancellationToken>()).Returns(message);
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true));

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await router.Received().Route(Is(@event), Is(cancellationToken));
            }
示例#2
0
            public async Task RunShouldNotUpdateSequenceNumberIfEndOfMessageIsReachedButSequenceNumberIsNull(
                byte[] bytes,
                int sequenceNumber,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] ISerializer serializer,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var message = new GatewayMessage {
                    SequenceNumber = null
                };

                serializer.Deserialize <GatewayMessage>(Any <Stream>(), Any <CancellationToken>()).Returns(message);
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true));

                gateway.SequenceNumber = sequenceNumber;

                await worker.Start(gateway);

                await worker.Run();

                gateway.SequenceNumber.Should().Be(sequenceNumber);
            }
示例#3
0
            public async Task RunShouldNotTruncateTheStreamIfEndOfMessageIsNotReached(
                byte[] bytes,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, false));

                await worker.Start(gateway);

                await worker.Run();

                stream.DidNotReceive().SetLength(0);
            }
示例#4
0
            public async Task RunShouldCreateAStream(
                byte[] bytes,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, 0, true));

                await worker.Start(gateway);

                await worker.Run();

                factory.Received().CreateStream();
            }
示例#5
0
            public async Task RunShouldWriteTheBytesToTheStream(
                byte[] bytes,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var cancellationToken = new CancellationToken(false);

                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true));

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await stream.Received().WriteAsync(Is <ReadOnlyMemory <byte> >(givenBytes => Encoding.UTF8.GetString(bytes) == Encoding.UTF8.GetString(bytes)), Is(cancellationToken));
            }
示例#6
0
            public async Task RunShouldNotReadFromTheChannelIfWaitToReadReturnedFalse(
                byte[] bytes,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var cancellationToken = new CancellationToken(false);

                channel.WaitToRead(Any <CancellationToken>()).Returns(false);

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await channel.DidNotReceive().Read(Is(cancellationToken));
            }
示例#7
0
            public async Task RunShouldNotDeserializeTheMessageIfEndOfMessageIsNotReached(
                byte[] bytes,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] ISerializer serializer,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var cancellationToken = new CancellationToken(false);

                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, false));

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await serializer.DidNotReceive().Deserialize <GatewayMessage>(Is(stream), Is(cancellationToken));
            }
示例#8
0
            public async Task RunShouldNotRouteTheMessageIfEndOfMessageIsReachedButEventDataIsNull(
                byte[] bytes,
                uint interval,
                int sequenceNumber,
                [Frozen, Substitute] Stream stream,
                [Frozen, Substitute] IChannel <GatewayMessageChunk> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] ISerializer serializer,
                [Frozen, Substitute] IEventRouter router,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, bytes.Length, true));

                await worker.Start(gateway);

                await worker.Run();

                await router.DidNotReceive().Route(Any <IGatewayEvent>(), Any <CancellationToken>());
            }