Skip to content

Commit 15b4c75

Browse files
committed
Add plugin command test.
1 parent ede77de commit 15b4c75

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public IReadOnlyList<Option> GetPluginCommandOptions()
9898
{
9999
return new List<Option>
100100
{
101-
102101
ManifestOption,
103102
OutputFolderOption,
104103
CleanOutputOption,

test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public void ResolveFunctionParameters()
8585
var idsParameter = openApiDocument.Paths["/foo"].Operations[OperationType.Get].Parameters.Where(static p => p.Name == "ids").FirstOrDefault();
8686

8787
// Assert
88-
Assert.Null(idsParameter.Content);
89-
Assert.NotNull(idsParameter.Schema);
90-
Assert.Equal("array", idsParameter.Schema.Type);
88+
Assert.Null(idsParameter?.Content);
89+
Assert.NotNull(idsParameter?.Schema);
90+
Assert.Equal("array", idsParameter?.Schema.Type);
9191
}
9292

9393
private static OpenApiDocument GetSampleOpenApiDocument()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
<None Update="UtilityFiles\examplepowershellsettings.json">
6363
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6464
</None>
65+
<None Update="UtilityFiles\exampleapimanifest.json">
66+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
67+
</None>
6568
</ItemGroup>
6669

6770
</Project>

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using System.CommandLine;
55
using System.CommandLine.Invocation;
66
using System.CommandLine.Parsing;
7+
using System.Text.Json;
78
using Microsoft.Extensions.Configuration;
89
using Microsoft.Extensions.Logging;
10+
using Microsoft.OpenApi.ApiManifest.OpenAI;
911
using Microsoft.OpenApi.Hidi.Options;
1012
using Microsoft.OpenApi.Hidi.Utilities;
1113
using Microsoft.OpenApi.Models;
@@ -349,6 +351,25 @@ public void InvokeShowCommand()
349351
Assert.Contains("graph LR", output);
350352
}
351353

354+
[Fact]
355+
public void InvokePluginCommand()
356+
{
357+
var rootCommand = Program.CreateRootCommand();
358+
var args = new string[] { "plugin", "-m", ".\\UtilityFiles\\exampleapimanifest.json", "--of", AppDomain.CurrentDomain.BaseDirectory };
359+
var parseResult = rootCommand.Parse(args);
360+
var handler = rootCommand.Subcommands.Where(c => c.Name == "plugin").First().Handler;
361+
var context = new InvocationContext(parseResult);
362+
363+
handler!.Invoke(context);
364+
365+
using var jsDoc = JsonDocument.Parse(File.ReadAllText("ai-plugin.json"));
366+
var openAiManifest = OpenAIPluginManifest.Load(jsDoc.RootElement);
367+
368+
Assert.Equal("Mastodon - Subset", openAiManifest?.NameForHuman);
369+
Assert.Equal("openapi", openAiManifest?.Api.Type);
370+
Assert.Equal("./openapi.json", openAiManifest?.Api.Url);
371+
}
372+
352373

353374
// Relatively useless test to keep the code coverage metrics happy
354375
[Fact]

0 commit comments

Comments
 (0)