|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using Microsoft.OpenApi.Models; |
| 6 | +using Microsoft.OpenApi.Services; |
| 7 | +using OpenAPIService.Test; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.OpenApi.Tests.Services |
| 11 | +{ |
| 12 | + public class OpenApiFilterServiceTests |
| 13 | + { |
| 14 | + private const string Title = "Partial Graph API"; |
| 15 | + private const string GraphVersion = "mock"; |
| 16 | + private readonly OpenApiFilterService _openApiFilterService; |
| 17 | + private readonly OpenApiDocument _openApiDocumentMock; |
| 18 | + |
| 19 | + public OpenApiFilterServiceTests() |
| 20 | + { |
| 21 | + _openApiFilterService = new OpenApiFilterService(); |
| 22 | + _openApiDocumentMock = OpenApiDocumentMock.CreateOpenApiDocument(); |
| 23 | + } |
| 24 | + |
| 25 | + [Theory] |
| 26 | + [InlineData("users.user.ListUser")] |
| 27 | + [InlineData("users.user.GetUser")] |
| 28 | + [InlineData("administrativeUnits.restore")] |
| 29 | + [InlineData("graphService.GetGraphService")] |
| 30 | + public void ReturnFilteredOpenApiDocumentBasedOnOperationIds(string operationId) |
| 31 | + { |
| 32 | + // Act |
| 33 | + var predicate = _openApiFilterService.CreatePredicate(operationId); |
| 34 | + var subsetOpenApiDocument = _openApiFilterService.CreateFilteredDocument(_openApiDocumentMock, Title, GraphVersion, predicate); |
| 35 | + |
| 36 | + // Assert |
| 37 | + Assert.NotNull(subsetOpenApiDocument); |
| 38 | + Assert.Single(subsetOpenApiDocument.Paths); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidOperationIdIsSpecified() |
| 43 | + { |
| 44 | + // Act and Assert |
| 45 | + var message = Assert.Throws<InvalidOperationException>(() =>_openApiFilterService.CreatePredicate(null)).Message; |
| 46 | + Assert.Equal("OperationId needs to be specified.", message); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments