Skip to content

Commit 0c05c3f

Browse files
committed
Clean up tests to reflect new LoadAsync pattern
1 parent 8d83694 commit 0c05c3f

39 files changed

+356
-343
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,18 @@ public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArguments
224224
}
225225

226226
[Fact]
227-
public void CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly()
227+
public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly()
228228
{
229229
// Arrange
230230
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles", "docWithReusableHeadersAndExamples.yaml");
231231
var operationIds = "getItems";
232232

233233
// Act
234234
using var stream = File.OpenRead(filePath);
235-
var doc = OpenApiDocument.Load(stream, "yaml").OpenApiDocument;
235+
var res = await OpenApiDocument.LoadAsync(stream);
236236

237237
var predicate = OpenApiFilterService.CreatePredicate(operationIds: operationIds);
238-
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(doc, predicate);
238+
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(res.OpenApiDocument, predicate);
239239

240240
var response = subsetOpenApiDocument.Paths["/items"].Operations[OperationType.Get]?.Responses?["200"];
241241
var responseHeader = response?.Headers["x-custom-header"];
@@ -244,7 +244,7 @@ public void CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly()
244244
var targetExamples = subsetOpenApiDocument.Components?.Examples;
245245

246246
// Assert
247-
Assert.Same(doc.Servers, subsetOpenApiDocument.Servers);
247+
Assert.Same(res.OpenApiDocument.Servers, subsetOpenApiDocument.Servers);
248248
Assert.False(responseHeader?.UnresolvedReference);
249249
Assert.False(mediaTypeExample?.UnresolvedReference);
250250
Assert.NotNull(targetHeaders);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ public OpenApiDiagnosticTests()
2323
}
2424

2525
[Fact]
26-
public void DetectedSpecificationVersionShouldBeV2_0()
26+
public async Task DetectedSpecificationVersionShouldBeV2_0()
2727
{
28-
var actual = OpenApiDocument.Load("V2Tests/Samples/basic.v2.yaml");
28+
var actual = await OpenApiDocument.LoadAsync("V2Tests/Samples/basic.v2.yaml");
2929

3030
actual.OpenApiDiagnostic.Should().NotBeNull();
3131
actual.OpenApiDiagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi2_0);
3232
}
3333

3434
[Fact]
35-
public void DetectedSpecificationVersionShouldBeV3_0()
35+
public async Task DetectedSpecificationVersionShouldBeV3_0()
3636
{
37-
var actual = OpenApiDocument.Load("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml");
37+
var actual = await OpenApiDocument.LoadAsync("V3Tests/Samples/OpenApiDocument/minimalDocument.yaml");
3838

3939
actual.OpenApiDiagnostic.Should().NotBeNull();
4040
actual.OpenApiDiagnostic.SpecificationVersion.Should().Be(OpenApiSpecVersion.OpenApi3_0);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ public OpenApiStreamReaderTests()
2121
}
2222

2323
[Fact]
24-
public void StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse()
24+
public async Task StreamShouldCloseIfLeaveStreamOpenSettingEqualsFalse()
2525
{
2626
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
2727
var settings = new OpenApiReaderSettings { LeaveStreamOpen = false };
28-
_ = OpenApiDocument.Load(stream, "yaml", settings);
28+
_ = await OpenApiDocument.LoadAsync(stream, settings);
2929
Assert.False(stream.CanRead);
3030
}
3131

3232
[Fact]
33-
public void StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue()
33+
public async Task StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue()
3434
{
3535
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));
3636
var settings = new OpenApiReaderSettings { LeaveStreamOpen = true };
37-
_ = OpenApiDocument.Load(stream, "yaml", settings);
37+
_ = await OpenApiDocument.LoadAsync(stream, settings);
3838
Assert.True(stream.CanRead);
3939
}
4040

@@ -48,7 +48,7 @@ public async Task StreamShouldNotBeDisposedIfLeaveStreamOpenSettingIsTrueAsync()
4848
memoryStream.Position = 0;
4949
var stream = memoryStream;
5050

51-
var result = OpenApiDocument.Load(stream, "yaml", new OpenApiReaderSettings { LeaveStreamOpen = true });
51+
var result = await OpenApiDocument.LoadAsync(stream, new OpenApiReaderSettings { LeaveStreamOpen = true });
5252
stream.Seek(0, SeekOrigin.Begin); // does not throw an object disposed exception
5353
Assert.True(stream.CanRead);
5454
}
@@ -64,7 +64,7 @@ public async Task StreamShouldReadWhenInitializedAsync()
6464
var stream = await httpClient.GetStreamAsync("20fe7a7b720a0e48e5842d002ac418b12a8201df/tests/v3.0/pass/petstore.yaml");
6565

6666
// Read V3 as YAML
67-
var result = OpenApiDocument.Load(stream, "yaml");
67+
var result = await OpenApiDocument.LoadAsync(stream);
6868
Assert.NotNull(result.OpenApiDocument);
6969
}
7070
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Threading.Tasks;
45
using FluentAssertions;
56
using Microsoft.OpenApi.Exceptions;
67
using Microsoft.OpenApi.Models;
@@ -12,11 +13,11 @@ namespace Microsoft.OpenApi.Readers.Tests.OpenApiReaderTests
1213
public class UnsupportedSpecVersionTests
1314
{
1415
[Fact]
15-
public void ThrowOpenApiUnsupportedSpecVersionException()
16+
public async Task ThrowOpenApiUnsupportedSpecVersionException()
1617
{
1718
try
1819
{
19-
_ = OpenApiDocument.Load("OpenApiReaderTests/Samples/unsupported.v1.yaml");
20+
_ = await OpenApiDocument.LoadAsync("OpenApiReaderTests/Samples/unsupported.v1.yaml");
2021
}
2122
catch (OpenApiUnsupportedSpecVersionException exception)
2223
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Threading.Tasks;
44
using Microsoft.OpenApi.Interfaces;
@@ -44,7 +44,7 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW
4444
await wr.FlushAsync();
4545
stream.Position = 0;
4646

47-
var result = await OpenApiDocument.LoadAsync(stream, OpenApiConstants.Yaml, settings: settings);
47+
var result = await OpenApiDocument.LoadAsync(stream, settings: settings);
4848

4949
Assert.NotNull(result.OpenApiDocument.Workspace);
5050
}

test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
5+
using System.Threading.Tasks;
56
using FluentAssertions;
67
using Microsoft.OpenApi.Exceptions;
78
using Microsoft.OpenApi.Models;
@@ -19,7 +20,7 @@ public ParseNodeTests()
1920
}
2021

2122
[Fact]
22-
public void BrokenSimpleList()
23+
public async Task BrokenSimpleList()
2324
{
2425
var input =
2526
"""
@@ -31,7 +32,7 @@ public void BrokenSimpleList()
3132
paths: { }
3233
""";
3334

34-
var result = OpenApiDocument.Parse(input, "yaml");
35+
var result = await OpenApiDocument.ParseAsync(input);
3536

3637
result.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
3738
new OpenApiError(new OpenApiReaderException("Expected a value.")),
@@ -40,7 +41,7 @@ public void BrokenSimpleList()
4041
}
4142

4243
[Fact]
43-
public void BadSchema()
44+
public async Task BadSchema()
4445
{
4546
var input = """
4647
openapi: 3.0.0
@@ -58,7 +59,7 @@ public void BadSchema()
5859
schema: asdasd
5960
""";
6061

61-
var res= OpenApiDocument.Parse(input, "yaml");
62+
var res = await OpenApiDocument.ParseAsync(input);
6263

6364
res.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>
6465
{

test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Threading.Tasks;
67
using FluentAssertions;
78
using Microsoft.OpenApi.Models;
89
using Microsoft.OpenApi.Models.References;
@@ -22,10 +23,10 @@ public TryLoadReferenceV2Tests()
2223
}
2324

2425
[Fact]
25-
public void LoadParameterReference()
26+
public async Task LoadParameterReference()
2627
{
2728
// Arrange
28-
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
29+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
2930
var reference = new OpenApiParameterReference("skipParam", result.OpenApiDocument);
3031

3132
// Assert
@@ -47,9 +48,9 @@ public void LoadParameterReference()
4748
}
4849

4950
[Fact]
50-
public void LoadSecuritySchemeReference()
51+
public async Task LoadSecuritySchemeReference()
5152
{
52-
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
53+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
5354

5455
var reference = new OpenApiSecuritySchemeReference("api_key_sample", result.OpenApiDocument);
5556

@@ -65,9 +66,9 @@ public void LoadSecuritySchemeReference()
6566
}
6667

6768
[Fact]
68-
public void LoadResponseReference()
69+
public async Task LoadResponseReference()
6970
{
70-
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
71+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
7172

7273
var reference = new OpenApiResponseReference("NotFound", result.OpenApiDocument);
7374

@@ -85,9 +86,9 @@ public void LoadResponseReference()
8586
}
8687

8788
[Fact]
88-
public void LoadResponseAndSchemaReference()
89+
public async Task LoadResponseAndSchemaReference()
8990
{
90-
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
91+
var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "multipleReferences.v2.yaml"));
9192
var reference = new OpenApiResponseReference("GeneralError", result.OpenApiDocument);
9293

9394
// Assert

test/Microsoft.OpenApi.Readers.Tests/TestCustomExtension.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System.Text.Json.Nodes;
5+
using System.Threading.Tasks;
56
using FluentAssertions;
67
using Microsoft.OpenApi.Interfaces;
78
using Microsoft.OpenApi.Models;
@@ -14,7 +15,7 @@ namespace Microsoft.OpenApi.Readers.Tests
1415
public class TestCustomExtension
1516
{
1617
[Fact]
17-
public void ParseCustomExtension()
18+
public async Task ParseCustomExtension()
1819
{
1920
var description =
2021
"""
@@ -40,7 +41,7 @@ public void ParseCustomExtension()
4041

4142
OpenApiReaderRegistry.RegisterReader("yaml", new OpenApiYamlReader());
4243
var diag = new OpenApiDiagnostic();
43-
var actual = OpenApiDocument.Parse(description, "yaml", settings: settings);
44+
var actual = await OpenApiDocument.ParseAsync(description, settings: settings);
4445

4546
var fooExtension = actual.OpenApiDocument.Info.Extensions["x-foo"] as FooExtension;
4647

test/Microsoft.OpenApi.Readers.Tests/V2Tests/ComparisonTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.IO;
5+
using System.Threading.Tasks;
56
using FluentAssertions;
67
using Microsoft.OpenApi.Models;
78
using Microsoft.OpenApi.Reader;
@@ -18,13 +19,13 @@ public class ComparisonTests
1819
[InlineData("minimal")]
1920
[InlineData("basic")]
2021
//[InlineData("definitions")] //Currently broken due to V3 references not behaving the same as V2
21-
public void EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(string fileName)
22+
public async Task EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(string fileName)
2223
{
2324
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
2425
using var streamV2 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
2526
using var streamV3 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
26-
var result1 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
27-
var result2 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
27+
var result1 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
28+
var result2 = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
2829

2930
result2.OpenApiDocument.Should().BeEquivalentTo(result1.OpenApiDocument,
3031
options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri));

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Threading.Tasks;
45
using FluentAssertions;
56
using Microsoft.OpenApi.Models;
67
using Microsoft.OpenApi.Reader;
@@ -11,7 +12,7 @@ namespace Microsoft.OpenApi.Readers.Tests.V2Tests
1112
public class OpenApiContactTests
1213
{
1314
[Fact]
14-
public void ParseStringContactFragmentShouldSucceed()
15+
public async Task ParseStringContactFragmentShouldSucceed()
1516
{
1617
var input =
1718
"""
@@ -23,12 +24,12 @@ public void ParseStringContactFragmentShouldSucceed()
2324
""";
2425

2526
// Act
26-
var contact = OpenApiModelFactory.Parse<OpenApiContact>(input, OpenApiSpecVersion.OpenApi2_0, out var diagnostic);
27+
var contact = await OpenApiModelFactory.ParseAsync<OpenApiContact>(input, OpenApiSpecVersion.OpenApi2_0);
2728

2829
// Assert
29-
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
30+
contact.OpenApiDiagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
3031

31-
contact.Should().BeEquivalentTo(
32+
contact.Element.Should().BeEquivalentTo(
3233
new OpenApiContact
3334
{
3435
Email = "[email protected]",

0 commit comments

Comments
 (0)