From d564e4a08bdcad5bfe948f6285730a2cd2a0edf7 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 28 Mar 2024 08:48:27 -0400 Subject: [PATCH] - adds missing unit tests for serialization of extensions Signed-off-by: Vincent Biret --- ...piAiReasoningInstructionsExtensionTests.cs | 20 +++++++++++++++++++ ...iAiRespondingInstructionsExtensionTests.cs | 20 +++++++++++++++++++ ...penApiDescriptionForModelExtensionTests.cs | 17 ++++++++++++++++ .../OpenApiKiotaExtensionTests.cs | 6 +++--- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs index 169c477a1d..1a4d716b51 100644 --- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs +++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs @@ -5,7 +5,9 @@ using Kiota.Builder.Configuration; using Kiota.Builder.OpenApiExtensions; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Writers; using Moq; using Xunit; @@ -53,4 +55,22 @@ public async Task ParsesInDocument() Assert.IsType(descriptionExtension); Assert.Equal("This is a description", ((OpenApiAiReasoningInstructionsExtension)descriptionExtension).ReasoningInstructions[0]); } + [Fact] + public void Serializes() + { + var value = new OpenApiAiReasoningInstructionsExtension + { + ReasoningInstructions = [ + "This is a description", + "This is a description 2", + ] + }; + using var sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); + + + value.Write(writer, OpenApiSpecVersion.OpenApi3_0); + var result = sWriter.ToString(); + Assert.Equal("[\"This is a description\",\"This is a description 2\"]", result); + } } diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs index 0402527c03..ba82ff57e7 100644 --- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs +++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs @@ -5,7 +5,9 @@ using Kiota.Builder.Configuration; using Kiota.Builder.OpenApiExtensions; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Writers; using Moq; using Xunit; @@ -53,4 +55,22 @@ public async Task ParsesInDocument() Assert.IsType(descriptionExtension); Assert.Equal("This is a description", ((OpenApiAiRespondingInstructionsExtension)descriptionExtension).RespondingInstructions[0]); } + [Fact] + public void Serializes() + { + var value = new OpenApiAiRespondingInstructionsExtension + { + RespondingInstructions = [ + "This is a description", + "This is a description 2", + ] + }; + using var sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); + + + value.Write(writer, OpenApiSpecVersion.OpenApi3_0); + var result = sWriter.ToString(); + Assert.Equal("[\"This is a description\",\"This is a description 2\"]", result); + } } diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs index cd7341f9c6..f66cc5e28e 100644 --- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs +++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs @@ -5,7 +5,9 @@ using Kiota.Builder.Configuration; using Kiota.Builder.OpenApiExtensions; using Microsoft.Extensions.Logging; +using Microsoft.OpenApi; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Writers; using Moq; using Xunit; @@ -48,4 +50,19 @@ public async Task ParsesInDocument() Assert.IsType(descriptionExtension); Assert.Equal("This is a description", ((OpenApiDescriptionForModelExtension)descriptionExtension).Description); } + [Fact] + public void Serializes() + { + var value = new OpenApiDescriptionForModelExtension + { + Description = "This is a description", + }; + using var sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); + + + value.Write(writer, OpenApiSpecVersion.OpenApi3_0); + var result = sWriter.ToString(); + Assert.Equal("\"This is a description\"", result); + } } diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiKiotaExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiKiotaExtensionTests.cs index 56bac02da8..27096a9862 100644 --- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiKiotaExtensionTests.cs +++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiKiotaExtensionTests.cs @@ -36,13 +36,13 @@ public void Serializes() } }, }; - using TextWriter sWriter = new StringWriter(); - OpenApiJsonWriter writer = new(sWriter); + using var sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); value.Write(writer, OpenApiSpecVersion.OpenApi3_0); var result = sWriter.ToString(); - Assert.Equal("{\n \"languagesInformation\": {\n \"CSharp\": {\n \"maturityLevel\": \"Preview\",\n \"dependencyInstallCommand\": \"dotnet add package\",\n \"dependencies\": [\n {\n \"name\": \"Microsoft.Graph.Core\",\n \"version\": \"1.0.0\"\n }\n ],\n \"clientClassName\": \"GraphServiceClient\",\n \"clientNamespaceName\": \"Microsoft.Graph\",\n \"structuredMimeTypes\": [\n \"application/json\",\n \"application/xml\"\n ]\n }\n }\n}", result); + Assert.Equal("{\"languagesInformation\":{\"CSharp\":{\"maturityLevel\":\"Preview\",\"dependencyInstallCommand\":\"dotnet add package\",\"dependencies\":[{\"name\":\"Microsoft.Graph.Core\",\"version\":\"1.0.0\"}],\"clientClassName\":\"GraphServiceClient\",\"clientNamespaceName\":\"Microsoft.Graph\",\"structuredMimeTypes\":[\"application/json\",\"application/xml\"]}}}", result); } [Fact] public void Parses()