Skip to content

Commit f5032a8

Browse files
authored
Add integration testing for OpenAPI document rendering (#219)
1 parent e05f858 commit f5032a8

27 files changed

+990
-41
lines changed

.github/workflows/build.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ jobs:
2222
- name: Checkout the repository
2323
uses: actions/checkout@v2
2424

25+
- name: Setup node.js
26+
uses: actions/setup-node@v2
27+
with:
28+
node-version: '14'
29+
30+
- name: Setup Azure Functions Core Tools
31+
shell: pwsh
32+
run: |
33+
npm install -g azure-functions-core-tools@3 --unsafe-perm true
34+
2535
- name: Setup .NET SDK 2.1 LTS
2636
uses: actions/setup-dotnet@v1
2737
with:
@@ -58,8 +68,41 @@ jobs:
5868
dir
5969
dotnet build . -c Debug -v minimal
6070
61-
- name: Test solution
71+
- name: Run unit tests
72+
shell: pwsh
73+
run: |
74+
dir
75+
dotnet test . -c Debug --filter:"TestCategory!=Integration"
76+
77+
# - name: Run integration tests (Windows)
78+
# if: matrix.os == 'windows-latest'
79+
# shell: pwsh
80+
# run: |
81+
# dir
82+
83+
# $rootDir = $pwd.Path
84+
# $func = $(Get-Command func).Source.Replace(".ps1", ".cmd")
85+
86+
# cd ./test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
87+
# Start-Process -NoNewWindow "$func" @("start","--verbose","false")
88+
# Start-Sleep -s 60
89+
90+
# cd $rootDir/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
91+
# dotnet test . -c Debug
92+
# cd $rootDir
93+
94+
- name: Run integration tests (Non-Windows)
95+
if: matrix.os != 'windows-latest'
6296
shell: pwsh
6397
run: |
6498
dir
99+
100+
$rootDir = $pwd.Path
101+
102+
cd ./test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
103+
Start-Process -NoNewWindow func @("start","--verbose","false")
104+
Start-Sleep -s 60
105+
106+
cd $rootDir/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
65107
dotnet test . -c Debug
108+
cd $rootDir

.github/workflows/pr.yaml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ jobs:
1818
- name: Checkout the repository
1919
uses: actions/checkout@v2
2020

21+
- name: Setup node.js
22+
uses: actions/setup-node@v2
23+
with:
24+
node-version: '14'
25+
26+
- name: Setup Azure Functions Core Tools
27+
shell: pwsh
28+
run: |
29+
npm install -g azure-functions-core-tools@3 --unsafe-perm true
30+
2131
- name: Setup .NET SDK 2.1 LTS
2232
uses: actions/setup-dotnet@v1
2333
with:
@@ -54,8 +64,41 @@ jobs:
5464
dir
5565
dotnet build . -c Debug -v minimal
5666
57-
- name: Test solution
67+
- name: Run unit tests
68+
shell: pwsh
69+
run: |
70+
dir
71+
dotnet test . -c Debug --filter:"TestCategory!=Integration"
72+
73+
# - name: Run integration tests (Windows)
74+
# if: matrix.os == 'windows-latest'
75+
# shell: pwsh
76+
# run: |
77+
# dir
78+
79+
# $rootDir = $pwd.Path
80+
# $func = $(Get-Command func).Source.Replace(".ps1", ".cmd")
81+
82+
# cd ./test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
83+
# Start-Process -NoNewWindow "$func" @("start","--verbose","false")
84+
# Start-Sleep -s 60
85+
86+
# cd $rootDir/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
87+
# dotnet test . -c Debug
88+
# cd $rootDir
89+
90+
- name: Run integration tests (Non-Windows)
91+
if: matrix.os != 'windows-latest'
5892
shell: pwsh
5993
run: |
6094
dir
95+
96+
$rootDir = $pwd.Path
97+
98+
cd ./test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
99+
Start-Process -NoNewWindow func @("start","--verbose","false")
100+
Start-Sleep -s 60
101+
102+
cd $rootDir/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
61103
dotnet test . -c Debug
104+
cd $rootDir

Microsoft.Azure.WebJobs.Extensions.OpenApi.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Ext
6262
EndProject
6363
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests", "test\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests\Microsoft.Azure.WebJobs.Extensions.OpenApi.CLI.Tests.csproj", "{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}"
6464
EndProject
65+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-integration", "test-integration", "{CBD9883B-134F-42CC-A201-EE06EBC48C3E}"
66+
EndProject
67+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp", "test-integration\Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp\Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.csproj", "{7F6EC289-B516-455E-8E5F-324D5C9212B7}"
68+
EndProject
69+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests", "test-integration\Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests\Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests.csproj", "{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB}"
70+
EndProject
6571
Global
6672
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6773
Debug|Any CPU = Debug|Any CPU
@@ -156,6 +162,14 @@ Global
156162
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Debug|Any CPU.Build.0 = Debug|Any CPU
157163
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Release|Any CPU.ActiveCfg = Release|Any CPU
158164
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082}.Release|Any CPU.Build.0 = Release|Any CPU
165+
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
166+
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
167+
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
168+
{7F6EC289-B516-455E-8E5F-324D5C9212B7}.Release|Any CPU.Build.0 = Release|Any CPU
169+
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
170+
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB}.Debug|Any CPU.Build.0 = Debug|Any CPU
171+
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB}.Release|Any CPU.ActiveCfg = Release|Any CPU
172+
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB}.Release|Any CPU.Build.0 = Release|Any CPU
159173
EndGlobalSection
160174
GlobalSection(SolutionProperties) = preSolution
161175
HideSolutionNode = FALSE
@@ -184,6 +198,8 @@ Global
184198
{968CD847-80D0-4740-92D5-F5553461EC04} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
185199
{D787694D-B87B-4E11-9455-B5BF9306D8FC} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
186200
{65AED6F0-D27E-4D6E-BA42-AD6EE1338082} = {8B62E3FB-9062-4716-803A-1FA51FCE68BC}
201+
{7F6EC289-B516-455E-8E5F-324D5C9212B7} = {CBD9883B-134F-42CC-A201-EE06EBC48C3E}
202+
{8324C8D1-A9FD-4F98-8ED9-82C3BE572DBB} = {CBD9883B-134F-42CC-A201-EE06EBC48C3E}
187203
EndGlobalSection
188204
GlobalSection(ExtensibilityGlobals) = postSolution
189205
SolutionGuid = {70FEC644-BB3C-4441-AF91-DC694803C8F2}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
2+
{
3+
public class Constants
4+
{
5+
public const string TestCategory = "Integration";
6+
public const string OpenApiDocEndpoint = "http://localhost:7071/api/openapi/v3.json";
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Net.Http;
2+
using System.Threading.Tasks;
3+
4+
using FluentAssertions;
5+
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
10+
11+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
12+
{
13+
[TestClass]
14+
[TestCategory(Constants.TestCategory)]
15+
public class Get_ApplicationJson_Object_Tests
16+
{
17+
private static HttpClient http = new HttpClient();
18+
19+
private JObject _doc;
20+
21+
[TestInitialize]
22+
public async Task Init()
23+
{
24+
var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false);
25+
this._doc = JsonConvert.DeserializeObject<JObject>(json);
26+
}
27+
28+
[DataTestMethod]
29+
[DataRow("/get-applicationjson-object", "get", "200")]
30+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode)
31+
{
32+
var responses = this._doc["paths"][path][operationType]["responses"];
33+
34+
responses[responseCode].Should().NotBeNull();
35+
}
36+
37+
[DataTestMethod]
38+
[DataRow("/get-applicationjson-object", "get", "200", "application/json")]
39+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType)
40+
{
41+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
42+
43+
content[contentType].Should().NotBeNull();
44+
}
45+
46+
[DataTestMethod]
47+
[DataRow("/get-applicationjson-object", "get", "200", "application/json", "singleStringObject")]
48+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema(string path, string operationType, string responseCode, string contentType, string reference)
49+
{
50+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
51+
52+
var @ref = content[contentType]["schema"]["$ref"];
53+
54+
@ref.Value<string>().Should().Be($"#/components/schemas/{reference}");
55+
}
56+
57+
[DataTestMethod]
58+
[DataRow("singleStringObject", "object")]
59+
public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchema(string @ref, string refType)
60+
{
61+
var schemas = this._doc["components"]["schemas"];
62+
63+
var schema = schemas[@ref];
64+
65+
schema.Should().NotBeNull();
66+
schema.Value<string>("type").Should().Be(refType);
67+
}
68+
69+
[DataTestMethod]
70+
[DataRow("singleStringObject", "object", "value", "string")]
71+
public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaProperty(string @ref, string refType, string propertyName, string propertyType)
72+
{
73+
var properties = this._doc["components"]["schemas"][@ref]["properties"];
74+
75+
var value = properties[propertyName];
76+
77+
value.Should().NotBeNull();
78+
value.Value<string>("type").Should().Be(propertyType);
79+
}
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System.Linq;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
5+
using FluentAssertions;
6+
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
9+
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Linq;
11+
12+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
13+
{
14+
[TestClass]
15+
[TestCategory(Constants.TestCategory)]
16+
public class Get_Query_TextPlain_String_Tests
17+
{
18+
private static HttpClient http = new HttpClient();
19+
20+
private JObject _doc;
21+
22+
[TestInitialize]
23+
public async Task Init()
24+
{
25+
var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false);
26+
this._doc = JsonConvert.DeserializeObject<JObject>(json);
27+
}
28+
29+
[DataTestMethod]
30+
[DataRow("/get-query-textplain-string")]
31+
public void Given_OpenApiDocument_Then_It_Should_Return_Path(string path)
32+
{
33+
var paths = this._doc["paths"];
34+
35+
paths.Value<JToken>(path).Should().NotBeNull();
36+
}
37+
38+
[DataTestMethod]
39+
[DataRow("/get-query-textplain-string", "get")]
40+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationType(string path, string operationType)
41+
{
42+
var pathItem = this._doc["paths"][path];
43+
44+
pathItem.Value<JToken>(operationType).Should().NotBeNull();
45+
}
46+
47+
[DataTestMethod]
48+
[DataRow("/get-query-textplain-string", "get", "name", "query", true)]
49+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationParameter(string path, string operationType, string name, string @in, bool required)
50+
{
51+
var parameters = this._doc["paths"][path][operationType]["parameters"].Children();
52+
53+
var parameter = parameters.SingleOrDefault(p => p["name"].Value<string>() == name);
54+
55+
parameter.Should().NotBeNull();
56+
parameter.Value<string>("in").Should().Be(@in);
57+
parameter.Value<bool>("required").Should().Be(required);
58+
}
59+
60+
[DataTestMethod]
61+
[DataRow("/get-query-textplain-string", "get", "name", "string")]
62+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationParameterSchema(string path, string operationType, string name, string dataType)
63+
{
64+
var parameters = this._doc["paths"][path][operationType]["parameters"].Children();
65+
var parameter = parameters.SingleOrDefault(p => p["name"].Value<string>() == name);
66+
67+
var schema = parameter["schema"];
68+
69+
schema.Value<string>("type").Should().Be(dataType);
70+
}
71+
72+
[DataTestMethod]
73+
[DataRow("/get-query-textplain-string", "get", "200")]
74+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode)
75+
{
76+
var responses = this._doc["paths"][path][operationType]["responses"];
77+
78+
responses[responseCode].Should().NotBeNull();
79+
}
80+
81+
[DataTestMethod]
82+
[DataRow("/get-query-textplain-string", "get", "200", "text/plain")]
83+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType)
84+
{
85+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
86+
87+
content[contentType].Should().NotBeNull();
88+
}
89+
90+
[DataTestMethod]
91+
[DataRow("/get-query-textplain-string", "get", "200", "text/plain", "string")]
92+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema(string path, string operationType, string responseCode, string contentType, string dataType)
93+
{
94+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
95+
96+
var schema = content[contentType]["schema"];
97+
98+
schema.Value<string>("type").Should().Be(dataType);
99+
}
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
8+
<AssemblyName>Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests</AssemblyName>
9+
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests</RootNamespace>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="coverlet.collector" Version="3.1.0">
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
<PrivateAssets>all</PrivateAssets>
16+
</PackageReference>
17+
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
21+
<PackageReference Include="FluentAssertions" Version="6.1.0" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
23+
<PackageReference Include="Microsoft.OpenApi" Version="1.2.3" />
24+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.6" />
25+
<PackageReference Include="MSTest.TestFramework" Version="2.2.6" />
26+
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
27+
</ItemGroup>
28+
29+
</Project>

0 commit comments

Comments
 (0)