47 lines
1006 B
C#
47 lines
1006 B
C#
using FluentAssertions;
|
|
using FreeCode.Services;
|
|
using Xunit;
|
|
|
|
namespace FreeCode.Tests.Unit.Services;
|
|
|
|
public sealed class RateLimitServiceTests
|
|
{
|
|
private readonly RateLimitService _sut = new();
|
|
|
|
[Fact]
|
|
public void CanProceed_WithoutRetryAfterHeader_ReturnsTrue()
|
|
{
|
|
var headers = new Dictionary<string, string>();
|
|
|
|
var result = _sut.CanProceed(headers);
|
|
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void CanProceed_WithRetryAfterHeader_ReturnsFalse()
|
|
{
|
|
var headers = new Dictionary<string, string>
|
|
{
|
|
["retry-after"] = "12"
|
|
};
|
|
|
|
var result = _sut.CanProceed(headers);
|
|
|
|
result.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void GetRetryAfter_ParsesRetryAfterHeader()
|
|
{
|
|
var headers = new Dictionary<string, string>
|
|
{
|
|
["Retry-After"] = "2.5"
|
|
};
|
|
|
|
var result = _sut.GetRetryAfter(headers);
|
|
|
|
result.Should().Be(TimeSpan.FromSeconds(2.5));
|
|
}
|
|
}
|