コード例 #1
0
            public async Task StartShouldCreateWorker(
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Target] DefaultGatewayService gateway
                )
            {
                await gateway.StartAsync();

                timerFactory.Received().CreateTimer(Is((AsyncTimerCallback)gateway.Run), Is(0), Is("Gateway Master"));
            }
コード例 #2
0
            public async Task ShouldJitter(
                Request request,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Target] DefaultBucketService service,
                CancellationToken cancellationToken
                )
            {
                await service.GetBucketAndWaitForAvailability(request, cancellationToken);

                await timerFactory.Received().CreateJitter(Is(cancellationToken));
            }
コード例 #3
0
            public async Task StartShouldCreateTimer(
                [Substitute] IClientWebSocket clientWebSocket,
                [Frozen, Substitute] IGatewayService gateway,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Target] DefaultGatewayTxWorker txWorker
                )
            {
                await txWorker.Start(gateway, clientWebSocket);

                timerFactory.Received().CreateTimer(Is((AsyncTimerCallback)txWorker.Run), Is(0), Is("Gateway TX"));
            }
コード例 #4
0
            public async Task StartShouldCreateWorkerThread(
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Frozen, Substitute] IGatewayService gateway,
                [Target] DefaultGatewayRxWorker rxWorker
                )
            {
                var cancellationToken = new CancellationToken(false);
                await rxWorker.Start(gateway);

                timerFactory.Received().CreateTimer(Is((AsyncTimerCallback)rxWorker.Run), Is(0), Is("Gateway RX"));
            }
コード例 #5
0
            public async Task ShouldCreateAndStartANewTimer(
                [Frozen] RequestOptions options,
                [Frozen] ITimer timer,
                [Frozen] ITimerFactory timerFactory,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                await worker.StartAsync(cancellationToken);

                timerFactory.Received().CreateTimer(Is <AsyncTimerCallback>(worker.Run), Is(options.PollingInterval), Is(nameof(DefaultRequestWorker)));
                await timer.Received().Start();
            }
コード例 #6
0
            public async Task ShouldDelayUntilResetAfterIsReachedIfHitsRemainingIsZero(
                int secondsToWait,
                Request request,
                [Frozen] Bucket bucket,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Frozen, Substitute] IBucketRepository repository,
                [Target] DefaultBucketService service,
                CancellationToken cancellationToken
                )
            {
                bucket.HitsRemaining = 0;
                bucket.ResetAfter    = DateTimeOffset.Now + TimeSpan.FromSeconds(secondsToWait);
                await service.GetBucketAndWaitForAvailability(request, cancellationToken);

                await timerFactory.Received().CreateDelay(Is <int>(ms => ms >= (secondsToWait * 1000) - 20), Is(cancellationToken));
            }
コード例 #7
0
            public async Task ShouldStartSendingAHeartbeatToTheTxWorker(
                uint interval,
                int sequenceNumber,
                [Frozen] ITimer timer,
                [Frozen, Substitute] IGatewayUtilsFactory factory,
                [Frozen, Substitute] IGatewayTxWorker txWorker,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Target] DefaultGatewayService gateway
                )
            {
                var cancellationToken = new CancellationToken(false);

                gateway.SequenceNumber = sequenceNumber;
                await gateway.StartAsync();

                await gateway.StartHeartbeat(interval);

                timerFactory.Received().CreateTimer(Is <AsyncTimerCallback>(gateway.Heartbeat), Is((int)interval), Is("Heartbeat"));
                await timer.Received().Start();
            }
コード例 #8
0
 public void TimerFactory_Always_StartsATimer()
 {
     timerFactory.Received().Start(1000, Arg.Any <Action>());
 }