From f7f184dc40689fd803515f8b39aaef5ad73d4a88 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Fri, 27 Sep 2024 11:35:46 +0300 Subject: [PATCH] Update test --- .../Services/OpenApiFilterServiceTests.cs | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs index f91d0db93..ebb863461 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using Microsoft.Extensions.Logging; @@ -105,6 +105,57 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() Assert.False(predicate("/foo", OperationType.Patch, null)); } + [Fact] + public void CreateFilteredDocumentUsingPredicateFromRequestUrl() + { + // Arrange + var openApiDocument = new OpenApiDocument + { + Info = new() { Title = "Test", Version = "1.0" }, + Servers = new List { new() { Url = "https://localhost/" } }, + Paths = new() + { + ["/test/{id}"] = new() + { + Operations = new Dictionary + { + { OperationType.Get, new() }, + { OperationType.Patch, new() } + }, + Parameters = new List + { + new() + { + Name = "id", + In = ParameterLocation.Path, + Required = true, + Schema = new() + { + Type = "string" + } + } + } + } + + + } + }; + + var requestUrls = new Dictionary> + { + {"/test/{id}", new List {"GET","PATCH"}} + }; + + // Act + var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: openApiDocument); + var subsetDoc = OpenApiFilterService.CreateFilteredDocument(openApiDocument, predicate); + + // Assert that there's only 1 parameter in the subset document + Assert.NotNull(subsetDoc); + Assert.NotEmpty(subsetDoc.Paths); + Assert.Single(subsetDoc.Paths.First().Value.Parameters); + } + [Fact] public void ShouldParseNestedPostmanCollection() {