Skip to content

Commit f7f184d

Browse files
committed
Update test
1 parent 8c0cf47 commit f7f184d

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

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

Lines changed: 52 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 Microsoft.Extensions.Logging;
@@ -105,6 +105,57 @@ public void TestPredicateFiltersUsingRelativeRequestUrls()
105105
Assert.False(predicate("/foo", OperationType.Patch, null));
106106
}
107107

108+
[Fact]
109+
public void CreateFilteredDocumentUsingPredicateFromRequestUrl()
110+
{
111+
// Arrange
112+
var openApiDocument = new OpenApiDocument
113+
{
114+
Info = new() { Title = "Test", Version = "1.0" },
115+
Servers = new List<OpenApiServer> { new() { Url = "https://localhost/" } },
116+
Paths = new()
117+
{
118+
["/test/{id}"] = new()
119+
{
120+
Operations = new Dictionary<OperationType, OpenApiOperation>
121+
{
122+
{ OperationType.Get, new() },
123+
{ OperationType.Patch, new() }
124+
},
125+
Parameters = new List<OpenApiParameter>
126+
{
127+
new()
128+
{
129+
Name = "id",
130+
In = ParameterLocation.Path,
131+
Required = true,
132+
Schema = new()
133+
{
134+
Type = "string"
135+
}
136+
}
137+
}
138+
}
139+
140+
141+
}
142+
};
143+
144+
var requestUrls = new Dictionary<string, List<string>>
145+
{
146+
{"/test/{id}", new List<string> {"GET","PATCH"}}
147+
};
148+
149+
// Act
150+
var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: openApiDocument);
151+
var subsetDoc = OpenApiFilterService.CreateFilteredDocument(openApiDocument, predicate);
152+
153+
// Assert that there's only 1 parameter in the subset document
154+
Assert.NotNull(subsetDoc);
155+
Assert.NotEmpty(subsetDoc.Paths);
156+
Assert.Single(subsetDoc.Paths.First().Value.Parameters);
157+
}
158+
108159
[Fact]
109160
public void ShouldParseNestedPostmanCollection()
110161
{

0 commit comments

Comments
 (0)