diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index 069f8cd67..c7bf1a558 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -113,7 +113,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog var walker = new OpenApiWalker(powerShellFormatter); walker.Walk(document); } - WriteOpenApi(options, openApiFormat, openApiVersion, document, logger); + await WriteOpenApiAsync(options, openApiFormat, openApiVersion, document, logger, cancellationToken).ConfigureAwait(false); } catch (TaskCanceledException) { @@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, return document; } - private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger) + private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) { using (logger.BeginScope("Output")) { @@ -216,11 +216,11 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma var stopwatch = new Stopwatch(); stopwatch.Start(); - document.Serialize(writer, openApiVersion); + await document.SerializeAsync(writer, openApiVersion, cancellationToken).ConfigureAwait(false); stopwatch.Stop(); logger.LogTrace("Finished serializing in {ElapsedMilliseconds}ms", stopwatch.ElapsedMilliseconds); - textWriter.Flush(); + await textWriter.FlushAsync(cancellationToken).ConfigureAwait(false); } } @@ -769,7 +769,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg // Write OpenAPI to Output folder options.Output = new(Path.Combine(options.OutputFolder, "openapi.json")); options.TerseOutput = true; - WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger); + await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); // Create OpenAIPluginManifest from ApiDependency and OpenAPI document var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "placeholder@contoso.com", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com") diff --git a/src/Microsoft.OpenApi.Workbench/MainModel.cs b/src/Microsoft.OpenApi.Workbench/MainModel.cs index 1cd4f24ac..7eee12251 100644 --- a/src/Microsoft.OpenApi.Workbench/MainModel.cs +++ b/src/Microsoft.OpenApi.Workbench/MainModel.cs @@ -270,7 +270,7 @@ internal async Task ParseDocumentAsync() stopwatch.Reset(); stopwatch.Start(); - Output = WriteContents(document); + Output = await WriteContentsAsync(document); stopwatch.Stop(); RenderTime = $"{stopwatch.ElapsedMilliseconds} ms"; @@ -299,15 +299,15 @@ internal async Task ParseDocumentAsync() /// /// Write content from the given document based on the format and version set in this class. /// - private string WriteContents(OpenApiDocument document) + private async Task WriteContentsAsync(OpenApiDocument document) { var outputStream = new MemoryStream(); - document.Serialize( + await document.SerializeAsync( outputStream, Version, Format, - new() + (Writers.OpenApiWriterSettings)new() { InlineLocalReferences = InlineLocal, InlineExternalReferences = InlineExternal @@ -315,7 +315,7 @@ private string WriteContents(OpenApiDocument document) outputStream.Position = 0; - return new StreamReader(outputStream).ReadToEnd(); + return await new StreamReader(outputStream).ReadToEndAsync(); } private static MemoryStream CreateStream(string text) diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs index 5d59a8de2..9d284db1a 100755 --- a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs @@ -3,6 +3,8 @@ using System.Globalization; using System.IO; +using System.Threading; +using System.Threading.Tasks; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Properties; @@ -22,10 +24,11 @@ public static class OpenApiSerializableExtensions /// The Open API element. /// The output stream. /// The Open API specification version. - public static void SerializeAsJson(this T element, Stream stream, OpenApiSpecVersion specVersion) + /// The cancellation token. + public static Task SerializeAsJsonAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - element.Serialize(stream, specVersion, OpenApiFormat.Json); + return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken); } /// @@ -35,10 +38,11 @@ public static void SerializeAsJson(this T element, Stream stream, OpenApiSpec /// The Open API element. /// The output stream. /// The Open API specification version. - public static void SerializeAsYaml(this T element, Stream stream, OpenApiSpecVersion specVersion) + /// The cancellation token. + public static Task SerializeAsYamlAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - element.Serialize(stream, specVersion, OpenApiFormat.Yaml); + return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken); } /// @@ -50,14 +54,16 @@ public static void SerializeAsYaml(this T element, Stream stream, OpenApiSpec /// The given stream. /// The Open API specification version. /// The output format (JSON or YAML). - public static void Serialize( + /// The cancellation token. + public static Task SerializeAsync( this T element, Stream stream, OpenApiSpecVersion specVersion, - OpenApiFormat format) + OpenApiFormat format, + CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - element.Serialize(stream, specVersion, format, null); + return element.SerializeAsync(stream, specVersion, format, null, cancellationToken); } /// @@ -70,12 +76,14 @@ public static void Serialize( /// The Open API specification version. /// The output format (JSON or YAML). /// Provide configuration settings for controlling writing output - public static void Serialize( + /// The cancellation token. + public static Task SerializeAsync( this T element, Stream stream, OpenApiSpecVersion specVersion, OpenApiFormat format, - OpenApiWriterSettings settings) + OpenApiWriterSettings settings, + CancellationToken cancellationToken = default) where T : IOpenApiSerializable { Utils.CheckArgumentNull(stream); @@ -88,7 +96,7 @@ public static void Serialize( OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings), _ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)), }; - element.Serialize(writer, specVersion); + return element.SerializeAsync(writer, specVersion, cancellationToken); } /// @@ -98,7 +106,8 @@ public static void Serialize( /// The Open API element. /// The output writer. /// Version of the specification the output should conform to - public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion) + /// The cancellation token. + public static Task SerializeAsync(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { Utils.CheckArgumentNull(element); @@ -122,7 +131,7 @@ public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSp throw new OpenApiException(string.Format(SRResource.OpenApiSpecVersionNotSupported, specVersion)); } - writer.Flush(); + return writer.FlushAsync(cancellationToken); } /// @@ -131,12 +140,14 @@ public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSp /// the /// The Open API element. /// The Open API specification version. - public static string SerializeAsJson( + /// The cancellation token. + public static Task SerializeAsJsonAsync( this T element, - OpenApiSpecVersion specVersion) + OpenApiSpecVersion specVersion, + CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.Serialize(specVersion, OpenApiFormat.Json); + return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken); } /// @@ -145,12 +156,14 @@ public static string SerializeAsJson( /// the /// The Open API element. /// The Open API specification version. - public static string SerializeAsYaml( + /// The cancellation token. + public static Task SerializeAsYamlAsync( this T element, - OpenApiSpecVersion specVersion) + OpenApiSpecVersion specVersion, + CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.Serialize(specVersion, OpenApiFormat.Yaml); + return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken); } /// @@ -160,20 +173,26 @@ public static string SerializeAsYaml( /// The Open API element. /// The Open API specification version. /// Open API document format. - public static string Serialize( + /// The cancellation token. + public static async Task SerializeAsync( this T element, OpenApiSpecVersion specVersion, - OpenApiFormat format) + OpenApiFormat format, + CancellationToken cancellationToken = default) where T : IOpenApiSerializable { Utils.CheckArgumentNull(element); using var stream = new MemoryStream(); - element.Serialize(stream, specVersion, format); + await element.SerializeAsync(stream, specVersion, format, cancellationToken).ConfigureAwait(false); stream.Position = 0; using var streamReader = new StreamReader(stream); - return streamReader.ReadToEnd(); +#if NET7_0_OR_GREATER + return await streamReader.ReadToEndAsync(cancellationToken).ConfigureAwait(false); +#else + return await streamReader.ReadToEndAsync().ConfigureAwait(false); +#endif } } } diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index e0b815f5d..8753755ac 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + netstandard2.0;net8.0 Latest true 2.0.0-preview4 diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index 0db85ed77..5b43b5187 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -318,7 +318,7 @@ private void RenderComponents(IOpenApiWriter writer, Action schemas)) + if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas)) { writer.WriteOptionalMap(OpenApiConstants.Schemas, Schemas, callback); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index 8cc1fda6c..cf7e53cae 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -83,11 +83,6 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenAp /// public IDictionary? Extensions { get; set; } = new Dictionary(); - /// - /// The unique hash code of the generated OpenAPI document - /// - public string HashCode => GenerateHashValue(this); - /// public IDictionary? Annotations { get; set; } @@ -243,7 +238,7 @@ public void SerializeAsV2(IOpenApiWriter writer) { var loops = writer.GetSettings().LoopDetector.Loops; - if (loops.TryGetValue(typeof(OpenApiSchema), out List schemas)) + if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas)) { var openApiSchemas = schemas.Cast().Distinct().ToList() .ToDictionary(k => k.Reference.Id); @@ -414,14 +409,15 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList? return url; }) .Where( - u => Uri.Compare( + u => u is not null && + Uri.Compare( u, firstServerUrl, UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0 && u.IsAbsoluteUri) - .Select(u => u.Scheme) + .Select(u => u!.Scheme) .Distinct() .ToList(); @@ -457,22 +453,24 @@ public void SetReferenceHostDocument() /// /// Takes in an OpenApi document instance and generates its hash value /// - /// The OpenAPI description to hash. + /// Propagates notification that operations should be canceled. /// The hash value. - public static string GenerateHashValue(OpenApiDocument doc) + public async Task GetHashCodeAsync(CancellationToken cancellationToken = default) { using HashAlgorithm sha = SHA512.Create(); using var cryptoStream = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write); using var streamWriter = new StreamWriter(cryptoStream); var openApiJsonWriter = new OpenApiJsonWriter(streamWriter, new() { Terse = true }); - doc.SerializeAsV3(openApiJsonWriter); - openApiJsonWriter.Flush(); + SerializeAsV3(openApiJsonWriter); + await openApiJsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false); +#if NET5_0_OR_GREATER + await cryptoStream.FlushFinalBlockAsync(cancellationToken).ConfigureAwait(false); +#else cryptoStream.FlushFinalBlock(); - var hash = sha.Hash; - - return ConvertByteArrayToString(hash); +#endif + return ConvertByteArrayToString(sha.Hash ?? []); } private static string ConvertByteArrayToString(byte[] hash) diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 6182eda2b..f5fe32274 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -283,11 +283,11 @@ public void SerializeAsV2(IOpenApiWriter writer) { var produces = Responses .Where(static r => r.Value.Content != null) - .SelectMany(static r => r.Value.Content?.Keys) + .SelectMany(static r => r.Value.Content?.Keys ?? []) .Concat( Responses .Where(static r => r.Value.Reference is {HostDocument: not null}) - .SelectMany(static r => r.Value.Content?.Keys)) + .SelectMany(static r => r.Value.Content?.Keys ?? [])) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); diff --git a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs index 31b939548..fea86f899 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs @@ -129,7 +129,11 @@ public static async Task LoadAsync(Stream input, string format = nul var result = await InternalLoadAsync(preparedStream, format, settings, cancellationToken).ConfigureAwait(false); if (!settings.LeaveStreamOpen) { +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP || NET5_0_OR_GREATER + await input.DisposeAsync().ConfigureAwait(false); +#else input.Dispose(); +#endif } return result; } diff --git a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs index 9ea04b400..78be4e37f 100644 --- a/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs +++ b/src/Microsoft.OpenApi/Writers/IOpenApiWriter.cs @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Threading; +using System.Threading.Tasks; + namespace Microsoft.OpenApi.Writers { /// @@ -71,6 +74,7 @@ public interface IOpenApiWriter /// /// Flush the writer. /// - void Flush(); + /// The cancellation token. + Task FlushAsync(CancellationToken cancellationToken = default); } } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs index 901b26194..0864729d9 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs @@ -7,6 +7,8 @@ using System.IO; using System.Linq; using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Extensions; @@ -46,7 +48,7 @@ public abstract class OpenApiWriterBase : IOpenApiWriter /// Initializes a new instance of the class. /// /// The text writer. - public OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null) + protected OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null) { } @@ -55,7 +57,7 @@ public OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null) /// /// /// - public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings) + protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings) { Writer = textWriter; Writer.NewLine = "\n"; @@ -119,12 +121,14 @@ public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings) /// public abstract void WriteRaw(string value); - /// - /// Flush the writer. - /// - public void Flush() + /// + public Task FlushAsync(CancellationToken cancellationToken = default) { - Writer.Flush(); +#if NET8_OR_GREATER + return Writer.FlushAsync(cancellationToken); +#else + return Writer.FlushAsync(); +#endif } /// diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs index 4142e9fcd..948c6544c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs @@ -5,6 +5,7 @@ using System.IO; using System.Text; using System.Text.Json.Nodes; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -234,12 +235,12 @@ public void ParseBasicOperationShouldSucceed() } [Fact] - public void ParseBasicOperationTwiceShouldYieldSameObject() + public async Task ParseBasicOperationTwiceShouldYieldSameObject() { // Arrange MapNode node; using (var stream = new MemoryStream( - Encoding.Default.GetBytes(_basicOperation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0)))) + Encoding.Default.GetBytes(await _basicOperation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0)))) { node = TestHelper.CreateYamlMapNode(stream); } @@ -269,12 +270,12 @@ public void ParseOperationWithBodyShouldSucceed() } [Fact] - public void ParseOperationWithBodyTwiceShouldYieldSameObject() + public async Task ParseOperationWithBodyTwiceShouldYieldSameObject() { // Arrange MapNode node; using (var stream = new MemoryStream( - Encoding.Default.GetBytes(_operationWithBody.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0)))) + Encoding.Default.GetBytes(await _operationWithBody.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0)))) { node = TestHelper.CreateYamlMapNode(stream); } @@ -404,7 +405,7 @@ public void ParseOperationWithBodyAndEmptyConsumesSetsRequestBodySchemaIfExists( } [Fact] - public void ParseV2ResponseWithExamplesExtensionWorks() + public async Task ParseV2ResponseWithExamplesExtensionWorks() { // Arrange MapNode node; @@ -415,7 +416,7 @@ public void ParseV2ResponseWithExamplesExtensionWorks() // Act var operation = OpenApiV2Deserializer.LoadOperation(node); - var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert var expected = @"summary: Get all pets @@ -454,7 +455,7 @@ public void ParseV2ResponseWithExamplesExtensionWorks() } [Fact] - public void LoadV3ExamplesInResponseAsExtensionsWorks() + public async Task LoadV3ExamplesInResponseAsExtensionsWorks() { // Arrange MapNode node; @@ -465,7 +466,7 @@ public void LoadV3ExamplesInResponseAsExtensionsWorks() // Act var operation = OpenApiV3Deserializer.LoadOperation(node); - var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert var expected = @"summary: Get all pets @@ -504,7 +505,7 @@ public void LoadV3ExamplesInResponseAsExtensionsWorks() } [Fact] - public void LoadV2OperationWithBodyParameterExamplesWorks() + public async Task LoadV2OperationWithBodyParameterExamplesWorks() { // Arrange MapNode node; @@ -515,7 +516,7 @@ public void LoadV2OperationWithBodyParameterExamplesWorks() // Act var operation = OpenApiV2Deserializer.LoadOperation(node); - var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert var expected = @"summary: Get all pets @@ -555,7 +556,7 @@ public void LoadV2OperationWithBodyParameterExamplesWorks() } [Fact] - public void LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks() + public async Task LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks() { // Arrange MapNode node; @@ -566,7 +567,7 @@ public void LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks() // Act var operation = OpenApiV3Deserializer.LoadOperation(node); - var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert var expected = @"summary: Get all pets diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs index 22747f0cf..a83da5e39 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs @@ -460,7 +460,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks() prop3: type: string"; - var actualMediaType = mediaType.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actualMediaType = await mediaType.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actualSchema.Should().BeEquivalentTo(expectedSchema); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index c281206e3..864bb5aaa 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -32,7 +32,7 @@ public OpenApiDocumentTests() OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader()); } - private static T Clone(T element) where T : IOpenApiSerializable + private static async Task CloneAsync(T element) where T : IOpenApiSerializable { using var stream = new MemoryStream(); var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture); @@ -41,15 +41,15 @@ private static T Clone(T element) where T : IOpenApiSerializable InlineLocalReferences = true }); element.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); stream.Position = 0; using var streamReader = new StreamReader(stream); - var result = streamReader.ReadToEnd(); + var result = await streamReader.ReadToEndAsync(); return OpenApiModelFactory.Parse(result, OpenApiSpecVersion.OpenApi3_0, out var _); } - private static OpenApiSecurityScheme CloneSecurityScheme(OpenApiSecurityScheme element) + private static async Task CloneSecuritySchemeAsync(OpenApiSecurityScheme element) { using var stream = new MemoryStream(); var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture); @@ -58,11 +58,11 @@ private static OpenApiSecurityScheme CloneSecurityScheme(OpenApiSecurityScheme e InlineLocalReferences = true }); element.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); stream.Position = 0; using var streamReader = new StreamReader(stream); - var result = streamReader.ReadToEnd(); + var result = await streamReader.ReadToEndAsync(); return OpenApiModelFactory.Parse(result, OpenApiSpecVersion.OpenApi3_0, out var _); } @@ -681,7 +681,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }; // Create a clone of the schema to avoid modifying things in components. - var petSchema = Clone(components.Schemas["pet1"]); + var petSchema = await CloneAsync(components.Schemas["pet1"]); petSchema.Reference = new() { Id = "pet1", @@ -689,7 +689,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() HostDocument = actual.Document }; - var newPetSchema = Clone(components.Schemas["newPet"]); + var newPetSchema = await CloneAsync(components.Schemas["newPet"]); newPetSchema.Reference = new() { @@ -698,7 +698,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() HostDocument = actual.Document }; - var errorModelSchema = Clone(components.Schemas["errorModel"]); + var errorModelSchema = await CloneAsync(components.Schemas["errorModel"]); errorModelSchema.Reference = new() { @@ -729,7 +729,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } }; - var securityScheme1 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName1"]); + var securityScheme1 = await CloneSecuritySchemeAsync(components.SecuritySchemes["securitySchemeName1"]); securityScheme1.Reference = new OpenApiReference { @@ -737,7 +737,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() Type = ReferenceType.SecurityScheme }; - var securityScheme2 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName2"]); + var securityScheme2 = await CloneSecuritySchemeAsync(components.SecuritySchemes["securitySchemeName2"]); securityScheme2.Reference = new OpenApiReference { @@ -1081,7 +1081,6 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }; actual.Document.Should().BeEquivalentTo(expected, options => options - .Excluding(x => x.HashCode) .Excluding(m => m.Tags[0].Reference) .Excluding(x => x.Paths["/pets"].Operations[OperationType.Get].Tags[0].Reference) .Excluding(x => x.Paths["/pets"].Operations[OperationType.Get].Tags[0].Reference.HostDocument) @@ -1325,7 +1324,7 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds() // Act var doc = (await OpenApiDocument.LoadAsync(stream)).Document; var actualParam = doc.Paths["/pets"].Operations[OperationType.Get].Parameters[0]; - var outputDoc = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0).MakeLineBreaksEnvironmentNeutral(); + var outputDoc = (await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0)).MakeLineBreaksEnvironmentNeutral(); var expectedParam = expected.Paths["/pets"].Operations[OperationType.Get].Parameters[0]; // Assert diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs index 6197cca71..8ade58ca5 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs @@ -77,7 +77,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed() } [Fact] - public void ParseMediaTypeWithEmptyArrayInExamplesWorks() + public async Task ParseMediaTypeWithEmptyArrayInExamplesWorks() { // Arrange var expected = @"{ @@ -107,7 +107,7 @@ public void ParseMediaTypeWithEmptyArrayInExamplesWorks() // Act var mediaType = OpenApiV3Deserializer.LoadMediaType(node); - var serialized = mediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var serialized = await mediaType.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert serialized.MakeLineBreaksEnvironmentNeutral() diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 8e52ad6aa..a1554352f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -383,8 +383,8 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() }; // We serialize so that we can get rid of the schema BaseUri properties which show up as diffs - var actual = result.Document.Components.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); - var expected = expectedComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await result.Document.Components.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); + var expected = await expectedComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual.Should().Be(expected); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs index ad2c9ffdb..8c729b7c4 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs @@ -105,7 +105,7 @@ public async Task SerializeAdvancedCallbackAsV3JsonWorksAsync(bool produceTerseO // Act AdvancedCallback.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -122,7 +122,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWorksAsync(bool produceTers // Act CallbackProxy.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -139,7 +139,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWithoutReferenceWorksAsync( // Act ReferencedCallback.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs index a959edbf6..3a69b708e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -274,13 +275,13 @@ public class OpenApiComponentsTests }; [Fact] - public void SerializeBasicComponentsAsJsonWorks() + public async Task SerializeBasicComponentsAsJsonWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -289,13 +290,13 @@ public void SerializeBasicComponentsAsJsonWorks() } [Fact] - public void SerializeBasicComponentsAsYamlWorks() + public async Task SerializeBasicComponentsAsYamlWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -304,7 +305,7 @@ public void SerializeBasicComponentsAsYamlWorks() } [Fact] - public void SerializeAdvancedComponentsAsJsonV3Works() + public async Task SerializeAdvancedComponentsAsJsonV3Works() { // Arrange var expected = @@ -347,7 +348,7 @@ public void SerializeAdvancedComponentsAsJsonV3Works() """; // Act - var actual = AdvancedComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -356,7 +357,7 @@ public void SerializeAdvancedComponentsAsJsonV3Works() } [Fact] - public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works() + public async Task SerializeAdvancedComponentsWithReferenceAsJsonV3Works() { // Arrange var expected = @@ -405,7 +406,7 @@ public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works() """; // Act - var actual = AdvancedComponentsWithReference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedComponentsWithReference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -414,7 +415,7 @@ public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works() } [Fact] - public void SerializeAdvancedComponentsAsYamlV3Works() + public async Task SerializeAdvancedComponentsAsYamlV3Works() { // Arrange var expected = @@ -444,7 +445,7 @@ public void SerializeAdvancedComponentsAsYamlV3Works() """; // Act - var actual = AdvancedComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -453,7 +454,7 @@ public void SerializeAdvancedComponentsAsYamlV3Works() } [Fact] - public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works() + public async Task SerializeAdvancedComponentsWithReferenceAsYamlV3Works() { // Arrange var expected = @@ -486,7 +487,7 @@ public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works() """; // Act - var actual = AdvancedComponentsWithReference.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedComponentsWithReference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -495,7 +496,7 @@ public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works() } [Fact] - public void SerializeBrokenComponentsAsJsonV3Works() + public async Task SerializeBrokenComponentsAsJsonV3Works() { // Arrange var expected = """ @@ -523,7 +524,7 @@ public void SerializeBrokenComponentsAsJsonV3Works() """; // Act - var actual = BrokenComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BrokenComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -532,7 +533,7 @@ public void SerializeBrokenComponentsAsJsonV3Works() } [Fact] - public void SerializeBrokenComponentsAsYamlV3Works() + public async Task SerializeBrokenComponentsAsYamlV3Works() { // Arrange var expected = @@ -553,7 +554,7 @@ public void SerializeBrokenComponentsAsYamlV3Works() """; // Act - var actual = BrokenComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await BrokenComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -562,7 +563,7 @@ public void SerializeBrokenComponentsAsYamlV3Works() } [Fact] - public void SerializeTopLevelReferencingComponentsAsYamlV3Works() + public async Task SerializeTopLevelReferencingComponentsAsYamlV3Works() { // Arrange // Arrange @@ -579,7 +580,7 @@ public void SerializeTopLevelReferencingComponentsAsYamlV3Works() """; // Act - var actual = TopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await TopLevelReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -588,7 +589,7 @@ public void SerializeTopLevelReferencingComponentsAsYamlV3Works() } [Fact] - public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() + public async Task SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() { // Arrange var expected = @"schemas: @@ -604,7 +605,7 @@ public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV type: string"; // Act - var actual = TopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await TopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -613,7 +614,7 @@ public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV } [Fact] - public void SerializeComponentsWithPathItemsAsJsonWorks() + public async Task SerializeComponentsWithPathItemsAsJsonWorks() { // Arrange var expected = @"{ @@ -659,7 +660,7 @@ public void SerializeComponentsWithPathItemsAsJsonWorks() } }"; // Act - var actual = ComponentsWithPathItem.SerializeAsJson(OpenApiSpecVersion.OpenApi3_1); + var actual = await ComponentsWithPathItem.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -668,7 +669,7 @@ public void SerializeComponentsWithPathItemsAsJsonWorks() } [Fact] - public void SerializeComponentsWithPathItemsAsYamlWorks() + public async Task SerializeComponentsWithPathItemsAsYamlWorks() { // Arrange var expected = @"pathItems: @@ -696,7 +697,7 @@ public void SerializeComponentsWithPathItemsAsYamlWorks() type: integer"; // Act - var actual = ComponentsWithPathItem.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await ComponentsWithPathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs index 06c00fec4..337548ccb 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -32,13 +33,13 @@ public class OpenApiContactTests [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json, "{ }")] [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml, "{ }")] [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml, "{ }")] - public void SerializeBasicContactWorks( + public async Task SerializeBasicContactWorks( OpenApiSpecVersion version, OpenApiFormat format, string expected) { // Arrange & Act - var actual = BasicContact.Serialize(version, format); + var actual = await BasicContact.SerializeAsync(version, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -49,7 +50,7 @@ public void SerializeBasicContactWorks( [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version) + public async Task SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -63,7 +64,7 @@ public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvanceContact.SerializeAsJson(version); + var actual = await AdvanceContact.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -74,7 +75,7 @@ public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version) [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version) + public async Task SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -86,7 +87,7 @@ public void SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvanceContact.SerializeAsYaml(version); + var actual = await AdvanceContact.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 5d493fc55..5d9c9175b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1355,7 +1355,7 @@ public async Task SerializeAdvancedDocumentAsV3JsonWorksAsync(bool produceTerseO // Act AdvancedDocument.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1372,7 +1372,7 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV3JsonWorksAsync(bool // Act AdvancedDocumentWithReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1389,7 +1389,7 @@ public async Task SerializeAdvancedDocumentWithServerVariableAsV2JsonWorksAsync( // Act AdvancedDocumentWithServerVariable.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1406,7 +1406,7 @@ public async Task SerializeAdvancedDocumentAsV2JsonWorksAsync(bool produceTerseO // Act AdvancedDocument.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1423,7 +1423,7 @@ public async Task SerializeDuplicateExtensionsAsV3JsonWorksAsync(bool produceTer // Act DuplicateExtensions.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1440,7 +1440,7 @@ public async Task SerializeDuplicateExtensionsAsV2JsonWorksAsync(bool produceTer // Act DuplicateExtensions.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -1457,14 +1457,14 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV2JsonWorksAsync(bool // Act AdvancedDocumentWithReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } [Fact] - public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works() + public async Task SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works() { // Arrange var expected = @"swagger: '2.0' @@ -1481,7 +1481,7 @@ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Work type: string"; // Act - var actual = SimpleDocumentWithTopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await SimpleDocumentWithTopLevelReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1490,7 +1490,7 @@ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Work } [Fact] - public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3Works() + public async Task SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3Works() { // Arrange var expected = @"swagger: '2.0' @@ -1501,7 +1501,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3 schema1: { }"; // Act - var actual = SimpleDocumentWithTopLevelSelfReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await SimpleDocumentWithTopLevelSelfReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1510,7 +1510,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3 } [Fact] - public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() + public async Task SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works() { // Arrange var expected = @"swagger: '2.0' @@ -1530,7 +1530,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertie type: string"; // Act - var actual = SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1539,7 +1539,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertie } [Fact] - public void SerializeDocumentWithReferenceButNoComponents() + public async Task SerializeDocumentWithReferenceButNoComponents() { // Arrange var document = new OpenApiDocument() @@ -1584,14 +1584,14 @@ public void SerializeDocumentWithReferenceButNoComponents() }; // Act - var actual = document.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); + var actual = await document.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); // Assert Assert.NotEmpty(actual); } [Fact] - public void SerializeRelativePathAsV2JsonWorks() + public async Task SerializeRelativePathAsV2JsonWorks() { // Arrange var expected = @@ -1612,7 +1612,7 @@ public void SerializeRelativePathAsV2JsonWorks() }; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1621,7 +1621,7 @@ public void SerializeRelativePathAsV2JsonWorks() } [Fact] - public void SerializeRelativePathWithHostAsV2JsonWorks() + public async Task SerializeRelativePathWithHostAsV2JsonWorks() { // Arrange var expected = @@ -1643,7 +1643,7 @@ public void SerializeRelativePathWithHostAsV2JsonWorks() }; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1652,7 +1652,7 @@ public void SerializeRelativePathWithHostAsV2JsonWorks() } [Fact] - public void SerializeRelativeRootPathWithHostAsV2JsonWorks() + public async Task SerializeRelativeRootPathWithHostAsV2JsonWorks() { // Arrange var expected = @@ -1673,7 +1673,7 @@ public void SerializeRelativeRootPathWithHostAsV2JsonWorks() }; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1696,8 +1696,17 @@ public async Task TestHashCodesForSimilarOpenApiDocuments() Test whether reading in two similar documents yield the same hash code, And reading in similar documents(one has a whitespace) yields the same hash code as the result is terse */ - Assert.True(doc1.HashCode != null && doc2.HashCode != null && doc1.HashCode.Equals(doc2.HashCode)); - Assert.Equal(doc1.HashCode, doc3.HashCode); + var doc1HashCode = await doc1.GetHashCodeAsync(); + var doc2HashCode = await doc2.GetHashCodeAsync(); + var doc3HashCode = await doc3.GetHashCodeAsync(); + Assert.NotNull(doc1HashCode); + Assert.NotNull(doc2HashCode); + Assert.NotNull(doc3HashCode); + Assert.NotEmpty(doc1HashCode); + Assert.NotEmpty(doc2HashCode); + Assert.NotEmpty(doc3HashCode); + Assert.Equal(doc1HashCode, doc2HashCode); + Assert.Equal(doc1HashCode, doc3HashCode); } private static async Task ParseInputFileAsync(string filePath) @@ -1707,7 +1716,7 @@ private static async Task ParseInputFileAsync(string filePath) } [Fact] - public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat() + public async Task SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat() { // Arrange var expected = @"swagger: '2.0' @@ -1750,7 +1759,7 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo }; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1759,7 +1768,7 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo } [Fact] - public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() + public async Task SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() { // Arrange var expected = @"openapi: 3.0.4 @@ -1839,7 +1848,7 @@ public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() }; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1912,7 +1921,7 @@ public async Task SerializeDocumentWithWebhooksAsV3JsonWorks(bool produceTerseOu // Act DocumentWithWebhooks.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -1920,7 +1929,7 @@ public async Task SerializeDocumentWithWebhooksAsV3JsonWorks(bool produceTerseOu } [Fact] - public void SerializeDocumentWithWebhooksAsV3YamlWorks() + public async Task SerializeDocumentWithWebhooksAsV3YamlWorks() { // Arrange var expected = @"openapi: '3.1.1' @@ -1956,7 +1965,7 @@ public void SerializeDocumentWithWebhooksAsV3YamlWorks() description: Return a 200 status to indicate that the data was received successfully"; // Act - var actual = DocumentWithWebhooks.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await DocumentWithWebhooks.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -1965,7 +1974,7 @@ public void SerializeDocumentWithWebhooksAsV3YamlWorks() } [Fact] - public void SerializeDocumentWithRootJsonSchemaDialectPropertyWorks() + public async Task SerializeDocumentWithRootJsonSchemaDialectPropertyWorks() { // Arrange var doc = new OpenApiDocument @@ -1986,7 +1995,7 @@ public void SerializeDocumentWithRootJsonSchemaDialectPropertyWorks() paths: { }"; // Act - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral()); @@ -2062,12 +2071,12 @@ public async Task SerializeDocWithDollarIdInDollarRefSucceeds() type: number "; var doc = (await OpenApiDocument.LoadAsync("Models/Samples/docWithDollarId.yaml")).Document; - var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral()); } [Fact] - public void SerializeDocumentTagsWithMultipleExtensionsWorks() + public async Task SerializeDocumentTagsWithMultipleExtensionsWorks() { var expected = @"{ ""openapi"": ""3.0.4"", @@ -2116,7 +2125,7 @@ public void SerializeDocumentTagsWithMultipleExtensionsWorks() } }; - var actual = doc.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await doc.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral()); } } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs index fe699f7aa..c9ce9d217 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -24,10 +25,10 @@ public class OpenApiEncodingTests [Theory] [InlineData(OpenApiFormat.Json, "{ }")] [InlineData(OpenApiFormat.Yaml, "{ }")] - public void SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expected) + public async Task SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expected) { // Arrange & Act - var actual = BasicEncoding.Serialize(OpenApiSpecVersion.OpenApi3_0, format); + var actual = await BasicEncoding.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -36,7 +37,7 @@ public void SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expecte } [Fact] - public void SerializeAdvanceEncodingAsV3JsonWorks() + public async Task SerializeAdvanceEncodingAsV3JsonWorks() { // Arrange var expected = @@ -50,7 +51,7 @@ public void SerializeAdvanceEncodingAsV3JsonWorks() """; // Act - var actual = AdvanceEncoding.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceEncoding.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -59,7 +60,7 @@ public void SerializeAdvanceEncodingAsV3JsonWorks() } [Fact] - public void SerializeAdvanceEncodingAsV3YamlWorks() + public async Task SerializeAdvanceEncodingAsV3YamlWorks() { // Arrange var expected = @@ -71,7 +72,7 @@ public void SerializeAdvanceEncodingAsV3YamlWorks() """; // Act - var actual = AdvanceEncoding.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceEncoding.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs index 023f4d78f..c920c986b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs @@ -108,7 +108,7 @@ public async Task SerializeAdvancedExampleAsV3JsonWorksAsync(bool produceTerseOu // Act AdvancedExample.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -125,7 +125,7 @@ public async Task SerializeReferencedExampleAsV3JsonWorksAsync(bool produceTerse // Act OpenApiExampleReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -142,7 +142,7 @@ public async Task SerializeReferencedExampleAsV3JsonWithoutReferenceWorksAsync(b // Act ReferencedExample.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs index 25bf6315d..59c81865f 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -24,10 +25,10 @@ public class OpenApiExternalDocsTests [Theory] [InlineData(OpenApiFormat.Json, "{ }")] [InlineData(OpenApiFormat.Yaml, "{ }")] - public void SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string expected) + public async Task SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string expected) { // Arrange & Act - var actual = BasicExDocs.Serialize(OpenApiSpecVersion.OpenApi3_0, format); + var actual = await BasicExDocs.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -36,7 +37,7 @@ public void SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string exp } [Fact] - public void SerializeAdvanceExDocsAsV3JsonWorks() + public async Task SerializeAdvanceExDocsAsV3JsonWorks() { // Arrange var expected = @@ -48,7 +49,7 @@ public void SerializeAdvanceExDocsAsV3JsonWorks() """; // Act - var actual = AdvanceExDocs.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceExDocs.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -57,7 +58,7 @@ public void SerializeAdvanceExDocsAsV3JsonWorks() } [Fact] - public void SerializeAdvanceExDocsAsV3YamlWorks() + public async Task SerializeAdvanceExDocsAsV3YamlWorks() { // Arrange var expected = @@ -67,7 +68,7 @@ public void SerializeAdvanceExDocsAsV3YamlWorks() """; // Act - var actual = AdvanceExDocs.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceExDocs.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs index 72c4fdfaa..e368c587b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs @@ -48,7 +48,7 @@ public async Task SerializeAdvancedHeaderAsV3JsonWorksAsync(bool produceTerseOut // Act AdvancedHeader.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -65,7 +65,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWorksAsync(bool produceTerseO // Act OpenApiHeaderReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -82,7 +82,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWithoutReferenceWorksAsync(bo // Act ReferencedHeader.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -99,7 +99,7 @@ public async Task SerializeAdvancedHeaderAsV2JsonWorksAsync(bool produceTerseOut // Act AdvancedHeader.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -116,7 +116,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWorksAsync(bool produceTerseO // Act OpenApiHeaderReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -133,7 +133,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWithoutReferenceWorksAsync(bo // Act ReferencedHeader.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs index 980ce0565..a3c4633e1 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -62,10 +63,10 @@ public static IEnumerable BasicInfoJsonExpected() [Theory] [MemberData(nameof(BasicInfoJsonExpected))] - public void SerializeBasicInfoAsJsonWorks(OpenApiSpecVersion version, string expected) + public async Task SerializeBasicInfoAsJsonWorks(OpenApiSpecVersion version, string expected) { // Arrange & Act - var actual = BasicInfo.SerializeAsJson(version); + var actual = await BasicInfo.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -91,10 +92,10 @@ public static IEnumerable BasicInfoYamlExpected() [Theory] [MemberData(nameof(BasicInfoYamlExpected))] - public void SerializeBasicInfoAsYamlWorks(OpenApiSpecVersion version, string expected) + public async Task SerializeBasicInfoAsYamlWorks(OpenApiSpecVersion version, string expected) { // Arrange & Act - var actual = BasicInfo.SerializeAsYaml(version); + var actual = await BasicInfo.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -136,10 +137,10 @@ public static IEnumerable AdvanceInfoJsonExpect() [Theory] [MemberData(nameof(AdvanceInfoJsonExpect))] - public void SerializeAdvanceInfoAsJsonWorks(OpenApiSpecVersion version, string expected) + public async Task SerializeAdvanceInfoAsJsonWorks(OpenApiSpecVersion version, string expected) { // Arrange & Act - var actual = AdvanceInfo.SerializeAsJson(version); + var actual = await AdvanceInfo.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -177,10 +178,10 @@ public static IEnumerable AdvanceInfoYamlExpect() [Theory] [MemberData(nameof(AdvanceInfoYamlExpect))] - public void SerializeAdvanceInfoAsYamlWorks(OpenApiSpecVersion version, string expected) + public async Task SerializeAdvanceInfoAsYamlWorks(OpenApiSpecVersion version, string expected) { // Arrange & Act - var actual = AdvanceInfo.SerializeAsYaml(version); + var actual = await AdvanceInfo.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -189,7 +190,7 @@ public void SerializeAdvanceInfoAsYamlWorks(OpenApiSpecVersion version, string e } [Fact] - public void InfoVersionShouldAcceptDateStyledAsVersions() + public async Task InfoVersionShouldAcceptDateStyledAsVersions() { // Arrange var info = new OpenApiInfo @@ -205,7 +206,7 @@ public void InfoVersionShouldAcceptDateStyledAsVersions() """; // Act - var actual = info.Serialize(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml); + var actual = await info.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -214,7 +215,7 @@ public void InfoVersionShouldAcceptDateStyledAsVersions() } [Fact] - public void SerializeInfoObjectWithSummaryAsV31YamlWorks() + public async Task SerializeInfoObjectWithSummaryAsV31YamlWorks() { // Arrange var expected = @"title: Sample Pet Store App @@ -223,7 +224,7 @@ public void SerializeInfoObjectWithSummaryAsV31YamlWorks() summary: This is a sample server for a pet store."; // Act - var actual = InfoWithSummary.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await InfoWithSummary.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -232,7 +233,7 @@ public void SerializeInfoObjectWithSummaryAsV31YamlWorks() } [Fact] - public void SerializeInfoObjectWithSummaryAsV31JsonWorks() + public async Task SerializeInfoObjectWithSummaryAsV31JsonWorks() { // Arrange var expected = @"{ @@ -243,7 +244,7 @@ public void SerializeInfoObjectWithSummaryAsV31JsonWorks() }"; // Act - var actual = InfoWithSummary.SerializeAsJson(OpenApiSpecVersion.OpenApi3_1); + var actual = await InfoWithSummary.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs index bff5efe2c..7ee848a26 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -38,7 +39,7 @@ public class OpenApiLicenseTests [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeBasicLicenseAsJsonWorks(OpenApiSpecVersion version) + public async Task SerializeBasicLicenseAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -49,7 +50,7 @@ public void SerializeBasicLicenseAsJsonWorks(OpenApiSpecVersion version) """; // Act - var actual = BasicLicense.SerializeAsJson(version); + var actual = await BasicLicense.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -60,13 +61,13 @@ public void SerializeBasicLicenseAsJsonWorks(OpenApiSpecVersion version) [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeBasicLicenseAsYamlWorks(OpenApiSpecVersion version) + public async Task SerializeBasicLicenseAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = "name: Apache 2.0"; // Act - var actual = BasicLicense.SerializeAsYaml(version); + var actual = await BasicLicense.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -77,7 +78,7 @@ public void SerializeBasicLicenseAsYamlWorks(OpenApiSpecVersion version) [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvanceLicenseAsJsonWorks(OpenApiSpecVersion version) + public async Task SerializeAdvanceLicenseAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -90,7 +91,7 @@ public void SerializeAdvanceLicenseAsJsonWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvanceLicense.SerializeAsJson(version); + var actual = await AdvanceLicense.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -101,7 +102,7 @@ public void SerializeAdvanceLicenseAsJsonWorks(OpenApiSpecVersion version) [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvanceLicenseAsYamlWorks(OpenApiSpecVersion version) + public async Task SerializeAdvanceLicenseAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -112,7 +113,7 @@ public void SerializeAdvanceLicenseAsYamlWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvanceLicense.SerializeAsYaml(version); + var actual = await AdvanceLicense.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -136,7 +137,7 @@ public void ShouldCopyFromOriginalObjectWithoutMutating() } [Fact] - public void SerializeLicenseWithIdentifierAsJsonWorks() + public async Task SerializeLicenseWithIdentifierAsJsonWorks() { // Arrange var expected = @@ -146,21 +147,21 @@ public void SerializeLicenseWithIdentifierAsJsonWorks() }"; // Act - var actual = LicenseWithIdentifier.SerializeAsJson(OpenApiSpecVersion.OpenApi3_1); + var actual = await LicenseWithIdentifier.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1); // Assert Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), actual.MakeLineBreaksEnvironmentNeutral()); } [Fact] - public void SerializeLicenseWithIdentifierAsYamlWorks() + public async Task SerializeLicenseWithIdentifierAsYamlWorks() { // Arrange var expected = @"name: Apache 2.0 identifier: Apache-2.0"; // Act - var actual = LicenseWithIdentifier.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1); + var actual = await LicenseWithIdentifier.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); // Assert Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), actual.MakeLineBreaksEnvironmentNeutral()); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs index 194d909b1..e1a949348 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs @@ -83,7 +83,7 @@ public async Task SerializeAdvancedLinkAsV3JsonWorksAsync(bool produceTerseOutpu // Act AdvancedLink.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -100,7 +100,7 @@ public async Task SerializeReferencedLinkAsV3JsonWorksAsync(bool produceTerseOut // Act LinkReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -117,7 +117,7 @@ public async Task SerializeReferencedLinkAsV3JsonWithoutReferenceWorksAsync(bool // Act ReferencedLink.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs index d4eecf7ee..a47ef4052 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json.Nodes; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -133,10 +134,10 @@ public OpenApiMediaTypeTests(ITestOutputHelper output) [Theory] [InlineData(OpenApiFormat.Json, "{ }")] [InlineData(OpenApiFormat.Yaml, "{ }")] - public void SerializeBasicMediaTypeAsV3Works(OpenApiFormat format, string expected) + public async Task SerializeBasicMediaTypeAsV3Works(OpenApiFormat format, string expected) { // Arrange & Act - var actual = BasicMediaType.Serialize(OpenApiSpecVersion.OpenApi3_0, format); + var actual = await BasicMediaType.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -145,7 +146,7 @@ public void SerializeBasicMediaTypeAsV3Works(OpenApiFormat format, string expect } [Fact] - public void SerializeAdvanceMediaTypeAsV3JsonWorks() + public async Task SerializeAdvanceMediaTypeAsV3JsonWorks() { // Arrange var expected = @@ -164,7 +165,7 @@ public void SerializeAdvanceMediaTypeAsV3JsonWorks() """; // Act - var actual = AdvanceMediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceMediaType.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -173,7 +174,7 @@ public void SerializeAdvanceMediaTypeAsV3JsonWorks() } [Fact] - public void SerializeAdvanceMediaTypeAsV3YamlWorks() + public async Task SerializeAdvanceMediaTypeAsV3YamlWorks() { // Arrange var expected = @@ -188,7 +189,7 @@ public void SerializeAdvanceMediaTypeAsV3YamlWorks() """; // Act - var actual = AdvanceMediaType.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvanceMediaType.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -197,7 +198,7 @@ public void SerializeAdvanceMediaTypeAsV3YamlWorks() } [Fact] - public void SerializeMediaTypeWithObjectExampleAsV3YamlWorks() + public async Task SerializeMediaTypeWithObjectExampleAsV3YamlWorks() { // Arrange var expected = @@ -223,7 +224,7 @@ public void SerializeMediaTypeWithObjectExampleAsV3YamlWorks() """; // Act - var actual = MediaTypeWithObjectExample.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithObjectExample.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -232,7 +233,7 @@ public void SerializeMediaTypeWithObjectExampleAsV3YamlWorks() } [Fact] - public void SerializeMediaTypeWithObjectExampleAsV3JsonWorks() + public async Task SerializeMediaTypeWithObjectExampleAsV3JsonWorks() { // Arrange var expected = @@ -274,7 +275,7 @@ public void SerializeMediaTypeWithObjectExampleAsV3JsonWorks() """; // Act - var actual = MediaTypeWithObjectExample.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithObjectExample.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -283,7 +284,7 @@ public void SerializeMediaTypeWithObjectExampleAsV3JsonWorks() } [Fact] - public void SerializeMediaTypeWithXmlExampleAsV3YamlWorks() + public async Task SerializeMediaTypeWithXmlExampleAsV3YamlWorks() { // Arrange var expected = @@ -298,7 +299,7 @@ public void SerializeMediaTypeWithXmlExampleAsV3YamlWorks() """; // Act - var actual = MediaTypeWithXmlExample.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithXmlExample.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -307,7 +308,7 @@ public void SerializeMediaTypeWithXmlExampleAsV3YamlWorks() } [Fact] - public void SerializeMediaTypeWithXmlExampleAsV3JsonWorks() + public async Task SerializeMediaTypeWithXmlExampleAsV3JsonWorks() { // Arrange var expected = @@ -326,7 +327,7 @@ public void SerializeMediaTypeWithXmlExampleAsV3JsonWorks() """; // Act - var actual = MediaTypeWithXmlExample.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithXmlExample.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -335,7 +336,7 @@ public void SerializeMediaTypeWithXmlExampleAsV3JsonWorks() } [Fact] - public void SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() + public async Task SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() { // Arrange var expected = @@ -363,7 +364,7 @@ public void SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() """; // Act - var actual = MediaTypeWithObjectExamples.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithObjectExamples.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); _output.WriteLine(actual); // Assert @@ -373,7 +374,7 @@ public void SerializeMediaTypeWithObjectExamplesAsV3YamlWorks() } [Fact] - public void SerializeMediaTypeWithObjectExamplesAsV3JsonWorks() + public async Task SerializeMediaTypeWithObjectExamplesAsV3JsonWorks() { // Arrange var expected = @@ -419,7 +420,7 @@ public void SerializeMediaTypeWithObjectExamplesAsV3JsonWorks() """; // Act - var actual = MediaTypeWithObjectExamples.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await MediaTypeWithObjectExamples.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); _output.WriteLine(actual); // Assert diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs index 3327887c9..e47d1db9b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -37,7 +38,7 @@ public class OpenApiOAuthFlowTests }; [Fact] - public void SerializeBasicOAuthFlowAsV3JsonWorks() + public async Task SerializeBasicOAuthFlowAsV3JsonWorks() { // Arrange var expected = @@ -48,7 +49,7 @@ public void SerializeBasicOAuthFlowAsV3JsonWorks() """; // Act - var actual = BasicOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicOAuthFlow.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -57,14 +58,14 @@ public void SerializeBasicOAuthFlowAsV3JsonWorks() } [Fact] - public void SerializeBasicOAuthFlowAsV3YamlWorks() + public async Task SerializeBasicOAuthFlowAsV3YamlWorks() { // Arrange var expected = @"scopes: { }"; // Act - var actual = BasicOAuthFlow.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicOAuthFlow.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -73,7 +74,7 @@ public void SerializeBasicOAuthFlowAsV3YamlWorks() } [Fact] - public void SerializePartialOAuthFlowAsV3JsonWorks() + public async Task SerializePartialOAuthFlowAsV3JsonWorks() { // Arrange var expected = @@ -88,7 +89,7 @@ public void SerializePartialOAuthFlowAsV3JsonWorks() """; // Act - var actual = PartialOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await PartialOAuthFlow.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -97,7 +98,7 @@ public void SerializePartialOAuthFlowAsV3JsonWorks() } [Fact] - public void SerializeCompleteOAuthFlowAsV3JsonWorks() + public async Task SerializeCompleteOAuthFlowAsV3JsonWorks() { // Arrange var expected = @@ -114,7 +115,7 @@ public void SerializeCompleteOAuthFlowAsV3JsonWorks() """; // Act - var actual = CompleteOAuthFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await CompleteOAuthFlow.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs index 1bb473a89..6e1b2e102 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -51,14 +52,14 @@ public class OpenApiOAuthFlowsTests }; [Fact] - public void SerializeBasicOAuthFlowsAsV3JsonWorks() + public async Task SerializeBasicOAuthFlowsAsV3JsonWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicOAuthFlows.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicOAuthFlows.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -67,14 +68,14 @@ public void SerializeBasicOAuthFlowsAsV3JsonWorks() } [Fact] - public void SerializeBasicOAuthFlowsAsV3YamlWorks() + public async Task SerializeBasicOAuthFlowsAsV3YamlWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicOAuthFlows.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicOAuthFlows.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -83,7 +84,7 @@ public void SerializeBasicOAuthFlowsAsV3YamlWorks() } [Fact] - public void SerializeOAuthFlowsWithSingleFlowAsV3JsonWorks() + public async Task SerializeOAuthFlowsWithSingleFlowAsV3JsonWorks() { // Arrange var expected = @@ -100,7 +101,7 @@ public void SerializeOAuthFlowsWithSingleFlowAsV3JsonWorks() """; // Act - var actual = OAuthFlowsWithSingleFlow.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await OAuthFlowsWithSingleFlow.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -109,7 +110,7 @@ public void SerializeOAuthFlowsWithSingleFlowAsV3JsonWorks() } [Fact] - public void SerializeOAuthFlowsWithMultipleFlowsAsV3JsonWorks() + public async Task SerializeOAuthFlowsWithMultipleFlowsAsV3JsonWorks() { // Arrange var expected = @@ -134,7 +135,7 @@ public void SerializeOAuthFlowsWithMultipleFlowsAsV3JsonWorks() """; // Act - var actual = OAuthFlowsWithMultipleFlows.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await OAuthFlowsWithMultipleFlows.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs index 5f6b5f4e7..654db50d5 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -256,7 +257,7 @@ public class OpenApiOperationTests }; [Fact] - public void SerializeBasicOperationAsV3JsonWorks() + public async Task SerializeBasicOperationAsV3JsonWorks() { // Arrange var expected = @@ -267,7 +268,7 @@ public void SerializeBasicOperationAsV3JsonWorks() """; // Act - var actual = _basicOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await _basicOperation.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -276,7 +277,7 @@ public void SerializeBasicOperationAsV3JsonWorks() } [Fact] - public void SerializeOperationWithBodyAsV3JsonWorks() + public async Task SerializeOperationWithBodyAsV3JsonWorks() { // Arrange var expected = @@ -339,7 +340,7 @@ public void SerializeOperationWithBodyAsV3JsonWorks() """; // Act - var actual = _operationWithBody.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await _operationWithBody.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -348,7 +349,7 @@ public void SerializeOperationWithBodyAsV3JsonWorks() } [Fact] - public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() + public async Task SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() { // Arrange var expected = @@ -423,7 +424,7 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() """; // Act - var actual = _advancedOperationWithTagsAndSecurity.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await _advancedOperationWithTagsAndSecurity.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -432,7 +433,7 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV3JsonWorks() } [Fact] - public void SerializeBasicOperationAsV2JsonWorks() + public async Task SerializeBasicOperationAsV2JsonWorks() { // Arrange var expected = @@ -443,7 +444,7 @@ public void SerializeBasicOperationAsV2JsonWorks() """; // Act - var actual = _basicOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await _basicOperation.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -452,7 +453,7 @@ public void SerializeBasicOperationAsV2JsonWorks() } [Fact] - public void SerializeOperationWithFormDataAsV3JsonWorks() + public async Task SerializeOperationWithFormDataAsV3JsonWorks() { // Arrange var expected = @@ -522,7 +523,7 @@ public void SerializeOperationWithFormDataAsV3JsonWorks() """; // Act - var actual = _operationWithFormData.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await _operationWithFormData.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -531,7 +532,7 @@ public void SerializeOperationWithFormDataAsV3JsonWorks() } [Fact] - public void SerializeOperationWithFormDataAsV2JsonWorks() + public async Task SerializeOperationWithFormDataAsV2JsonWorks() { // Arrange var expected = @@ -578,7 +579,7 @@ public void SerializeOperationWithFormDataAsV2JsonWorks() """; // Act - var actual = _operationWithFormData.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await _operationWithFormData.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -587,7 +588,7 @@ public void SerializeOperationWithFormDataAsV2JsonWorks() } [Fact] - public void SerializeOperationWithBodyAsV2JsonWorks() + public async Task SerializeOperationWithBodyAsV2JsonWorks() { // Arrange var expected = @@ -647,7 +648,7 @@ public void SerializeOperationWithBodyAsV2JsonWorks() """; // Act - var actual = _operationWithBody.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await _operationWithBody.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -656,7 +657,7 @@ public void SerializeOperationWithBodyAsV2JsonWorks() } [Fact] - public void SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() + public async Task SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() { // Arrange var expected = @@ -728,7 +729,7 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() """; // Act - var actual = _advancedOperationWithTagsAndSecurity.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await _advancedOperationWithTagsAndSecurity.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -737,7 +738,7 @@ public void SerializeAdvancedOperationWithTagAndSecurityAsV2JsonWorks() } [Fact] - public void SerializeOperationWithNullCollectionAsV2JsonWorks() + public async Task SerializeOperationWithNullCollectionAsV2JsonWorks() { // Arrange var expected = @@ -753,7 +754,7 @@ public void SerializeOperationWithNullCollectionAsV2JsonWorks() }; // Act - var actual = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await operation.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -803,7 +804,7 @@ public void EnsureOpenApiOperationCopyConstructorCopiesNull() } [Fact] - public void EnsureOpenApiOperationCopyConstructor_SerializationResultsInSame() + public async Task EnsureOpenApiOperationCopyConstructor_SerializationResultsInSame() { var operations = new[] { @@ -816,9 +817,9 @@ public void EnsureOpenApiOperationCopyConstructor_SerializationResultsInSame() foreach (var operation in operations) { // Act - var expected = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var expected = await operation.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); var openApiOperation = new OpenApiOperation(operation); - var actual = openApiOperation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await openApiOperation.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual.Should().Be(expected); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs index 95596b787..8b4d8a42a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Text.Json.Nodes; using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -194,7 +193,7 @@ public void WhenStyleIsFormTheDefaultValueOfExplodeShouldBeTrueOtherwiseFalse(Pa [InlineData(ParameterLocation.Header, ParameterStyle.Simple)] [InlineData(ParameterLocation.Cookie, ParameterStyle.Form)] [InlineData(null, ParameterStyle.Simple)] - public void WhenStyleAndInIsNullTheDefaultValueOfStyleShouldBeSimple(ParameterLocation? inValue, ParameterStyle expectedStyle) + public async Task WhenStyleAndInIsNullTheDefaultValueOfStyleShouldBeSimple(ParameterLocation? inValue, ParameterStyle expectedStyle) { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -207,13 +206,13 @@ public void WhenStyleAndInIsNullTheDefaultValueOfStyleShouldBeSimple(ParameterLo // Act & Assert parameter.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); parameter.Style.Should().Be(expectedStyle); } [Fact] - public void SerializeQueryParameterWithMissingStyleSucceeds() + public async Task SerializeQueryParameterWithMissingStyleSucceeds() { // Arrange var expected = @"name: id @@ -224,14 +223,14 @@ public void SerializeQueryParameterWithMissingStyleSucceeds() type: integer"; // Act - var actual = QueryParameterWithMissingStyle.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await QueryParameterWithMissingStyle.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual.MakeLineBreaksEnvironmentNeutral().Should().Be(expected.MakeLineBreaksEnvironmentNeutral()); } [Fact] - public void SerializeBasicParameterAsV3JsonWorks() + public async Task SerializeBasicParameterAsV3JsonWorks() { // Arrange var expected = @@ -243,7 +242,7 @@ public void SerializeBasicParameterAsV3JsonWorks() """; // Act - var actual = BasicParameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicParameter.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -252,7 +251,7 @@ public void SerializeBasicParameterAsV3JsonWorks() } [Fact] - public void SerializeAdvancedParameterAsV3JsonWorks() + public async Task SerializeAdvancedParameterAsV3JsonWorks() { // Arrange var expected = @@ -287,7 +286,7 @@ public void SerializeAdvancedParameterAsV3JsonWorks() """; // Act - var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedPathParameterWithSchema.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -296,7 +295,7 @@ public void SerializeAdvancedParameterAsV3JsonWorks() } [Fact] - public void SerializeAdvancedParameterAsV2JsonWorks() + public async Task SerializeAdvancedParameterAsV2JsonWorks() { // Arrange var expected = @@ -317,7 +316,7 @@ public void SerializeAdvancedParameterAsV2JsonWorks() """; // Act - var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await AdvancedPathParameterWithSchema.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -336,7 +335,7 @@ public async Task SerializeReferencedParameterAsV3JsonWorksAsync(bool produceTer // Act OpenApiParameterReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -353,7 +352,7 @@ public async Task SerializeReferencedParameterAsV3JsonWithoutReferenceWorksAsync // Act ReferencedParameter.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -370,7 +369,7 @@ public async Task SerializeReferencedParameterAsV2JsonWorksAsync(bool produceTer // Act OpenApiParameterReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -387,7 +386,7 @@ public async Task SerializeReferencedParameterAsV2JsonWithoutReferenceWorksAsync // Act ReferencedParameter.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -404,7 +403,7 @@ public async Task SerializeParameterWithSchemaTypeObjectAsV2JsonWorksAsync(bool // Act AdvancedHeaderParameterWithSchemaTypeObject.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -421,7 +420,7 @@ public async Task SerializeParameterWithFormStyleAndExplodeFalseWorksAsync(bool // Act ParameterWithFormStyleAndExplodeFalse.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -438,7 +437,7 @@ public async Task SerializeParameterWithFormStyleAndExplodeTrueWorksAsync(bool p // Act ParameterWithFormStyleAndExplodeTrue.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs index 1a8497e5a..4e6e47509 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiReferenceTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -85,7 +86,7 @@ public void SettingExternalReferenceV2ShouldSucceed(string expected, string exte } [Fact] - public void SerializeSchemaReferenceAsJsonV3Works() + public async Task SerializeSchemaReferenceAsJsonV3Works() { // Arrange var reference = new OpenApiReference { Type = ReferenceType.Schema, Id = "Pet" }; @@ -97,7 +98,7 @@ public void SerializeSchemaReferenceAsJsonV3Works() """; // Act - var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await reference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -106,7 +107,7 @@ public void SerializeSchemaReferenceAsJsonV3Works() } [Fact] - public void SerializeSchemaReferenceAsYamlV3Works() + public async Task SerializeSchemaReferenceAsYamlV3Works() { // Arrange var reference = new OpenApiReference @@ -118,14 +119,14 @@ public void SerializeSchemaReferenceAsYamlV3Works() var expected = @"$ref: '#/components/schemas/Pet'"; // Act - var actual = reference.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await reference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual.Should().Be(expected); } [Fact] - public void SerializeSchemaReferenceAsJsonV2Works() + public async Task SerializeSchemaReferenceAsJsonV2Works() { // Arrange var reference = new OpenApiReference @@ -142,14 +143,14 @@ public void SerializeSchemaReferenceAsJsonV2Works() """.MakeLineBreaksEnvironmentNeutral(); // Act - var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await reference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual.MakeLineBreaksEnvironmentNeutral().Should().Be(expected); } [Fact] - public void SerializeSchemaReferenceAsYamlV2Works() + public async Task SerializeSchemaReferenceAsYamlV2Works() { // Arrange var reference = new OpenApiReference @@ -160,14 +161,14 @@ public void SerializeSchemaReferenceAsYamlV2Works() var expected = @"$ref: '#/definitions/Pet'"; // Act - var actual = reference.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await reference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual.Should().Be(expected); } [Fact] - public void SerializeExternalReferenceAsJsonV2Works() + public async Task SerializeExternalReferenceAsJsonV2Works() { // Arrange var reference = new OpenApiReference @@ -185,7 +186,7 @@ public void SerializeExternalReferenceAsJsonV2Works() """; // Act - var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await reference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -194,7 +195,7 @@ public void SerializeExternalReferenceAsJsonV2Works() } [Fact] - public void SerializeExternalReferenceAsYamlV2Works() + public async Task SerializeExternalReferenceAsYamlV2Works() { // Arrange var reference = new OpenApiReference @@ -206,14 +207,14 @@ public void SerializeExternalReferenceAsYamlV2Works() var expected = @"$ref: main.json#/definitions/Pets"; // Act - var actual = reference.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await reference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual.Should().Be(expected); } [Fact] - public void SerializeExternalReferenceAsJsonV3Works() + public async Task SerializeExternalReferenceAsJsonV3Works() { // Arrange var reference = new OpenApiReference { ExternalResource = "main.json", Type = ReferenceType.Schema, Id = "Pets" }; @@ -226,7 +227,7 @@ public void SerializeExternalReferenceAsJsonV3Works() """; // Act - var actual = reference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await reference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); expected = expected.MakeLineBreaksEnvironmentNeutral(); actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -235,14 +236,14 @@ public void SerializeExternalReferenceAsJsonV3Works() } [Fact] - public void SerializeExternalReferenceAsYamlV3Works() + public async Task SerializeExternalReferenceAsYamlV3Works() { // Arrange var reference = new OpenApiReference { ExternalResource = "main.json", Type = ReferenceType.Schema, Id = "Pets" }; var expected = @"$ref: main.json#/components/schemas/Pets"; // Act - var actual = reference.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await reference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual.Should().Be(expected); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs index ebffa38fd..f391ef4d8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs @@ -59,7 +59,7 @@ public async Task SerializeAdvancedRequestBodyAsV3JsonWorksAsync(bool produceTer // Act AdvancedRequestBody.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -76,7 +76,7 @@ public async Task SerializeReferencedRequestBodyAsV3JsonWorksAsync(bool produceT // Act OpenApiRequestBodyReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -93,7 +93,7 @@ public async Task SerializeReferencedRequestBodyAsV3JsonWithoutReferenceWorksAsy // Act ReferencedRequestBody.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs index f09d41da8..5026a0549 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs @@ -186,7 +186,7 @@ public OpenApiResponseTests(ITestOutputHelper output) [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json)] [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml)] [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml)] - public void SerializeBasicResponseWorks( + public async Task SerializeBasicResponseWorks( OpenApiSpecVersion version, OpenApiFormat format) { @@ -196,7 +196,7 @@ public void SerializeBasicResponseWorks( }" : @"description: "; // Act - var actual = BasicResponse.Serialize(version, format); + var actual = await BasicResponse.SerializeAsync(version, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -205,7 +205,7 @@ public void SerializeBasicResponseWorks( } [Fact] - public void SerializeAdvancedResponseAsV3JsonWorks() + public async Task SerializeAdvancedResponseAsV3JsonWorks() { // Arrange var expected = @"{ @@ -239,7 +239,7 @@ public void SerializeAdvancedResponseAsV3JsonWorks() }"; // Act - var actual = AdvancedV3Response.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedV3Response.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -248,7 +248,7 @@ public void SerializeAdvancedResponseAsV3JsonWorks() } [Fact] - public void SerializeAdvancedResponseAsV3YamlWorks() + public async Task SerializeAdvancedResponseAsV3YamlWorks() { // Arrange var expected = @@ -272,7 +272,7 @@ public void SerializeAdvancedResponseAsV3YamlWorks() myextension: myextensionvalue"; // Act - var actual = AdvancedV3Response.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedV3Response.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -281,7 +281,7 @@ public void SerializeAdvancedResponseAsV3YamlWorks() } [Fact] - public void SerializeAdvancedResponseAsV2JsonWorks() + public async Task SerializeAdvancedResponseAsV2JsonWorks() { // Arrange var expected = @"{ @@ -309,7 +309,7 @@ public void SerializeAdvancedResponseAsV2JsonWorks() }"; // Act - var actual = AdvancedV2Response.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await AdvancedV2Response.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -318,7 +318,7 @@ public void SerializeAdvancedResponseAsV2JsonWorks() } [Fact] - public void SerializeAdvancedResponseAsV2YamlWorks() + public async Task SerializeAdvancedResponseAsV2YamlWorks() { // Arrange var expected = @@ -339,7 +339,7 @@ public void SerializeAdvancedResponseAsV2YamlWorks() type: integer"; // Act - var actual = AdvancedV2Response.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0); + var actual = await AdvancedV2Response.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -358,7 +358,7 @@ public async Task SerializeReferencedResponseAsV3JsonWorksAsync(bool produceTers // Act V3OpenApiResponseReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -375,7 +375,7 @@ public async Task SerializeReferencedResponseAsV3JsonWithoutReferenceWorksAsync( // Act ReferencedV3Response.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -392,7 +392,7 @@ public async Task SerializeReferencedResponseAsV2JsonWorksAsync(bool produceTers // Act V2OpenApiResponseReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -409,7 +409,7 @@ public async Task SerializeReferencedResponseAsV2JsonWithoutReferenceWorksAsync( // Act ReferencedV2Response.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index 75ea5ca47..49f1596c5 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -215,13 +215,13 @@ public class OpenApiSchemaTests }; [Fact] - public void SerializeBasicSchemaAsV3JsonWorks() + public async Task SerializeBasicSchemaAsV3JsonWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicSchema.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -230,7 +230,7 @@ public void SerializeBasicSchemaAsV3JsonWorks() } [Fact] - public void SerializeAdvancedSchemaNumberAsV3JsonWorks() + public async Task SerializeAdvancedSchemaNumberAsV3JsonWorks() { // Arrange var expected = @@ -251,7 +251,7 @@ public void SerializeAdvancedSchemaNumberAsV3JsonWorks() """; // Act - var actual = AdvancedSchemaNumber.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedSchemaNumber.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -260,7 +260,7 @@ public void SerializeAdvancedSchemaNumberAsV3JsonWorks() } [Fact] - public void SerializeAdvancedSchemaObjectAsV3JsonWorks() + public async Task SerializeAdvancedSchemaObjectAsV3JsonWorks() { // Arrange var expected = @@ -303,7 +303,7 @@ public void SerializeAdvancedSchemaObjectAsV3JsonWorks() """; // Act - var actual = AdvancedSchemaObject.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedSchemaObject.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -312,7 +312,7 @@ public void SerializeAdvancedSchemaObjectAsV3JsonWorks() } [Fact] - public void SerializeAdvancedSchemaWithAllOfAsV3JsonWorks() + public async Task SerializeAdvancedSchemaWithAllOfAsV3JsonWorks() { // Arrange var expected = @@ -358,7 +358,7 @@ public void SerializeAdvancedSchemaWithAllOfAsV3JsonWorks() """; // Act - var actual = AdvancedSchemaWithAllOf.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedSchemaWithAllOf.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -377,7 +377,7 @@ public async Task SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync(bo // Act ReferencedSchema.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -394,7 +394,7 @@ public async Task SerializeReferencedSchemaAsV3JsonWorksAsync(bool produceTerseO // Act ReferencedSchema.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -411,14 +411,14 @@ public async Task SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync(bool prod // Act AdvancedSchemaWithRequiredPropertiesObject.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } [Fact] - public void SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildrenSchema() + public async Task SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildrenSchema() { // Arrange var schema = new OpenApiSchema @@ -440,7 +440,7 @@ public void SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildre // Act // Serialize as V2 schema.SerializeAsV2(openApiJsonWriter); - openApiJsonWriter.Flush(); + await openApiJsonWriter.FlushAsync(); var v2Schema = outputStringWriter.GetStringBuilder().ToString().MakeLineBreaksEnvironmentNeutral(); @@ -604,7 +604,7 @@ public void OpenApiWalkerVisitsOpenApiSchemaNot() } [Fact] - public void SerializeSchemaWithUnrecognizedPropertiesWorks() + public async Task SerializeSchemaWithUnrecognizedPropertiesWorks() { // Arrange var schema = new OpenApiSchema @@ -624,7 +624,7 @@ public void SerializeSchemaWithUnrecognizedPropertiesWorks() }"; // Act - var actual = schema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_1); + var actual = await schema.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1); // Assert actual.MakeLineBreaksEnvironmentNeutral().Should().Be(expected.MakeLineBreaksEnvironmentNeutral()); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs index 1e9e13323..8dcebc315 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecurityRequirementTests.cs @@ -72,13 +72,13 @@ public class OpenApiSecurityRequirementTests }; [Fact] - public void SerializeBasicSecurityRequirementAsV3JsonWorks() + public async Task SerializeBasicSecurityRequirementAsV3JsonWorks() { // Arrange var expected = @"{ }"; // Act - var actual = BasicSecurityRequirement.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicSecurityRequirement.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -97,14 +97,14 @@ public async Task SerializeSecurityRequirementAsV3JsonWorksAsync(bool produceTer // Act SecurityRequirementWithReferencedSecurityScheme.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } [Fact] - public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV3JsonWorks() + public async Task SerializeSecurityRequirementWithReferencedSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -124,7 +124,7 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV3JsonWork """; // Act - var actual = SecurityRequirementWithReferencedSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await SecurityRequirementWithReferencedSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -133,7 +133,7 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV3JsonWork } [Fact] - public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV2JsonWorks() + public async Task SerializeSecurityRequirementWithReferencedSecuritySchemeAsV2JsonWorks() { // Arrange var expected = @@ -153,7 +153,7 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV2JsonWork """; // Act - var actual = SecurityRequirementWithReferencedSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + var actual = await SecurityRequirementWithReferencedSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -162,7 +162,7 @@ public void SerializeSecurityRequirementWithReferencedSecuritySchemeAsV2JsonWork } [Fact] - public void SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV3JsonShouldSkipUnserializableKeyValuePair() + public async Task SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV3JsonShouldSkipUnserializableKeyValuePair() { // Arrange var expected = @@ -178,7 +178,7 @@ public void SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV3JsonSh """; // Act - var actual = SecurityRequirementWithUnreferencedSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await SecurityRequirementWithUnreferencedSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -187,7 +187,7 @@ public void SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV3JsonSh } [Fact] - public void SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV2JsonShouldSkipUnserializableKeyValuePair() + public async Task SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV2JsonShouldSkipUnserializableKeyValuePair() { // Arrange var expected = @@ -204,7 +204,7 @@ public void SerializeSecurityRequirementWithUnreferencedSecuritySchemeAsV2JsonSh // Act var actual = - SecurityRequirementWithUnreferencedSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0); + await SecurityRequirementWithUnreferencedSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi2_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs index 58794373d..ebe06d4d6 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs @@ -115,7 +115,7 @@ public class OpenApiSecuritySchemeTests }; [Fact] - public void SerializeApiKeySecuritySchemeAsV3JsonWorks() + public async Task SerializeApiKeySecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -129,7 +129,7 @@ public void SerializeApiKeySecuritySchemeAsV3JsonWorks() """; // Act - var actual = ApiKeySecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await ApiKeySecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -138,7 +138,7 @@ public void SerializeApiKeySecuritySchemeAsV3JsonWorks() } [Fact] - public void SerializeApiKeySecuritySchemeAsV3YamlWorks() + public async Task SerializeApiKeySecuritySchemeAsV3YamlWorks() { // Arrange var expected = @@ -150,7 +150,7 @@ public void SerializeApiKeySecuritySchemeAsV3YamlWorks() """; // Act - var actual = ApiKeySecurityScheme.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await ApiKeySecurityScheme.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -159,7 +159,7 @@ public void SerializeApiKeySecuritySchemeAsV3YamlWorks() } [Fact] - public void SerializeHttpBasicSecuritySchemeAsV3JsonWorks() + public async Task SerializeHttpBasicSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -172,7 +172,7 @@ public void SerializeHttpBasicSecuritySchemeAsV3JsonWorks() """; // Act - var actual = HttpBasicSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await HttpBasicSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -181,7 +181,7 @@ public void SerializeHttpBasicSecuritySchemeAsV3JsonWorks() } [Fact] - public void SerializeHttpBearerSecuritySchemeAsV3JsonWorks() + public async Task SerializeHttpBearerSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -195,7 +195,7 @@ public void SerializeHttpBearerSecuritySchemeAsV3JsonWorks() """; // Act - var actual = HttpBearerSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await HttpBearerSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -204,7 +204,7 @@ public void SerializeHttpBearerSecuritySchemeAsV3JsonWorks() } [Fact] - public void SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks() + public async Task SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -225,7 +225,7 @@ public void SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks() """; // Act - var actual = OAuth2SingleFlowSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await OAuth2SingleFlowSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -234,7 +234,7 @@ public void SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks() } [Fact] - public void SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks() + public async Task SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -271,7 +271,7 @@ public void SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks() """; // Act - var actual = OAuth2MultipleFlowSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await OAuth2MultipleFlowSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -280,7 +280,7 @@ public void SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks() } [Fact] - public void SerializeOpenIdConnectSecuritySchemeAsV3JsonWorks() + public async Task SerializeOpenIdConnectSecuritySchemeAsV3JsonWorks() { // Arrange var expected = @@ -293,7 +293,7 @@ public void SerializeOpenIdConnectSecuritySchemeAsV3JsonWorks() """; // Act - var actual = OpenIdConnectSecurityScheme.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await OpenIdConnectSecurityScheme.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -312,7 +312,7 @@ public async Task SerializeReferencedSecuritySchemeAsV3JsonWorksAsync(bool produ // Act OpenApiSecuritySchemeReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -329,7 +329,7 @@ public async Task SerializeReferencedSecuritySchemeAsV3JsonWithoutReferenceWorks // Act ReferencedSecurityScheme.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs index 19fc00aeb..1d4cc248c 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -47,7 +48,7 @@ public class OpenApiServerTests }; [Fact] - public void SerializeBasicServerAsV3JsonWorks() + public async Task SerializeBasicServerAsV3JsonWorks() { // Arrange var expected = @@ -59,7 +60,7 @@ public void SerializeBasicServerAsV3JsonWorks() """; // Act - var actual = BasicServer.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await BasicServer.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -68,7 +69,7 @@ public void SerializeBasicServerAsV3JsonWorks() } [Fact] - public void SerializeAdvancedServerAsV3JsonWorks() + public async Task SerializeAdvancedServerAsV3JsonWorks() { // Arrange var expected = @@ -97,7 +98,7 @@ public void SerializeAdvancedServerAsV3JsonWorks() """; // Act - var actual = AdvancedServer.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedServer.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs index ca23e3b97..032b9c7f3 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -27,10 +28,10 @@ public class OpenApiServerVariableTests [Theory] [InlineData(OpenApiFormat.Json, "{ }")] [InlineData(OpenApiFormat.Yaml, "{ }")] - public void SerializeBasicServerVariableAsV3Works(OpenApiFormat format, string expected) + public async Task SerializeBasicServerVariableAsV3Works(OpenApiFormat format, string expected) { // Arrange & Act - var actual = BasicServerVariable.Serialize(OpenApiSpecVersion.OpenApi3_0, format); + var actual = await BasicServerVariable.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -39,7 +40,7 @@ public void SerializeBasicServerVariableAsV3Works(OpenApiFormat format, string e } [Fact] - public void SerializeAdvancedServerVariableAsV3JsonWorks() + public async Task SerializeAdvancedServerVariableAsV3JsonWorks() { // Arrange var expected = @@ -55,7 +56,7 @@ public void SerializeAdvancedServerVariableAsV3JsonWorks() """; // Act - var actual = AdvancedServerVariable.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedServerVariable.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -64,7 +65,7 @@ public void SerializeAdvancedServerVariableAsV3JsonWorks() } [Fact] - public void SerializeAdvancedServerVariableAsV3YamlWorks() + public async Task SerializeAdvancedServerVariableAsV3YamlWorks() { // Arrange var expected = @@ -77,7 +78,7 @@ public void SerializeAdvancedServerVariableAsV3YamlWorks() """; // Act - var actual = AdvancedServerVariable.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0); + var actual = await AdvancedServerVariable.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs index 24c186b0b..62616fe25 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs @@ -44,7 +44,7 @@ public async Task SerializeBasicTagAsV3JsonWithoutReferenceWorksAsync(bool produ // Act BasicTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -61,7 +61,7 @@ public async Task SerializeBasicTagAsV2JsonWithoutReferenceWorksAsync(bool produ // Act BasicTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -86,7 +86,7 @@ public void SerializeBasicTagAsV3YamlWithoutReferenceWorks() } [Fact] - public void SerializeBasicTagAsV2YamlWithoutReferenceWorks() + public async Task SerializeBasicTagAsV2YamlWithoutReferenceWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -95,7 +95,7 @@ public void SerializeBasicTagAsV2YamlWithoutReferenceWorks() // Act BasicTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -105,7 +105,7 @@ public void SerializeBasicTagAsV2YamlWithoutReferenceWorks() } [Fact] - public void SerializeAdvancedTagAsV3YamlWithoutReferenceWorks() + public async Task SerializeAdvancedTagAsV3YamlWithoutReferenceWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -122,7 +122,7 @@ public void SerializeAdvancedTagAsV3YamlWithoutReferenceWorks() // Act AdvancedTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -132,7 +132,7 @@ public void SerializeAdvancedTagAsV3YamlWithoutReferenceWorks() } [Fact] - public void SerializeAdvancedTagAsV2YamlWithoutReferenceWorks() + public async Task SerializeAdvancedTagAsV2YamlWithoutReferenceWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -149,7 +149,7 @@ public void SerializeAdvancedTagAsV2YamlWithoutReferenceWorks() // Act AdvancedTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -169,7 +169,7 @@ public async Task SerializeAdvancedTagAsV3JsonWorksAsync(bool produceTerseOutput // Act AdvancedTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -186,14 +186,14 @@ public async Task SerializeAdvancedTagAsV2JsonWorksAsync(bool produceTerseOutput // Act AdvancedTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } [Fact] - public void SerializeAdvancedTagAsV3YamlWorks() + public async Task SerializeAdvancedTagAsV3YamlWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -208,7 +208,7 @@ public void SerializeAdvancedTagAsV3YamlWorks() // Act AdvancedTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -218,7 +218,7 @@ public void SerializeAdvancedTagAsV3YamlWorks() } [Fact] - public void SerializeAdvancedTagAsV2YamlWorks() + public async Task SerializeAdvancedTagAsV2YamlWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -233,7 +233,7 @@ public void SerializeAdvancedTagAsV2YamlWorks() // Act AdvancedTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -253,7 +253,7 @@ public async Task SerializeReferencedTagAsV3JsonWorksAsync(bool produceTerseOutp // Act ReferencedTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -270,14 +270,14 @@ public async Task SerializeReferencedTagAsV2JsonWorksAsync(bool produceTerseOutp // Act ReferencedTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } [Fact] - public void SerializeReferencedTagAsV3YamlWorks() + public async Task SerializeReferencedTagAsV3YamlWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -287,7 +287,7 @@ public void SerializeReferencedTagAsV3YamlWorks() // Act ReferencedTag.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert @@ -297,7 +297,7 @@ public void SerializeReferencedTagAsV3YamlWorks() } [Fact] - public void SerializeReferencedTagAsV2YamlWorks() + public async Task SerializeReferencedTagAsV2YamlWorks() { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -307,7 +307,7 @@ public void SerializeReferencedTagAsV2YamlWorks() // Act ReferencedTag.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); var actual = outputStringWriter.GetStringBuilder().ToString(); // Assert diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs index 3a75b2336..45c13500c 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -34,12 +35,12 @@ public class OpenApiXmlTests [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json)] [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml)] [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml)] - public void SerializeBasicXmlWorks( + public async Task SerializeBasicXmlWorks( OpenApiSpecVersion version, OpenApiFormat format) { // Act - var actual = BasicXml.Serialize(version, format); + var actual = await BasicXml.SerializeAsync(version, format); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -49,7 +50,7 @@ public void SerializeBasicXmlWorks( [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvancedXmlAsJsonWorks(OpenApiSpecVersion version) + public async Task SerializeAdvancedXmlAsJsonWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -65,7 +66,7 @@ public void SerializeAdvancedXmlAsJsonWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvancedXml.SerializeAsJson(version); + var actual = await AdvancedXml.SerializeAsJsonAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); @@ -76,7 +77,7 @@ public void SerializeAdvancedXmlAsJsonWorks(OpenApiSpecVersion version) [Theory] [InlineData(OpenApiSpecVersion.OpenApi3_0)] [InlineData(OpenApiSpecVersion.OpenApi2_0)] - public void SerializeAdvancedXmlAsYamlWorks(OpenApiSpecVersion version) + public async Task SerializeAdvancedXmlAsYamlWorks(OpenApiSpecVersion version) { // Arrange var expected = @@ -90,7 +91,7 @@ public void SerializeAdvancedXmlAsYamlWorks(OpenApiSpecVersion version) """; // Act - var actual = AdvancedXml.SerializeAsYaml(version); + var actual = await AdvancedXml.SerializeAsYamlAsync(version); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs index 8942e692c..b147e19ee 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs @@ -170,7 +170,7 @@ public async Task SerializeCallbackReferenceAsV3JsonWorks(bool produceTerseOutpu // Act _externalCallbackReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -187,7 +187,7 @@ public async Task SerializeCallbackReferenceAsV31JsonWorks(bool produceTerseOutp // Act _externalCallbackReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiExampleReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiExampleReferenceTests.cs index a3342ade6..a3c5efb7e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiExampleReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiExampleReferenceTests.cs @@ -161,7 +161,7 @@ public async Task SerializeExampleReferenceAsV3JsonWorks(bool produceTerseOutput // Act _localExampleReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -178,7 +178,7 @@ public async Task SerializeExampleReferenceAsV31JsonWorks(bool produceTerseOutpu // Act _localExampleReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs index c979e1eb0..9e1867455 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs @@ -120,7 +120,7 @@ public async Task SerializeHeaderReferenceAsV3JsonWorks(bool produceTerseOutput) // Act _localHeaderReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -137,7 +137,7 @@ public async Task SerializeHeaderReferenceAsV31JsonWorks(bool produceTerseOutput // Act _localHeaderReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -154,7 +154,7 @@ public async Task SerializeHeaderReferenceAsV2JsonWorksAsync(bool produceTerseOu // Act _localHeaderReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiLinkReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiLinkReferenceTests.cs index 3587a83d9..9f005727f 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiLinkReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiLinkReferenceTests.cs @@ -169,7 +169,7 @@ public async Task SerializeLinkReferenceAsV3JsonWorks(bool produceTerseOutput) // Act _localLinkReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -186,7 +186,7 @@ public async Task SerializeLinkReferenceAsV31JsonWorks(bool produceTerseOutput) // Act _localLinkReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiParameterReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiParameterReferenceTests.cs index 8745da455..57239f13b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiParameterReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiParameterReferenceTests.cs @@ -122,7 +122,7 @@ public async Task SerializeParameterReferenceAsV3JsonWorks(bool produceTerseOutp // Act _localParameterReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -139,7 +139,7 @@ public async Task SerializeParameterReferenceAsV31JsonWorks(bool produceTerseOut // Act _localParameterReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -156,7 +156,7 @@ public async Task SerializeParameterReferenceAsV2JsonWorksAsync(bool produceTers // Act _localParameterReference.SerializeAsV2(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs index c23d564d5..5d18b9095 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs @@ -130,7 +130,7 @@ public async Task SerializePathItemReferenceAsV31JsonWorks(bool produceTerseOutp // Act _localPathItemReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiRequestBodyReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiRequestBodyReferenceTests.cs index 7bd9ab35b..4befbb298 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiRequestBodyReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiRequestBodyReferenceTests.cs @@ -133,7 +133,7 @@ public async Task SerializeRequestBodyReferenceAsV3JsonWorks(bool produceTerseOu // Act _localRequestBodyReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -150,7 +150,7 @@ public async Task SerializeRequestBodyReferenceAsV31JsonWorks(bool produceTerseO // Act _localRequestBodyReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiResponseReferenceTest.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiResponseReferenceTest.cs index 361006b64..441677a6f 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiResponseReferenceTest.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiResponseReferenceTest.cs @@ -115,7 +115,7 @@ public async Task SerializeResponseReferenceAsV3JsonWorks(bool produceTerseOutpu // Act _localResponseReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -132,7 +132,7 @@ public async Task SerializeResponseReferenceAsV31JsonWorks(bool produceTerseOutp // Act _localResponseReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiSecuritySchemeReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiSecuritySchemeReferenceTests.cs index af9ab3c23..d13d63c9a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiSecuritySchemeReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiSecuritySchemeReferenceTests.cs @@ -67,7 +67,7 @@ public async Task SerializeSecuritySchemeReferenceAsV3JsonWorks(bool produceTers // Act _openApiSecuritySchemeReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -84,7 +84,7 @@ public async Task SerializeSecuritySchemeReferenceAsV31JsonWorks(bool produceTer // Act _openApiSecuritySchemeReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs index 8ec0e1373..d0e5758a5 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs @@ -89,7 +89,7 @@ public async Task SerializeTagReferenceAsV3JsonWorks(bool produceTerseOutput) // Act _openApiTagReference.SerializeAsV3(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); @@ -106,7 +106,7 @@ public async Task SerializeTagReferenceAsV31JsonWorks(bool produceTerseOutput) // Act _openApiTagReference.SerializeAsV31(writer); - writer.Flush(); + await writer.FlushAsync(); // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 88599f6ef..19d51a834 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1,7 +1,7 @@ [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/Microsoft/OpenAPI.NET")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Readers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName=".NET 8.0")] public static class IDiagnosticExtensions { public static void AddRange(this System.Collections.Generic.ICollection collection, System.Collections.Generic.IEnumerable enumerable) { } @@ -148,6 +148,7 @@ namespace Microsoft.OpenApi.Extensions { public static class EnumExtensions { + [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2075", Justification="Fields are never trimmed for enum types.")] public static T GetAttributeOfType(this System.Enum enumValue) where T : System.Attribute { } public static string GetDisplayName(this System.Enum enumValue) { } @@ -167,21 +168,21 @@ namespace Microsoft.OpenApi.Extensions } public static class OpenApiSerializableExtensions { - public static string Serialize(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format) + public static System.Threading.Tasks.Task SerializeAsJsonAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static void Serialize(this T element, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) + public static System.Threading.Tasks.Task SerializeAsJsonAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static void Serialize(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format) + public static System.Threading.Tasks.Task SerializeAsYamlAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static void Serialize(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings) + public static System.Threading.Tasks.Task SerializeAsYamlAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static string SerializeAsJson(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion) + public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static void SerializeAsJson(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion) + public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static string SerializeAsYaml(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion) + public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static void SerializeAsYaml(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion) + public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } } public static class OpenApiServerExtensions @@ -198,7 +199,7 @@ namespace Microsoft.OpenApi.Extensions } public static class StringExtensions { - public static T GetEnumFromDisplayName(this string displayName) { } + public static T GetEnumFromDisplayName<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicFields)] T>(this string displayName) { } } } namespace Microsoft.OpenApi.Interfaces @@ -560,7 +561,6 @@ namespace Microsoft.OpenApi.Models public Microsoft.OpenApi.Models.OpenApiComponents? Components { get; set; } public System.Collections.Generic.IDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } - public string HashCode { get; } public Microsoft.OpenApi.Models.OpenApiInfo Info { get; set; } public string? JsonSchemaDialect { get; set; } public Microsoft.OpenApi.Models.OpenApiPaths Paths { get; set; } @@ -570,11 +570,11 @@ namespace Microsoft.OpenApi.Models public System.Collections.Generic.IDictionary? Webhooks { get; set; } public Microsoft.OpenApi.Services.OpenApiWorkspace? Workspace { get; set; } public bool AddComponent(string id, T componentToRegister) { } + public System.Threading.Tasks.Task GetHashCodeAsync(System.Threading.CancellationToken cancellationToken = default) { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SetReferenceHostDocument() { } - public static string GenerateHashValue(Microsoft.OpenApi.Models.OpenApiDocument doc) { } public static Microsoft.OpenApi.Reader.ReadResult Load(System.IO.MemoryStream stream, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) { } public static System.Threading.Tasks.Task LoadAsync(string url, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null) { } public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream stream, string? format = null, Microsoft.OpenApi.Reader.OpenApiReaderSettings? settings = null, System.Threading.CancellationToken cancellationToken = default) { } @@ -1758,7 +1758,7 @@ namespace Microsoft.OpenApi.Writers } public interface IOpenApiWriter { - void Flush(); + System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken = default); void WriteEndArray(); void WriteEndObject(); void WriteNull(); @@ -1803,15 +1803,15 @@ namespace Microsoft.OpenApi.Writers { protected const string IndentationString = " "; protected readonly System.Collections.Generic.Stack Scopes; - public OpenApiWriterBase(System.IO.TextWriter textWriter) { } - public OpenApiWriterBase(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings) { } + protected OpenApiWriterBase(System.IO.TextWriter textWriter) { } + protected OpenApiWriterBase(System.IO.TextWriter textWriter, Microsoft.OpenApi.Writers.OpenApiWriterSettings settings) { } protected abstract int BaseIndentation { get; } public Microsoft.OpenApi.Writers.OpenApiWriterSettings Settings { get; set; } protected System.IO.TextWriter Writer { get; } protected Microsoft.OpenApi.Writers.Scope CurrentScope() { } public virtual void DecreaseIndentation() { } protected Microsoft.OpenApi.Writers.Scope EndScope(Microsoft.OpenApi.Writers.ScopeType type) { } - public void Flush() { } + public System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken = default) { } public virtual void IncreaseIndentation() { } protected bool IsArrayScope() { } protected bool IsObjectScope() { } diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index 30247333f..b9c41bf5f 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs @@ -12,6 +12,7 @@ using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -48,7 +49,7 @@ from shouldBeTerse in shouldProduceTerseOutputValues [Theory] [MemberData(nameof(WriteStringListAsJsonShouldMatchExpectedTestCases))] - public void WriteStringListAsJsonShouldMatchExpected(string[] stringValues, bool produceTerseOutput) + public async Task WriteStringListAsJsonShouldMatchExpected(string[] stringValues, bool produceTerseOutput) { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); @@ -62,7 +63,7 @@ public void WriteStringListAsJsonShouldMatchExpected(string[] stringValues, bool } writer.WriteEndArray(); - writer.Flush(); + await writer.FlushAsync(); var parsedObject = JsonSerializer.Deserialize>(outputString.GetStringBuilder().ToString()); var expectedObject = diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs index 2d966e8a5..69b176645 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiWriterAnyExtensionsTests.cs @@ -264,7 +264,7 @@ private static async Task WriteAsJsonAsync(JsonNode any, bool produceTer new() { Terse = produceTerseOutput }); writer.WriteAny(any); - writer.Flush(); + await writer.FlushAsync(); stream.Position = 0; // Act diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs index f088a3d75..7d07e51ef 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Writers; @@ -57,7 +58,7 @@ public static IEnumerable WriteStringListAsYamlShouldMatchExpectedTest [Theory] [MemberData(nameof(WriteStringListAsYamlShouldMatchExpectedTestCases))] - public void WriteStringListAsYamlShouldMatchExpected(string[] stringValues, string expectedYaml) + public async Task WriteStringListAsYamlShouldMatchExpected(string[] stringValues, string expectedYaml) { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); @@ -71,7 +72,7 @@ public void WriteStringListAsYamlShouldMatchExpected(string[] stringValues, stri } writer.WriteEndArray(); - writer.Flush(); + await writer.FlushAsync(); var actualYaml = outputString.GetStringBuilder() .ToString()