Пример #1
0
            public async Task RunShouldWaitUntilTheWebSocketIsOpen(
                int sequenceNumber,
                [Substitute] IClientWebSocket clientWebSocket,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] IChannel <GatewayMessage> channel,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Target] DefaultGatewayTxWorker worker
                )
            {
                var tries   = 0;
                var message = new GatewayMessage {
                    SequenceNumber = sequenceNumber
                };
                var cancellationToken = new CancellationToken(false);

                clientWebSocket.State.Returns(WebSocketState.Connecting);

                channel.Read(Any <CancellationToken>()).Returns(new ValueTask <GatewayMessage>(message));
                channel.WaitToRead(Any <CancellationToken>()).Returns(true);
                factory.CreateDelay(Any <uint>(), Any <CancellationToken>()).Returns(async x =>
                {
                    if (++tries == 2)
                    {
                        clientWebSocket.State.Returns(WebSocketState.Open);
                    }

                    await Task.CompletedTask;
                });

                await worker.Start(gateway, clientWebSocket);

                await worker.Run(cancellationToken);

                await factory.Received(2).CreateDelay(100, Is(cancellationToken));
            }
            public async Task StartShouldCreateWebSocketClient(
                [Frozen, Substitute] IGatewayUtilsFactory gatewayUtilsFactory,
                [Target] DefaultGatewayService gateway
                )
            {
                await gateway.StartAsync();

                gatewayUtilsFactory.Received().CreateWebSocketClient();
            }
            public async Task ShouldWaitRandomAmountOfTimeBetween1And5Seconds(
                string sessionId,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Target] DefaultGatewayRestartService service
                )
            {
                var cancellationToken = new CancellationToken(false);
                var resume            = true;

                await service.Restart(gateway, resume, cancellationToken);

                await factory.Received().CreateRandomDelay(1000, 5000, Is(cancellationToken));
            }
Пример #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();
            }