2025-01-05 16:57:13 -06:00
|
|
|
namespace AnthropicClient.Tests.Unit.Models;
|
|
|
|
|
|
|
|
|
|
public class PagingRequestTests : SerializationTest
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Constructor_WhenLimitIsLessThanMinimum_ItShouldThrowArgumentOutOfRangeException()
|
|
|
|
|
{
|
|
|
|
|
var act = () => new PagingRequest(limit: 0);
|
|
|
|
|
|
|
|
|
|
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Constructor_WhenLimitIsGreaterThanMaximum_ItShouldThrowArgumentOutOfRangeException()
|
|
|
|
|
{
|
|
|
|
|
var act = () => new PagingRequest(limit: 1001);
|
|
|
|
|
|
|
|
|
|
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')");
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 21:55:53 -06:00
|
|
|
[Fact]
|
|
|
|
|
public void Constructor_WhenBothBeforeIdAndAfterIdAreSet_ItShouldThrowArgumentException()
|
|
|
|
|
{
|
|
|
|
|
var act = () => new PagingRequest(beforeId: "before-id", afterId: "after-id");
|
|
|
|
|
|
|
|
|
|
act.Should().Throw<ArgumentException>().WithMessage("Only one of beforeId or afterId can be set.");
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 16:57:13 -06:00
|
|
|
[Fact]
|
|
|
|
|
public void ToQueryParameters_WhenNoPropertiesSet_ItShouldReturnEmptyString()
|
|
|
|
|
{
|
|
|
|
|
var pagingRequest = new PagingRequest();
|
|
|
|
|
|
|
|
|
|
var result = pagingRequest.ToQueryParameters();
|
|
|
|
|
|
2025-01-05 21:20:27 -06:00
|
|
|
result.Should().Be("limit=20");
|
2025-01-05 16:57:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ToQueryParameters_WhenBeforeIdIsSet_ItShouldReturnBeforeId()
|
|
|
|
|
{
|
|
|
|
|
var pagingRequest = new PagingRequest(beforeId: "before-id");
|
|
|
|
|
|
|
|
|
|
var result = pagingRequest.ToQueryParameters();
|
|
|
|
|
|
2025-01-05 21:20:27 -06:00
|
|
|
result.Should().Be("before_id=before-id&limit=20");
|
2025-01-05 16:57:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ToQueryParameters_WhenAfterIdIsSet_ItShouldReturnAfterId()
|
|
|
|
|
{
|
|
|
|
|
var pagingRequest = new PagingRequest(afterId: "after-id");
|
|
|
|
|
|
|
|
|
|
var result = pagingRequest.ToQueryParameters();
|
|
|
|
|
|
2025-01-05 21:20:27 -06:00
|
|
|
result.Should().Be("after_id=after-id&limit=20");
|
2025-01-05 16:57:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ToQueryParameters_WhenLimitIsSetToNonDefaultValue_ItShouldReturnLimit()
|
|
|
|
|
{
|
|
|
|
|
var pagingRequest = new PagingRequest(limit: 10);
|
|
|
|
|
|
|
|
|
|
var result = pagingRequest.ToQueryParameters();
|
|
|
|
|
|
|
|
|
|
result.Should().Be("limit=10");
|
|
|
|
|
}
|
|
|
|
|
}
|