コード例 #1
0
            public async Task ShouldNotDecreaseTheNumberOfHitsByOneIfHitsRemainingIsZero(
                Request request,
                [Frozen] Bucket bucket,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Frozen, Substitute] IBucketRepository repository,
                [Target] DefaultBucketService service,
                CancellationToken cancellationToken
                )
            {
                bucket.HitsRemaining = 0;
                var result = await service.GetBucketAndWaitForAvailability(request, cancellationToken);

                result.HitsRemaining.Should().Be(0);
            }
コード例 #2
0
            public async Task ShouldNotDelayIfHitsRemainingIsNotZero(
                Request request,
                [Frozen] Bucket bucket,
                [Frozen, Substitute] ITimerFactory timerFactory,
                [Frozen, Substitute] IBucketRepository repository,
                [Target] DefaultBucketService service,
                CancellationToken cancellationToken
                )
            {
                bucket.HitsRemaining = 1;
                await service.GetBucketAndWaitForAvailability(request, cancellationToken);

                await timerFactory.DidNotReceive().CreateDelay(Is((int)Math.Ceiling((bucket.ResetAfter - DateTimeOffset.Now).TotalMilliseconds)), Is(cancellationToken));
            }
コード例 #3
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));
            }
コード例 #4
0
            public async Task ShouldNotCreateNewBucketIfOneWasFound(
                Request request,
                [Frozen] Bucket bucket,
                [Frozen, Substitute] IBucketRepository repository,
                [Target] DefaultBucketService service,
                CancellationToken cancellationToken
                )
            {
                await service.GetBucketAndWaitForAvailability(request, cancellationToken);

                await repository.DidNotReceive().Add(
                    Is <Bucket>(bucket =>
                                bucket.Endpoints == Convert.ToUInt64(request.Endpoint.Value) &&
                                bucket.ApiCategory == request.Endpoint.Category &&
                                bucket.MajorParameters == request.Parameters &&
                                bucket.HitsRemaining == 1
                                ),
                    Is(cancellationToken)
                    );
            }