Add file operations example and complete file support implementation
Co-authored-by: StevanFreeborn <65925598+StevanFreeborn@users.noreply.github.com>
This commit is contained in:
co-authored by
StevanFreeborn
parent
84ce38a586
commit
9a63dec2b9
@@ -161,59 +161,4 @@ public class AnthropicApiClientFileTests : IntegrationTest
|
||||
result.Error.Should().BeOfType<AnthropicError>();
|
||||
result.Error.Error.Should().BeOfType<InvalidRequestError>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ListAllFilesAsync_WhenCalled_ItShouldReturnAllPages()
|
||||
{
|
||||
var firstPageJson = @"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""file"",
|
||||
""id"": ""file_abc123"",
|
||||
""filename"": ""example1.txt"",
|
||||
""content_type"": ""text/plain"",
|
||||
""size_bytes"": 1024,
|
||||
""created_at"": ""2024-03-15T10:30:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": true,
|
||||
""first_id"": ""file_abc123"",
|
||||
""last_id"": ""file_abc123""
|
||||
}";
|
||||
|
||||
var secondPageJson = @"{
|
||||
""data"": [
|
||||
{
|
||||
""type"": ""file"",
|
||||
""id"": ""file_def456"",
|
||||
""filename"": ""example2.txt"",
|
||||
""content_type"": ""text/plain"",
|
||||
""size_bytes"": 2048,
|
||||
""created_at"": ""2024-03-15T11:30:00Z""
|
||||
}
|
||||
],
|
||||
""has_more"": false,
|
||||
""first_id"": ""file_def456"",
|
||||
""last_id"": ""file_def456""
|
||||
}";
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenListFilesRequest()
|
||||
.Respond(HttpStatusCode.OK, "application/json", firstPageJson);
|
||||
|
||||
_mockHttpMessageHandler
|
||||
.WhenListFilesRequest()
|
||||
.Respond(HttpStatusCode.OK, "application/json", secondPageJson);
|
||||
|
||||
var pages = new List<AnthropicResult<Page<AnthropicFile>>>();
|
||||
await foreach (var page in Client.ListAllFilesAsync(1))
|
||||
{
|
||||
pages.Add(page);
|
||||
}
|
||||
|
||||
pages.Should().HaveCount(2);
|
||||
pages.All(p => p.IsSuccess).Should().BeTrue();
|
||||
pages[0].Value!.Data[0].Id.Should().Be("file_abc123");
|
||||
pages[1].Value!.Data[0].Id.Should().Be("file_def456");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user