Skip to content

Commit

Permalink
- adds missing unit tests for serialization of extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Mar 28, 2024
1 parent 74d62ea commit d564e4a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -53,4 +55,22 @@ public async Task ParsesInDocument()
Assert.IsType<OpenApiAiReasoningInstructionsExtension>(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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -53,4 +55,22 @@ public async Task ParsesInDocument()
Assert.IsType<OpenApiAiRespondingInstructionsExtension>(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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,4 +50,19 @@ public async Task ParsesInDocument()
Assert.IsType<OpenApiDescriptionForModelExtension>(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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d564e4a

Please sign in to comment.