Skip to content

Commit

Permalink
.Net: Bugfix - ACA Sessions - Code Interpreter Demo (microsoft#7899)
Browse files Browse the repository at this point in the history
# Motivation

Resolves microsoft#7429

- microsoft#7429

---------

Co-authored-by: Roger Barreto <rbarreto@microsoft.com>
  • Loading branch information
RogerBarreto and rogerio-barreto committed Aug 6, 2024
1 parent e867457 commit a41bb91
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task<SessionsRemoteFileMetadata> UploadFileAsync(
await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

using var fileContent = new ByteArrayContent(File.ReadAllBytes(localFilePath));
using var request = new HttpRequestMessage(HttpMethod.Post, $"{this._poolManagementEndpoint}python/uploadFile?identifier={this._settings.SessionId}&api-version={ApiVersion}")
using var request = new HttpRequestMessage(HttpMethod.Post, $"{this._poolManagementEndpoint}files/upload?identifier={this._settings.SessionId}&api-version={ApiVersion}")
{
Content = new MultipartFormDataContent
{
Expand All @@ -173,7 +173,7 @@ public async Task<SessionsRemoteFileMetadata> UploadFileAsync(

var JsonElementResult = JsonSerializer.Deserialize<JsonElement>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));

return JsonSerializer.Deserialize<SessionsRemoteFileMetadata>(JsonElementResult.GetProperty("$values")[0].GetRawText())!;
return JsonSerializer.Deserialize<SessionsRemoteFileMetadata>(JsonElementResult.GetProperty("value")[0].GetProperty("properties").GetRawText())!;
}

/// <summary>
Expand Down Expand Up @@ -230,7 +230,7 @@ public async Task<IReadOnlyList<SessionsRemoteFileMetadata>> ListFilesAsync()
using var httpClient = this._httpClientFactory.CreateClient();
await this.AddHeadersAsync(httpClient).ConfigureAwait(false);

var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}python/files?identifier={this._settings.SessionId}&api-version={ApiVersion}")).ConfigureAwait(false);
var response = await httpClient.GetAsync(new Uri($"{this._poolManagementEndpoint}/files?identifier={this._settings.SessionId}&api-version={ApiVersion}")).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
Expand All @@ -239,13 +239,13 @@ public async Task<IReadOnlyList<SessionsRemoteFileMetadata>> ListFilesAsync()

var jsonElementResult = JsonSerializer.Deserialize<JsonElement>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));

var files = jsonElementResult.GetProperty("$values");
var files = jsonElementResult.GetProperty("value");

var result = new SessionsRemoteFileMetadata[files.GetArrayLength()];

for (var i = 0; i < result.Length; i++)
{
result[i] = JsonSerializer.Deserialize<SessionsRemoteFileMetadata>(files[i].GetRawText())!;
result[i] = JsonSerializer.Deserialize<SessionsRemoteFileMetadata>(files[i].GetProperty("properties").GetRawText())!;
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SessionsRemoteFileMetadata(string filename, int size)
/// The last modified time.
/// </summary>
[Description("Last modified time.")]
[JsonPropertyName("last_modified_time")]
[JsonPropertyName("lastModifiedTime")]
public DateTime? LastModifiedTime { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ public async Task ItShouldListFilesAsync()

// Assert
Assert.Contains<SessionsRemoteFileMetadata>(result, (item) =>
item.Filename == "test.txt" &&
item.Size == 680 &&
item.LastModifiedTime!.Value.Ticks == 638508470494918207);
item.Filename == "test-file.txt" &&
item.Size == 516 &&
item.LastModifiedTime!.Value.Ticks == 638585580822423944);

Assert.Contains<SessionsRemoteFileMetadata>(result, (item) =>
item.Filename == "test2.txt" &&
item.Size == 1074 &&
item.LastModifiedTime!.Value.Ticks == 638508471084916062);
item.Filename == "test-file2.txt" &&
item.Size == 211 &&
item.LastModifiedTime!.Value.Ticks == 638585580822423944);
}

[Fact]
Expand All @@ -210,9 +210,9 @@ public async Task ItShouldUploadFileAsync()
var responseContent = await File.ReadAllTextAsync(UpdaloadFileTestDataFilePath);
var requestPayload = await File.ReadAllBytesAsync(FileTestDataFilePath);

var expectedResponse = new SessionsRemoteFileMetadata("test.txt", 680)
var expectedResponse = new SessionsRemoteFileMetadata("test-file.txt", 516)
{
LastModifiedTime = new DateTime(638508470494918207),
LastModifiedTime = new DateTime(638585526384228269)
};

this._messageHandlerStub.ResponseToReturn = new HttpResponseMessage(HttpStatusCode.OK)
Expand All @@ -223,7 +223,7 @@ public async Task ItShouldUploadFileAsync()
var plugin = new SessionsPythonPlugin(this._defaultSettings, this._httpClientFactory);

// Act
var result = await plugin.UploadFileAsync(".test.txt", FileTestDataFilePath);
var result = await plugin.UploadFileAsync("test-file.txt", FileTestDataFilePath);

// Assert
Assert.Equal(result.Filename, expectedResponse.Filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{
"$id": "1",
"$values": [
"value": [
{
"$id": "2",
"filename": "test2.txt",
"size": 1074,
"last_modified_time": "2024-05-09T10:25:08.4916062Z"
"properties": {
"$id": "3",
"filename": "test-file.txt",
"size": 516,
"lastModifiedTime": "2024-08-06T16:21:22.2423944Z"
}
},
{
"$id": "3",
"filename": "test.txt",
"size": 680,
"last_modified_time": "2024-05-09T10:24:09.4918207Z"
"$id": "4",
"properties": {
"$id": "5",
"filename": "test-file2.txt",
"size": 211,
"lastModifiedTime": "2024-08-06T16:21:22.2423944Z"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"$id": "1",
"$values": [
"value": [
{
"$id": "2",
"filename": "test.txt",
"size": 680,
"last_modified_time": "2024-05-09T10:24:09.4918207Z"
"properties": {
"$id": "3",
"filename": "test-file.txt",
"size": 516,
"lastModifiedTime": "2024-08-06T14:50:38.4228269Z"
}
}
]
}

0 comments on commit a41bb91

Please sign in to comment.