Skip to content

Commit 9b68313

Browse files
committed
tests: upgrades to xunit v3
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent a32c1da commit 9b68313

107 files changed

Lines changed: 727 additions & 734 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="coverlet.msbuild" Version="10.0.1" PrivateAssets="all" />
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
1818
<PackageReference Include="Moq" Version="4.20.72" />
19-
<PackageReference Include="xunit" Version="2.9.3" />
19+
<PackageReference Include="xunit.v3" Version="3.2.2" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
2121
<PackageReference Include="coverlet.collector" Version="10.0.1" PrivateAssets="all" />
2222
</ItemGroup>

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly(
298298
using var stream = File.OpenRead(filePath);
299299
var settings = new OpenApiReaderSettings();
300300
settings.AddYamlReader();
301-
var doc = (await OpenApiDocument.LoadAsync(stream, "yaml", settings)).Document;
301+
var doc = (await OpenApiDocument.LoadAsync(stream, "yaml", settings, TestContext.Current.CancellationToken)).Document;
302302

303303
// validated the tags are read as references
304304
var openApiOperationTags = doc?.Paths["/items"].Operations?[HttpMethod.Get].Tags?.ToArray();
@@ -344,7 +344,7 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly(
344344
}
345345
};
346346
subsetOpenApiDocument.SerializeAsV3(writer);
347-
await writer.FlushAsync();
347+
await writer.FlushAsync(TestContext.Current.CancellationToken);
348348
var result = outputStringWriter.ToString();
349349
Assert.NotEmpty(result);
350350
}

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ public async Task ShowCommandGeneratesMermaidMarkdownFileWithMermaidDiagramAsync
138138
Output = new("sample.md")
139139
};
140140

141-
await OpenApiService.ShowOpenApiDocumentAsync(options, _logger);
141+
await OpenApiService.ShowOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
142142

143-
var output = await File.ReadAllTextAsync(options.Output.FullName);
143+
var output = await File.ReadAllTextAsync(options.Output.FullName, TestContext.Current.CancellationToken);
144144
Assert.Contains("graph LR", output, StringComparison.Ordinal);
145145
}
146146

@@ -151,52 +151,52 @@ public async Task ShowCommandGeneratesMermaidHtmlFileWithMermaidDiagramAsync()
151151
{
152152
OpenApi = Path.Combine("UtilityFiles", "SampleOpenApi.yml")
153153
};
154-
var filePath = await OpenApiService.ShowOpenApiDocumentAsync(options, _logger);
154+
var filePath = await OpenApiService.ShowOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
155155
Assert.True(File.Exists(filePath));
156156
}
157157

158158
[Fact]
159159
public Task ThrowIfOpenApiUrlIsNotProvidedWhenValidatingAsync()
160160
{
161161
return Assert.ThrowsAsync<ArgumentNullException>(() =>
162-
OpenApiService.ValidateOpenApiDocumentAsync("", _logger));
162+
OpenApiService.ValidateOpenApiDocumentAsync("", _logger, TestContext.Current.CancellationToken));
163163
}
164164

165165
[Fact]
166166
public Task ThrowIfURLIsNotResolvableWhenValidatingAsync()
167167
{
168168
return Assert.ThrowsAsync<InvalidOperationException>(() =>
169-
OpenApiService.ValidateOpenApiDocumentAsync("https://example.org926F4F21-88E7-4DC5-BF88-6C529BB77844/itdoesnmatter", _logger));
169+
OpenApiService.ValidateOpenApiDocumentAsync("https://example.org926F4F21-88E7-4DC5-BF88-6C529BB77844/itdoesnmatter", _logger, TestContext.Current.CancellationToken));
170170
}
171171

172172
[Fact]
173173
public Task ThrowIfFileDoesNotExistWhenValidatingAsync()
174174
{
175175
return Assert.ThrowsAsync<InvalidOperationException>(() =>
176-
OpenApiService.ValidateOpenApiDocumentAsync("aFileThatBetterNotExist.fake", _logger));
176+
OpenApiService.ValidateOpenApiDocumentAsync("aFileThatBetterNotExist.fake", _logger, TestContext.Current.CancellationToken));
177177
}
178178

179179
[Fact]
180180
public async Task ValidateCommandProcessesOpenApiAsync()
181181
{
182182
// create a dummy ILogger instance for testing
183-
await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger);
183+
await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger, TestContext.Current.CancellationToken);
184184

185185
Assert.True(true);
186186
}
187187

188188
[Fact]
189189
public async Task ValidFileReturnsTrueAsync()
190190
{
191-
var isValid = await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger);
191+
var isValid = await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger, TestContext.Current.CancellationToken);
192192

193193
Assert.True(isValid);
194194
}
195195

196196
[Fact]
197197
public async Task InvalidFileReturnsFalseAsync()
198198
{
199-
var isValid = await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "InvalidSampleOpenApi.yml"), _logger);
199+
var isValid = await OpenApiService.ValidateOpenApiDocumentAsync(Path.Combine("UtilityFiles", "InvalidSampleOpenApi.yml"), _logger, TestContext.Current.CancellationToken);
200200

201201
Assert.False(isValid);
202202
}
@@ -224,9 +224,9 @@ public async Task TransformCommandConvertsOpenApiAsync()
224224
InlineExternal = false,
225225
};
226226
// create a dummy ILogger instance for testing
227-
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger);
227+
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
228228

229-
var output = await File.ReadAllTextAsync("sample.json");
229+
var output = await File.ReadAllTextAsync("sample.json", TestContext.Current.CancellationToken);
230230
Assert.NotEmpty(output);
231231
}
232232

@@ -243,9 +243,9 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAsync()
243243
InlineExternal = false,
244244
};
245245
// create a dummy ILogger instance for testing
246-
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger);
246+
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
247247

248-
var output = await File.ReadAllTextAsync("output.yml");
248+
var output = await File.ReadAllTextAsync("output.yml", TestContext.Current.CancellationToken);
249249
Assert.NotEmpty(output);
250250
}
251251

@@ -263,9 +263,9 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAndSwitchF
263263
InlineExternal = false,
264264
};
265265
// create a dummy ILogger instance for testing
266-
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger);
266+
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
267267

268-
var output = await File.ReadAllTextAsync("output.yml");
268+
var output = await File.ReadAllTextAsync("output.yml", TestContext.Current.CancellationToken);
269269
Assert.NotEmpty(output);
270270
}
271271

@@ -280,7 +280,7 @@ public Task ThrowTransformCommandIfOpenApiAndCsdlAreEmptyAsync()
280280
InlineExternal = false,
281281
};
282282
return Assert.ThrowsAsync<ArgumentException>(() =>
283-
OpenApiService.TransformOpenApiDocumentAsync(options, _logger));
283+
OpenApiService.TransformOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken));
284284
}
285285

286286
[Fact]
@@ -299,9 +299,9 @@ public async Task TransformToPowerShellCompliantOpenApiAsync()
299299
SettingsConfig = SettingsUtilities.GetConfiguration(settingsPath)
300300
};
301301
// create a dummy ILogger instance for testing
302-
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger);
302+
await OpenApiService.TransformOpenApiDocumentAsync(options, _logger, TestContext.Current.CancellationToken);
303303

304-
var output = await File.ReadAllTextAsync("output.yaml");
304+
var output = await File.ReadAllTextAsync("output.yaml", TestContext.Current.CancellationToken);
305305
Assert.NotEmpty(output);
306306
}
307307

@@ -314,9 +314,9 @@ public async Task InvokeTransformCommandAsync()
314314
var parseResult = rootCommand.Parse(args);
315315
var handler = Assert.IsType<AsynchronousCommandLineAction>(rootCommand.Subcommands.First(c => c.Name == "transform").Action, exactMatch: false);
316316

317-
await handler.InvokeAsync(parseResult);
317+
await handler.InvokeAsync(parseResult, TestContext.Current.CancellationToken);
318318

319-
var output = await File.ReadAllTextAsync("sample.json");
319+
var output = await File.ReadAllTextAsync("sample.json", TestContext.Current.CancellationToken);
320320
Assert.NotEmpty(output);
321321
}
322322

@@ -330,9 +330,9 @@ public async Task InvokeShowCommandAsync()
330330
var parseResult = rootCommand.Parse(args);
331331
var handler = Assert.IsType<AsynchronousCommandLineAction>(rootCommand.Subcommands.First(c => c.Name == "show").Action, exactMatch: false);
332332

333-
await handler.InvokeAsync(parseResult);
333+
await handler.InvokeAsync(parseResult, TestContext.Current.CancellationToken);
334334

335-
var output = await File.ReadAllTextAsync("sample.md");
335+
var output = await File.ReadAllTextAsync("sample.md", TestContext.Current.CancellationToken);
336336
Assert.Contains("graph LR", output, StringComparison.Ordinal);
337337
}
338338

@@ -345,9 +345,9 @@ public async Task InvokePluginCommandAsync()
345345
var parseResult = rootCommand.Parse(args);
346346
var handler = Assert.IsType<AsynchronousCommandLineAction>(rootCommand.Subcommands.First(c => c.Name == "plugin").Action, exactMatch: false);
347347

348-
await handler.InvokeAsync(parseResult);
348+
await handler.InvokeAsync(parseResult, TestContext.Current.CancellationToken);
349349

350-
using var jsDoc = JsonDocument.Parse(await File.ReadAllTextAsync("ai-plugin.json"));
350+
using var jsDoc = JsonDocument.Parse(await File.ReadAllTextAsync("ai-plugin.json", TestContext.Current.CancellationToken));
351351
var openAiManifest = OpenAIPluginManifest.Load(jsDoc.RootElement);
352352

353353
Assert.NotNull(openAiManifest);

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<PackageReference Include="coverlet.msbuild" Version="10.0.1" PrivateAssets="all" />
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
2121
<PackageReference Include="FluentAssertions" Version="7.2.2" />
22-
<PackageReference Include="xunit" Version="2.9.3" />
22+
<PackageReference Include="xunit.v3" Version="3.2.2" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all" />
2424
</ItemGroup>
2525

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiDiagnosticTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class OpenApiDiagnosticTests
1616
[Fact]
1717
public async Task DetectedSpecificationVersionShouldBeV2_0()
1818
{
19-
var actual = await OpenApiDocument.LoadAsync("V2Tests/Samples/basic.v2.yaml", SettingsFixture.ReaderSettings);
19+
var actual = await OpenApiDocument.LoadAsync("V2Tests/Samples/basic.v2.yaml", SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
2020

2121
Assert.NotNull(actual.Diagnostic);
2222
Assert.Equal(OpenApiSpecVersion.OpenApi2_0, actual.Diagnostic.SpecificationVersion);
@@ -25,7 +25,7 @@ public async Task DetectedSpecificationVersionShouldBeV2_0()
2525
[Fact]
2626
public async Task DetectedSpecificationVersionShouldBeV3_0()
2727
{
28-
var actual = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml", SettingsFixture.ReaderSettings);
28+
var actual = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml", SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
2929

3030
Assert.NotNull(actual.Diagnostic);
3131
Assert.Equal(OpenApiSpecVersion.OpenApi3_0, actual.Diagnostic.SpecificationVersion);
@@ -44,7 +44,7 @@ public async Task DiagnosticReportMergedForExternalReferenceAsync()
4444
settings.AddYamlReader();
4545

4646
ReadResult result;
47-
result = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/TodoMain.yaml", settings);
47+
result = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/OpenApiDiagnosticReportMerged/TodoMain.yaml", settings, token: TestContext.Current.CancellationToken);
4848

4949
Assert.NotNull(result);
5050
Assert.NotNull(result.Document.Workspace);

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/OpenApiStreamReaderTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse()
2020
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
2121
var settings = new OpenApiReaderSettings { LeaveStreamOpen = false };
2222
settings.AddYamlReader();
23-
(_, var diagnostic) = await OpenApiDocument.LoadAsync(stream, settings: settings);
23+
(_, var diagnostic) = await OpenApiDocument.LoadAsync(stream, settings: settings, cancellationToken: TestContext.Current.CancellationToken);
2424
Assert.False(stream.CanRead);
2525
Assert.Equal(OpenApiConstants.Yaml, diagnostic.Format);
2626
}
@@ -31,7 +31,7 @@ public async Task StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue()
3131
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
3232
var settings = new OpenApiReaderSettings { LeaveStreamOpen = true };
3333
settings.AddYamlReader();
34-
_ = await OpenApiDocument.LoadAsync(stream, settings: settings);
34+
_ = await OpenApiDocument.LoadAsync(stream, settings: settings, cancellationToken: TestContext.Current.CancellationToken);
3535
Assert.True(stream.CanRead);
3636
}
3737

@@ -41,13 +41,13 @@ public async Task StreamShouldNotBeDisposedIfLeaveStreamOpenSettingIsTrueAsync()
4141
var memoryStream = new MemoryStream();
4242
using var fileStream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
4343

44-
await fileStream.CopyToAsync(memoryStream);
44+
await fileStream.CopyToAsync(memoryStream, TestContext.Current.CancellationToken);
4545
memoryStream.Position = 0;
4646
var stream = memoryStream;
4747

4848
var settings = new OpenApiReaderSettings { LeaveStreamOpen = true };
4949
settings.AddYamlReader();
50-
_ = await OpenApiDocument.LoadAsync(stream, settings: settings);
50+
_ = await OpenApiDocument.LoadAsync(stream, settings: settings, cancellationToken: TestContext.Current.CancellationToken);
5151
stream.Seek(0, SeekOrigin.Begin); // does not throw an object disposed exception
5252
Assert.True(stream.CanRead);
5353
}
@@ -60,12 +60,12 @@ public async Task StreamShouldReadWhenInitializedAsync()
6060
BaseAddress = new Uri("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/")
6161
};
6262

63-
var stream = await httpClient.GetStreamAsync("20fe7a7b720a0e48e5842d002ac418b12a8201df/tests/v3.0/pass/petstore.yaml");
63+
var stream = await httpClient.GetStreamAsync("20fe7a7b720a0e48e5842d002ac418b12a8201df/tests/v3.0/pass/petstore.yaml", TestContext.Current.CancellationToken);
6464

6565
// Read V3 as YAML
6666
var settings = new OpenApiReaderSettings();
6767
settings.AddYamlReader();
68-
var result = await OpenApiDocument.LoadAsync(stream, settings: settings);
68+
var result = await OpenApiDocument.LoadAsync(stream, settings: settings, cancellationToken: TestContext.Current.CancellationToken);
6969
Assert.NotNull(result.Document);
7070
}
7171
}

test/Microsoft.OpenApi.Readers.Tests/OpenApiReaderTests/UnsupportedSpecVersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public async Task ThrowOpenApiUnsupportedSpecVersionException()
1414
{
1515
try
1616
{
17-
_ = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/unsupported.v1.yaml", SettingsFixture.ReaderSettings);
17+
_ = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/unsupported.v1.yaml", SettingsFixture.ReaderSettings, token: TestContext.Current.CancellationToken);
1818
}
1919
catch (OpenApiUnsupportedSpecVersionException exception)
2020
{

test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW
3535
""";
3636
var wr = new StreamWriter(stream);
3737
await wr.WriteAsync(doc);
38-
await wr.FlushAsync();
38+
await wr.FlushAsync(TestContext.Current.CancellationToken);
3939
stream.Position = 0;
4040

41-
var result = await OpenApiDocument.LoadAsync(stream, OpenApiConstants.Yaml, settings: settings);
41+
var result = await OpenApiDocument.LoadAsync(stream, OpenApiConstants.Yaml, settings: settings, cancellationToken: TestContext.Current.CancellationToken);
4242

4343
Assert.NotNull(result.Document.Workspace);
4444
}
@@ -56,7 +56,7 @@ public async Task LoadDocumentWithExternalReferenceShouldLoadBothDocumentsIntoWo
5656
settings.AddYamlReader();
5757

5858
ReadResult result;
59-
result = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiWorkspace/TodoMain.yaml", settings);
59+
result = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiWorkspace/TodoMain.yaml", settings, token: TestContext.Current.CancellationToken);
6060

6161
var externalDocBaseUri = result.Document.Workspace.GetDocumentId("./TodoComponents.yaml");
6262
var schemasPath = "#/components/schemas/";
@@ -82,7 +82,7 @@ public async Task LoadDocumentWithExternalReferencesInSubDirectories()
8282
settings.AddYamlReader();
8383

8484
// Act
85-
var result = await OpenApiDocument.LoadAsync($"{sampleFolderPath}/Root.yaml", settings);
85+
var result = await OpenApiDocument.LoadAsync($"{sampleFolderPath}/Root.yaml", settings, token: TestContext.Current.CancellationToken);
8686
var document = result.Document;
8787
var workspace = result.Document.Workspace;
8888

0 commit comments

Comments
 (0)