Skip to content

Commit 632549a

Browse files
committed
first set of tests moved to ClientTestBase (auto sync/async)
1 parent 3416acf commit 632549a

35 files changed

+353
-478
lines changed

tests/Assistants/Assistants.VectorStoresTests.cs

Lines changed: 91 additions & 172 deletions
Large diffs are not rendered by default.

tests/Assistants/AssistantsTests.cs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using NUnit.Framework;
23
using OpenAI.Assistants;
34
using OpenAI.Files;
45
using OpenAI.Tests.Utility;
@@ -598,11 +599,10 @@ public async Task FunctionToolsWork()
598599
Assert.That(messages[0].Content[0].Text.ToLowerInvariant(), Does.Contain("tacos"));
599600
}
600601

602+
[AsyncOnly]
601603
[Test]
602604
public async Task StreamingRunWorksAsync()
603605
{
604-
AssertAsyncOnly();
605-
606606
AssistantClient client = GetTestClient();
607607
Assistant assistant = await client.CreateAssistantAsync("gpt-4o-mini");
608608
Validate(assistant);
@@ -648,11 +648,10 @@ AsyncCollectionResult<StreamingUpdate> streamingResult
648648
Print(">>> Done <<<");
649649
}
650650

651+
[SyncOnly]
651652
[Test]
652653
public void StreamingRunWorks()
653654
{
654-
AssertSyncOnly();
655-
656655
AssistantClient client = GetTestClient();
657656
Assistant assistant = client.CreateAssistant("gpt-4o-mini");
658657
Validate(assistant);
@@ -698,11 +697,10 @@ CollectionResult<StreamingUpdate> streamingResult
698697
Print(">>> Done <<<");
699698
}
700699

700+
[AsyncOnly]
701701
[TestCase]
702702
public async Task StreamingToolCallAsync()
703703
{
704-
AssertAsyncOnly();
705-
706704
AssistantClient client = GetTestClient();
707705
FunctionToolDefinition getWeatherTool = new("get_current_weather")
708706
{
@@ -761,11 +759,10 @@ public async Task StreamingToolCallAsync()
761759
} while (run?.Status.IsTerminal == false);
762760
}
763761

762+
[SyncOnly]
764763
[TestCase]
765764
public void StreamingToolCall()
766765
{
767-
AssertSyncOnly();
768-
769766
AssistantClient client = GetTestClient();
770767
FunctionToolDefinition getWeatherTool = new("get_current_weather")
771768
{
@@ -1027,11 +1024,10 @@ This file describes the favorite foods of several people.
10271024
});
10281025
}
10291026

1027+
[SyncOnly]
10301028
[Test]
10311029
public void FileSearchStreamingWorksSync()
10321030
{
1033-
AssertSyncOnly();
1034-
10351031
const string fileContent = """
10361032
The favorite food of several people:
10371033
- Summanus Ferdinand: tacos
@@ -1118,11 +1114,10 @@ public void FileSearchStreamingWorksSync()
11181114
Assert.That(message, Does.Contain("cake"));
11191115
}
11201116

1117+
[AsyncOnly]
11211118
[Test]
11221119
public async Task FileSearchStreamingWorksAsync()
11231120
{
1124-
AssertAsyncOnly();
1125-
11261121
const string fileContent = """
11271122
The favorite food of several people:
11281123
- Summanus Ferdinand: tacos
@@ -1211,11 +1206,10 @@ public async Task FileSearchStreamingWorksAsync()
12111206
Assert.That(message, Does.Contain("cake"));
12121207
}
12131208

1209+
[AsyncOnly]
12141210
[Test]
12151211
public async Task Pagination_CanEnumerateAssistantsAsync()
12161212
{
1217-
AssertAsyncOnly();
1218-
12191213
const int TestAssistantCount = 10;
12201214

12211215
AssistantClient client = GetTestClient();
@@ -1256,11 +1250,10 @@ public async Task Pagination_CanEnumerateAssistantsAsync()
12561250
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
12571251
}
12581252

1253+
[SyncOnly]
12591254
[Test]
12601255
public void Pagination_CanEnumerateAssistants()
12611256
{
1262-
AssertSyncOnly();
1263-
12641257
const int TestAssistantCount = 10;
12651258

12661259
AssistantClient client = GetTestClient();
@@ -1301,11 +1294,10 @@ public void Pagination_CanEnumerateAssistants()
13011294
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
13021295
}
13031296

1297+
[AsyncOnly]
13041298
[Test]
13051299
public async Task Pagination_CanPageThroughAssistantCollectionAsync()
13061300
{
1307-
AssertAsyncOnly();
1308-
13091301
const int TestAssistantCount = 10;
13101302
const int TestPageSizeLimit = 2;
13111303

@@ -1359,11 +1351,10 @@ public async Task Pagination_CanPageThroughAssistantCollectionAsync()
13591351
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
13601352
}
13611353

1354+
[SyncOnly]
13621355
[Test]
13631356
public void Pagination_CanPageThroughAssistantCollection()
13641357
{
1365-
AssertSyncOnly();
1366-
13671358
const int TestAssistantCount = 10;
13681359
const int TestPageSizeLimit = 2;
13691360

@@ -1427,11 +1418,10 @@ private static IEnumerable<Assistant> GetAssistantsFromPage(ClientResult page)
14271418
return els.Select(el => ModelReaderWriter.Read<Assistant>(BinaryData.FromString(el.GetRawText())));
14281419
}
14291420

1421+
[AsyncOnly]
14301422
[Test]
14311423
public async Task Pagination_CanRehydrateAssistantPageCollectionFromBytesAsync()
14321424
{
1433-
AssertAsyncOnly();
1434-
14351425
const int TestAssistantCount = 10;
14361426
const int TestPageSizeLimit = 2;
14371427

@@ -1495,11 +1485,10 @@ public async Task Pagination_CanRehydrateAssistantPageCollectionFromBytesAsync()
14951485
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
14961486
}
14971487

1488+
[SyncOnly]
14981489
[Test]
14991490
public void Pagination_CanRehydrateAssistantPageCollectionFromBytes()
15001491
{
1501-
AssertSyncOnly();
1502-
15031492
const int TestAssistantCount = 10;
15041493
const int TestPageSizeLimit = 2;
15051494

@@ -1564,11 +1553,10 @@ public void Pagination_CanRehydrateAssistantPageCollectionFromBytes()
15641553
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
15651554
}
15661555

1556+
[AsyncOnly]
15671557
[Test]
15681558
public async Task Pagination_CanRehydrateAssistantPageCollectionFromPageTokenAsync()
15691559
{
1570-
AssertAsyncOnly();
1571-
15721560
const int TestAssistantCount = 10;
15731561
const int TestPageSizeLimit = 2;
15741562

@@ -1643,11 +1631,10 @@ public async Task Pagination_CanRehydrateAssistantPageCollectionFromPageTokenAsy
16431631
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
16441632
}
16451633

1634+
[SyncOnly]
16461635
[Test]
16471636
public void Pagination_CanRehydrateAssistantPageCollectionFromPageToken()
16481637
{
1649-
AssertSyncOnly();
1650-
16511638
const int TestAssistantCount = 10;
16521639
const int TestPageSizeLimit = 2;
16531640

@@ -1721,11 +1708,10 @@ public void Pagination_CanRehydrateAssistantPageCollectionFromPageToken()
17211708
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
17221709
}
17231710

1711+
[AsyncOnly]
17241712
[Test]
17251713
public async Task Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocolAsync()
17261714
{
1727-
AssertAsyncOnly();
1728-
17291715
const int TestAssistantCount = 10;
17301716
const int TestPageSizeLimit = 2;
17311717

@@ -1771,11 +1757,10 @@ public async Task Pagination_CanCastAssistantPageCollectionToConvenienceFromProt
17711757
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
17721758
}
17731759

1760+
[SyncOnly]
17741761
[Test]
17751762
public void Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocol()
17761763
{
1777-
AssertSyncOnly();
1778-
17791764
const int TestAssistantCount = 10;
17801765
const int TestPageSizeLimit = 2;
17811766

@@ -1821,11 +1806,10 @@ public void Pagination_CanCastAssistantPageCollectionToConvenienceFromProtocol()
18211806
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
18221807
}
18231808

1809+
[AsyncOnly]
18241810
[Test]
18251811
public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytesAsync()
18261812
{
1827-
AssertAsyncOnly();
1828-
18291813
AssistantClient client = GetTestClient();
18301814
Assistant assistant = client.CreateAssistant("gpt-4o", new AssistantCreationOptions()
18311815
{
@@ -1896,11 +1880,10 @@ public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytesAsync()
18961880
Assert.That(rehydratedRunSteps, Is.EqualTo(runSteps).AsCollection);
18971881
}
18981882

1883+
[SyncOnly]
18991884
[Test]
19001885
public void Pagination_CanRehydrateRunStepPageCollectionFromBytes()
19011886
{
1902-
AssertSyncOnly();
1903-
19041887
AssistantClient client = GetTestClient();
19051888
Assistant assistant = client.CreateAssistant("gpt-4o", new AssistantCreationOptions()
19061889
{

tests/Audio/GenerateSpeechMockTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ClientModel;
33
using System.Threading;
4+
using Microsoft.ClientModel.TestFramework;
45
using NUnit.Framework;
56
using OpenAI.Audio;
67
using OpenAI.Tests.Utility;

tests/Audio/GenerateSpeechTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using NUnit.Framework;
23
using OpenAI.Audio;
34
using OpenAI.Tests.Utility;
45
using System;

tests/Audio/TranscriptionMockTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Microsoft.ClientModel.TestFramework;
8+
using Microsoft.ClientModel.TestFramework.Mocks;
79
using NUnit.Framework;
810
using OpenAI.Audio;
911
using OpenAI.Tests.Utility;
@@ -160,12 +162,11 @@ public void TranscribeAudioFromStreamRespectsTheCancellationToken()
160162

161163
private OpenAIClientOptions GetClientOptionsWithMockResponse(int status, string content)
162164
{
163-
MockPipelineResponse response = new MockPipelineResponse(status);
164-
response.SetContent(content);
165+
MockPipelineResponse response = new MockPipelineResponse(status).WithContent(content);
165166

166167
return new OpenAIClientOptions()
167168
{
168-
Transport = new MockPipelineTransport(response)
169+
Transport = new MockPipelineTransport(_ => response)
169170
};
170171
}
171172

tests/Audio/TranscriptionTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using NUnit.Framework;
23
using OpenAI.Audio;
34
using OpenAI.Tests.Utility;
45
using System;

tests/Audio/TranslationMockTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Threading;
66
using System.Threading.Tasks;
7+
using Microsoft.ClientModel.TestFramework;
8+
using Microsoft.ClientModel.TestFramework.Mocks;
79
using NUnit.Framework;
810
using OpenAI.Audio;
911
using OpenAI.Tests.Utility;
@@ -136,12 +138,11 @@ public void TranslateAudioFromStreamRespectsTheCancellationToken()
136138

137139
private OpenAIClientOptions GetClientOptionsWithMockResponse(int status, string content = null)
138140
{
139-
MockPipelineResponse response = new MockPipelineResponse(status);
140-
response.SetContent(content ?? "{}");
141+
MockPipelineResponse response = new MockPipelineResponse(status).WithContent(content ?? "{}");
141142

142143
return new OpenAIClientOptions()
143144
{
144-
Transport = new MockPipelineTransport(response)
145+
Transport = new MockPipelineTransport(_ => response)
145146
};
146147
}
147148

tests/Audio/TranslationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using NUnit.Framework;
23
using OpenAI.Audio;
34
using OpenAI.Tests.Utility;
45
using System;

tests/Batch/BatchTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using NUnit.Framework;
23
using OpenAI.Batch;
34
using OpenAI.Files;
45
using OpenAI.Tests.Utility;
@@ -24,11 +25,10 @@ public BatchTests(bool isAsync) : base(isAsync)
2425
{
2526
}
2627

28+
[SyncOnly]
2729
[Test]
2830
public void ListBatchesProtocol()
2931
{
30-
AssertSyncOnly();
31-
3232
BatchClient client = GetTestClient();
3333
CollectionResult batches = client.GetBatches(after: null, limit: null, options: null);
3434

@@ -56,11 +56,10 @@ public void ListBatchesProtocol()
5656
Assert.That(pageCount, Is.GreaterThanOrEqualTo(1));
5757
}
5858

59+
[AsyncOnly]
5960
[Test]
6061
public async Task ListBatchesProtocolAsync()
6162
{
62-
AssertAsyncOnly();
63-
6463
BatchClient client = GetTestClient();
6564
AsyncCollectionResult batches = client.GetBatchesAsync(after: null, limit: null, options: null);
6665

tests/Chat/ChatMockTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClientModel.TestFramework;
2+
using Microsoft.ClientModel.TestFramework.Mocks;
3+
using NUnit.Framework;
24
using OpenAI.Chat;
35
using OpenAI.Tests.Utility;
46
using System;
@@ -217,11 +219,10 @@ public void CompleteChatRespectsTheCancellationToken()
217219
}
218220
}
219221

222+
[AsyncOnly]
220223
[Test]
221224
public void CompleteChatStreamingAsyncRespectsTheCancellationToken()
222225
{
223-
AssertAsyncOnly();
224-
225226
ChatClient client = new ChatClient("model", s_fakeCredential);
226227
using CancellationTokenSource cancellationSource = new();
227228
cancellationSource.Cancel();
@@ -233,11 +234,10 @@ public void CompleteChatStreamingAsyncRespectsTheCancellationToken()
233234
Assert.That(async () => await enumerator.MoveNextAsync(), Throws.InstanceOf<OperationCanceledException>());
234235
}
235236

237+
[SyncOnly]
236238
[Test]
237239
public void CompleteChatStreamingRespectsTheCancellationToken()
238240
{
239-
AssertSyncOnly();
240-
241241
ChatClient client = new ChatClient("model", s_fakeCredential);
242242
using CancellationTokenSource cancellationSource = new();
243243
cancellationSource.Cancel();
@@ -273,12 +273,11 @@ private async ValueTask<StreamingChatCompletionUpdate> InvokeCompleteChatStreami
273273

274274
private OpenAIClientOptions GetClientOptionsWithMockResponse(int status, string content)
275275
{
276-
MockPipelineResponse response = new MockPipelineResponse(status);
277-
response.SetContent(content);
276+
MockPipelineResponse response = new MockPipelineResponse(status).WithContent(content);
278277

279278
return new OpenAIClientOptions()
280279
{
281-
Transport = new MockPipelineTransport(response)
280+
Transport = new MockPipelineTransport(_ => response)
282281
};
283282
}
284283
}

0 commit comments

Comments
 (0)