コード例 #1
0
            public async Task RunShouldReadFromTheChannelIfWaitToReadReturnedTrue(
                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(true);
                channel.Read(Any <CancellationToken>()).Returns(new GatewayMessageChunk(bytes, 0, true));

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await channel.Received().Read(Is(cancellationToken));
            }
コード例 #2
0
            public async Task RunShouldDeserializeTheMessageIfEndOfMessageIsReached(
                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, true));

                await worker.Start(gateway);

                await worker.Run(cancellationToken);

                await serializer.Received().Deserialize <GatewayMessage>(Is(stream), Is(cancellationToken));
            }
コード例 #3
0
            public async Task SendShouldThrowIfTheGatewayWasStopped(
                string chunk,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker worker
                )
            {
                var message = new GatewayMessageChunk {
                    Bytes = Encoding.UTF8.GetBytes(chunk)
                };
                var cancellationToken = new CancellationToken(false);

                await worker.Start(gateway);

                await worker.Stop();

                var         operationCancellationToken = new CancellationToken(false);
                Func <Task> func = () => worker.Emit(message, operationCancellationToken);

                await func.Should().ThrowAsync <OperationCanceledException>();
            }
コード例 #4
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>());
            }
コード例 #5
0
            public async Task RunShouldNotUpdateSequenceNumberIfEndOfMessageIsNotReached(
                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 = sequenceNumber
                };

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

                await worker.Start(gateway);

                await worker.Run();

                gateway.DidNotReceive().SequenceNumber = sequenceNumber;
            }