Skip to content

Commit e6b2cf3

Browse files
.Net: Enable api manifest integration test (microsoft#12408)
### Motivation and Context This PR enables and moves the `ApiManifestKernelExtensionsTests` test from the unit tests project to the integration tests project.
1 parent 5c04bbe commit e6b2cf3

7 files changed

Lines changed: 141 additions & 146 deletions

File tree

dotnet/src/Functions/Functions.UnitTests/Functions.UnitTests.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
<EmbeddedResource Include="OpenApi\TestPlugins\nonCompliant_documentV3_0.json" />
3535
<EmbeddedResource Include="OpenApi\TestPlugins\documentV3_1.yaml" />
3636
<EmbeddedResource Include="OpenApi\TestPlugins\documentV3_0.json" />
37-
<EmbeddedResource Include="OpenApi\TestPlugins\example-apimanifest-repair-service.json">
38-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39-
</EmbeddedResource>
4037
<EmbeddedResource Include="OpenApi\TestPlugins\repair-service.json" />
4138
<EmbeddedResource Include="OpenApi\TestPlugins\openapi_feature_testsV3_0.json" />
4239
<EmbeddedResource Include="OpenApi\TestResponses\ObjectResponseSchema.json" />
@@ -75,12 +72,6 @@
7572
<EmbeddedResource Include="OpenApi\TestPlugins\multipart-form-data.json" />
7673
</ItemGroup>
7774
<ItemGroup>
78-
<None Update="OpenApi\TestPlugins\example-apimanifest-local.json">
79-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
80-
</None>
81-
<None Update="OpenApi\TestPlugins\example-apimanifest.json">
82-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
83-
</None>
8475
<None Update="OpenApi\TestPlugins\messages-apiplugin.json">
8576
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
8677
</None>

dotnet/src/Functions/Functions.UnitTests/OpenApi/Extensions/ApiManifestKernelExtensionsTests.cs

Lines changed: 0 additions & 136 deletions
This file was deleted.

dotnet/src/IntegrationTests/IntegrationTests.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<ProjectReference Include="..\Connectors\Connectors.Ollama\Connectors.Ollama.csproj" />
7171
<ProjectReference Include="..\Connectors\Connectors.Onnx\Connectors.Onnx.csproj" />
7272
<ProjectReference Include="..\Connectors\Connectors.MistralAI\Connectors.MistralAI.csproj" />
73+
<ProjectReference Include="..\Functions\Functions.OpenApi.Extensions\Functions.OpenApi.Extensions.csproj" />
7374
<ProjectReference Include="..\VectorData\AzureAISearch\AzureAISearch.csproj" />
7475
<ProjectReference Include="..\VectorData\CosmosMongoDB\CosmosMongoDB.csproj" />
7576
<ProjectReference Include="..\VectorData\CosmosNoSql\CosmosNoSql.csproj" />
@@ -151,6 +152,12 @@
151152
<Content Include="CrossLanguage\Data\SimplePromptTest.yaml">
152153
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
153154
</Content>
155+
<Content Include="Plugins\OpenApiManifest\example-apimanifest-local.json">
156+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
157+
</Content>
158+
<Content Include="Plugins\OpenApiManifest\example-apimanifest.json">
159+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
160+
</Content>
154161
<Content Include="Plugins\OpenApi\instacart-service.yaml">
155162
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
156163
</Content>
@@ -160,6 +167,9 @@
160167
</ItemGroup>
161168

162169
<ItemGroup>
170+
<Content Include="Plugins\OpenApiManifest\example-apimanifest-repair-service.json">
171+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
172+
</Content>
163173
<EmbeddedResource Include="prompts/GenerateStory.yaml">
164174
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
165175
</EmbeddedResource>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using Microsoft.SemanticKernel;
6+
using Xunit;
7+
8+
namespace SemanticKernel.IntegrationTests.Plugins.OpenApiManifest;
9+
10+
public sealed class ApiManifestKernelExtensionsTests
11+
{
12+
private readonly string _testPluginsDir;
13+
private readonly Kernel _kernel;
14+
15+
public ApiManifestKernelExtensionsTests()
16+
{
17+
this._testPluginsDir = Path.Combine(Directory.GetCurrentDirectory(), "Plugins", "OpenApiManifest");
18+
this._kernel = new Kernel();
19+
}
20+
21+
[Fact]
22+
public async Task ItCanCreatePluginFromApiManifestAsync()
23+
{
24+
// Act
25+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest.json");
26+
27+
// Arrange
28+
var plugin = await this._kernel.CreatePluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath);
29+
30+
// Assert
31+
Assert.NotNull(plugin);
32+
Assert.Equal(3, plugin.FunctionCount);
33+
}
34+
35+
[Fact]
36+
public async Task ItCanCreatePluginFromApiManifestWithDescriptionParameterAsync()
37+
{
38+
// Act
39+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest.json");
40+
var description = "My plugin description";
41+
42+
// Arrange
43+
var plugin = await this._kernel.CreatePluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath, description);
44+
45+
// Assert
46+
Assert.NotNull(plugin);
47+
Assert.Equal(description, plugin.Description);
48+
}
49+
50+
[Fact]
51+
public async Task ItCanCreatePluginFromApiManifestWithEmptyDescriptionParameterAsync()
52+
{
53+
// Act
54+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest.json");
55+
56+
// Arrange
57+
var plugin = await this._kernel.CreatePluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath, description: null);
58+
59+
// Assert
60+
Assert.NotNull(plugin);
61+
Assert.Empty(plugin.Description);
62+
}
63+
64+
[Fact]
65+
public async Task ItCanImportPluginFromApiManifestAsync()
66+
{
67+
// Act
68+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest.json");
69+
70+
// Arrange
71+
var plugin = await this._kernel.ImportPluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath);
72+
73+
// Assert
74+
Assert.NotNull(plugin);
75+
Assert.Equal(3, plugin.FunctionCount);
76+
Assert.Single(this._kernel.Plugins);
77+
}
78+
79+
[Fact]
80+
public async Task ItCanImportPluginFromApiManifestWithDescriptionParameterAsync()
81+
{
82+
// Act
83+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest.json");
84+
var description = "My plugin description";
85+
86+
// Arrange
87+
var plugin = await this._kernel.ImportPluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath, description);
88+
89+
// Assert
90+
Assert.NotNull(plugin);
91+
Assert.Equal(description, plugin.Description);
92+
}
93+
94+
[Fact]
95+
public async Task ItCanImportPluginFromApiManifestWithLocalAndRemoteApiDescriptionUrlAsync()
96+
{
97+
// Act
98+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest-local.json");
99+
100+
// Arrange
101+
var plugin = await this._kernel.ImportPluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath);
102+
103+
// Assert
104+
Assert.NotNull(plugin);
105+
Assert.Equal(2, plugin.FunctionCount);
106+
}
107+
108+
[Fact]
109+
// Verify that functions are correctly imported
110+
public async Task VerifyPluginFunctionsFromApiManifestAsync()
111+
{
112+
// Act
113+
var manifestFilePath = Path.Combine(this._testPluginsDir, "example-apimanifest-local.json");
114+
115+
// Arrange
116+
var plugin = await this._kernel.ImportPluginFromApiManifestAsync("ApiManifestPlugin", manifestFilePath);
117+
118+
// Assert
119+
Assert.NotNull(plugin);
120+
Assert.Equal(2, plugin.FunctionCount);
121+
122+
// Assert functions imported from local openapi.json
123+
Assert.True(plugin.Contains("listRepairs"));
124+
Assert.Contains(plugin["listRepairs"].Metadata.AdditionalProperties, static p => p.Key == "method" && p.Value?.ToString() == "GET");
125+
126+
// Assert functions imported from remote openapi.json
127+
Assert.True(plugin.Contains("directoryObject_GetDirectoryObject"));
128+
Assert.Contains(plugin["directoryObject_GetDirectoryObject"].Metadata.AdditionalProperties, static p => p.Key == "method" && p.Value?.ToString() == "GET");
129+
}
130+
}

dotnet/src/Functions/Functions.UnitTests/OpenApi/TestPlugins/example-apimanifest-local.json renamed to dotnet/src/IntegrationTests/Plugins/OpenApiManifest/example-apimanifest-local.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"apiDependencies": {
88
"repairservice": {
9-
"apiDescriptionUrl": "../TestPlugins/example-apimanifest-repair-service.json",
9+
"apiDescriptionUrl": "../OpenApiManifest/example-apimanifest-repair-service.json",
1010
"requests": [
1111
{
1212
"method": "GET",

dotnet/src/Functions/Functions.UnitTests/OpenApi/TestPlugins/example-apimanifest-repair-service.json renamed to dotnet/src/IntegrationTests/Plugins/OpenApiManifest/example-apimanifest-repair-service.json

File renamed without changes.

dotnet/src/Functions/Functions.UnitTests/OpenApi/TestPlugins/example-apimanifest.json renamed to dotnet/src/IntegrationTests/Plugins/OpenApiManifest/example-apimanifest.json

File renamed without changes.

0 commit comments

Comments
 (0)