fix: only allow afterId or beforeId to be set. not both at same time.
This commit is contained in:
@@ -34,6 +34,7 @@ public class PagingRequest
|
|||||||
/// <param name="beforeId">The ID of the item before which to start the page.</param>
|
/// <param name="beforeId">The ID of the item before which to start the page.</param>
|
||||||
/// <param name="afterId">The ID of the item after which to start the page.</param>
|
/// <param name="afterId">The ID of the item after which to start the page.</param>
|
||||||
/// <param name="limit">The maximum number of items to return in the page.</param>
|
/// <param name="limit">The maximum number of items to return in the page.</param>
|
||||||
|
/// <exception cref="ArgumentException">Thrown when both <paramref name="beforeId"/> and <paramref name="afterId"/> are specified.</exception>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="limit"/> is less than 1 or greater than 1000.</exception>
|
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="limit"/> is less than 1 or greater than 1000.</exception>
|
||||||
/// <returns>A new instance of the <see cref="PagingRequest"/> class.</returns>
|
/// <returns>A new instance of the <see cref="PagingRequest"/> class.</returns>
|
||||||
public PagingRequest(
|
public PagingRequest(
|
||||||
@@ -47,6 +48,11 @@ public class PagingRequest
|
|||||||
throw new ArgumentOutOfRangeException(nameof(limit), $"{nameof(limit)} must be between {LimitMinimum} and {LimitMaximum}.");
|
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;
|
BeforeId = beforeId;
|
||||||
AfterId = afterId;
|
AfterId = afterId;
|
||||||
Limit = limit;
|
Limit = limit;
|
||||||
|
|||||||
@@ -549,13 +549,12 @@ public class AnthropicApiClientTests : IntegrationTest
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task ListModelsAsync_WhenCalledWithPagingRequestUsingCustomValues_ItShouldReturnListOfModels()
|
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
|
_mockHttpMessageHandler
|
||||||
.WhenListModelsRequest()
|
.WhenListModelsRequest()
|
||||||
.WithQueryString(new Dictionary<string, string>
|
.WithQueryString(new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "before_id", pagingRequest.BeforeId },
|
|
||||||
{ "after_id", pagingRequest.AfterId },
|
{ "after_id", pagingRequest.AfterId },
|
||||||
{ "limit", pagingRequest.Limit.ToString() },
|
{ "limit", pagingRequest.Limit.ToString() },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ public class PagingRequestTests : SerializationTest
|
|||||||
act.Should().Throw<ArgumentOutOfRangeException>().WithMessage("limit must be between 1 and 1000. (Parameter 'limit')");
|
act.Should().Throw<ArgumentOutOfRangeException>().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<ArgumentException>().WithMessage("Only one of beforeId or afterId can be set.");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQueryParameters_WhenNoPropertiesSet_ItShouldReturnEmptyString()
|
public void ToQueryParameters_WhenNoPropertiesSet_ItShouldReturnEmptyString()
|
||||||
{
|
{
|
||||||
@@ -57,14 +65,4 @@ public class PagingRequestTests : SerializationTest
|
|||||||
|
|
||||||
result.Should().Be("limit=10");
|
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user