Skip to content

Commit ea2d73f

Browse files
committed
Adds test for retrieving path parameters
1 parent b39303e commit ea2d73f

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -135,5 +135,22 @@ public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArguments
135135
var message2 = Assert.Throws<InvalidOperationException>(() => OpenApiFilterService.CreatePredicate("users.user.ListUser", "users.user")).Message;
136136
Assert.Equal("Cannot specify both operationIds and tags at the same time.", message2);
137137
}
138+
139+
[Theory]
140+
[InlineData("reports.getTeamsUserActivityUserDetail-a3f1", null)]
141+
[InlineData(null, "reports.Functions")]
142+
public void ReturnsPathParametersOnSlicingBasedOnOperationIdsOrTags(string operationIds, string tags)
143+
{
144+
// Act
145+
var predicate = OpenApiFilterService.CreatePredicate(operationIds, tags);
146+
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(_openApiDocumentMock, predicate);
147+
148+
// Assert
149+
foreach (var pathItem in subsetOpenApiDocument.Paths)
150+
{
151+
Assert.True(pathItem.Value.Parameters.Any());
152+
Assert.Equal(1, pathItem.Value.Parameters.Count);
153+
}
154+
}
138155
}
139156
}

Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public static OpenApiDocument CreateOpenApiDocument()
116116
}
117117
}
118118
}
119+
},
120+
Parameters = new List<OpenApiParameter>
121+
{
122+
{
123+
new OpenApiParameter()
124+
{
125+
Name = "period",
126+
In = ParameterLocation.Path,
127+
Required = true,
128+
Schema = new OpenApiSchema()
129+
{
130+
Type = "string"
131+
}
132+
}
133+
}
119134
}
120135
},
121136
["/reports/microsoft.graph.getTeamsUserActivityUserDetail(date={date})"] = new OpenApiPathItem()
@@ -175,7 +190,20 @@ public static OpenApiDocument CreateOpenApiDocument()
175190
}
176191
}
177192
}
178-
}
193+
},
194+
Parameters = new List<OpenApiParameter>
195+
{
196+
new OpenApiParameter
197+
{
198+
Name = "period",
199+
In = ParameterLocation.Path,
200+
Required = true,
201+
Schema = new OpenApiSchema()
202+
{
203+
Type = "string"
204+
}
205+
}
206+
}
179207
},
180208
["/users"] = new OpenApiPathItem()
181209
{

0 commit comments

Comments
 (0)