diff --git a/src/AnthropicClient/Models/PagingRequest.cs b/src/AnthropicClient/Models/PagingRequest.cs index f8b415a..52746df 100644 --- a/src/AnthropicClient/Models/PagingRequest.cs +++ b/src/AnthropicClient/Models/PagingRequest.cs @@ -34,6 +34,7 @@ public class PagingRequest /// The ID of the item before which to start the page. /// The ID of the item after which to start the page. /// The maximum number of items to return in the page. + /// Thrown when both and are specified. /// Thrown when is less than 1 or greater than 1000. /// A new instance of the class. public PagingRequest( @@ -47,6 +48,11 @@ public class PagingRequest throw new ArgumentOutOfRangeException(nameof(limit), $"{nameof(limit)} must be between {LimitMinimum} and {LimitMaximum}."); } + if (string.IsNullOrEmpty(beforeId) is false && string.IsNullOrEmpty(afterId) is false) + { + throw new ArgumentException($"Only one of {nameof(beforeId)} or {nameof(afterId)} can be set."); + } + BeforeId = beforeId; AfterId = afterId; Limit = limit; diff --git a/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs index 8c8f0b3..eaef353 100644 --- a/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs +++ b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs @@ -549,13 +549,12 @@ public class AnthropicApiClientTests : IntegrationTest [Fact] public async Task ListModelsAsync_WhenCalledWithPagingRequestUsingCustomValues_ItShouldReturnListOfModels() { - var pagingRequest = new PagingRequest("prev_id", "next_id", 10); + var pagingRequest = new PagingRequest(afterId: "next_id", limit: 10); _mockHttpMessageHandler .WhenListModelsRequest() .WithQueryString(new Dictionary { - { "before_id", pagingRequest.BeforeId }, { "after_id", pagingRequest.AfterId }, { "limit", pagingRequest.Limit.ToString() }, }) diff --git a/tests/AnthropicClient.Tests/Unit/Models/PagingRequestTests.cs b/tests/AnthropicClient.Tests/Unit/Models/PagingRequestTests.cs index 069120c..b63599b 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/PagingRequestTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/PagingRequestTests.cs @@ -18,6 +18,14 @@ public class PagingRequestTests : SerializationTest act.Should().Throw().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')"); } + [Fact] + public void Constructor_WhenBothBeforeIdAndAfterIdAreSet_ItShouldThrowArgumentException() + { + var act = () => new PagingRequest(beforeId: "before-id", afterId: "after-id"); + + act.Should().Throw().WithMessage("Only one of beforeId or afterId can be set."); + } + [Fact] public void ToQueryParameters_WhenNoPropertiesSet_ItShouldReturnEmptyString() { @@ -57,14 +65,4 @@ public class PagingRequestTests : SerializationTest result.Should().Be("limit=10"); } - - [Fact] - public void ToQueryParameters_WhenAllPropertiesAreSet_ItShouldReturnAllProperties() - { - var pagingRequest = new PagingRequest(beforeId: "before-id", afterId: "after-id", limit: 10); - - var result = pagingRequest.ToQueryParameters(); - - result.Should().Be("before_id=before-id&after_id=after-id&limit=10"); - } } \ No newline at end of file