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); }
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)); }
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)); }
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) ); }