-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afd7d03
commit 0a3411d
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Standard.AI.OpenAI.Tests.Acceptance/Clients/AIFiles/AIFilesClientTests.UploadFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright (c) The Standard Organization, a coalition of the Good-Hearted Engineers | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Force.DeepCloner; | ||
using Standard.AI.OpenAI.Models.Services.Foundations.AIFiles; | ||
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIFiles; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Standard.AI.OpenAI.Tests.Acceptance.Clients.AIFiles | ||
{ | ||
public partial class AIFilesClientTests | ||
{ | ||
[Fact] | ||
public async Task ShouldUploadFileAsync() | ||
{ | ||
AIFileRequest randomAIFileRequest = | ||
CreateRandomAIFileRequest(); | ||
|
||
var uploadAIFileRequest = new AIFile | ||
{ | ||
Request = randomAIFileRequest | ||
}; | ||
|
||
ExternalAIFileRequest externalAIFileRequest = | ||
ConvertToExternalAIFileRequest(uploadAIFileRequest.Request); | ||
|
||
ExternalAIFileResponse externalAIFileResponse = | ||
CreateExternalAiFileResponseOnUpload(externalAIFileRequest); | ||
|
||
AIFileResponse aiFileResponse = | ||
ConvertToAIFileResponse(externalAIFileResponse); | ||
|
||
AIFile expectedAIFile = uploadAIFileRequest.DeepClone(); | ||
expectedAIFile.Response = aiFileResponse; | ||
|
||
this.wireMockServer.Given( | ||
Request.Create() | ||
.UsingPost() | ||
.WithPath("/v1/files") | ||
.WithHeader("Authorization", $"Bearer {this.apiKey}") | ||
.WithHeader("OpenAI-Organization", this.organizationId)) | ||
.RespondWith( | ||
Response.Create() | ||
.WithBodyAsJson(externalAIFileResponse)); | ||
|
||
// when | ||
AIFile actualAIFile = | ||
await this.openAIClient.AIFiles.UploadFileAsync(uploadAIFileRequest); | ||
|
||
// then | ||
actualAIFile.Should().BeEquivalentTo(expectedAIFile); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters