Table of Contents

Class RateLimitingTestController

Namespace
ProjectTemplate.Web.Tests.TestControllers
Assembly
ProjectTemplate.Web.Tests.dll

Provides test endpoints for demonstrating and verifying rate limiting policies in the application.

[ApiController]
[Route("test/rate-limiting")]
public sealed class RateLimitingTestController : ControllerBase
Inheritance
RateLimitingTestController
Inherited Members

Remarks

This controller exposes endpoints that are protected by different rate limiting policies, such as 'Fixed' and 'Concurrency', to facilitate testing and validation of rate limiting behavior. Intended for use in development and testing scenarios.

Methods

Concurrency(CancellationToken)

Handles a GET request to the 'concurrency' endpoint, responding after a fixed delay to simulate concurrent request handling.

[HttpGet("concurrency")]
[EnableRateLimiting("concurrency")]
public Task<IActionResult> Concurrency(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token that can be used to cancel the operation before the delay completes.

Returns

Task<IActionResult>

An IActionResult containing the result of the concurrency operation.

Remarks

This endpoint is subject to concurrency rate limiting as defined by the applied policy. The response is delayed by 750 milliseconds to simulate processing time.

Fixed()

Handles HTTP GET requests for the 'fixed' endpoint and returns a fixed result response.

[HttpGet("fixed")]
[EnableRateLimiting("fixed")]
public IActionResult Fixed()

Returns

IActionResult

An IActionResult containing a JSON object with a 'result' property set to "fixed".

Remarks

This endpoint is rate-limited according to the 'Fixed' policy defined in Fixed.

ResetConcurrencySignal()

Resets the concurrency signal to its initial state, allowing new concurrency operations to be tracked.

public static void ResetConcurrencySignal()

Remarks

Call this method to reinitialize the concurrency signal before starting a new set of concurrent operations. This is typically used in scenarios where concurrency tracking needs to be restarted or cleared.

WaitForConcurrencyRequestStartedAsync()

Waits asynchronously until a concurrency request has started or the operation times out after five seconds.

public static Task WaitForConcurrencyRequestStartedAsync()

Returns

Task

A task that completes when a concurrency request has started or the five-second timeout elapses.

Remarks

If the concurrency request does not start within five seconds, the returned task will complete in a faulted state with a timeout exception.