|
| 1 | +using System.Text.Json; |
| 2 | +using TestBuildingBlocks; |
| 3 | +using Xunit; |
| 4 | +using Xunit.Abstractions; |
| 5 | + |
| 6 | +namespace OpenApiTests.Meta; |
| 7 | + |
| 8 | +public sealed class MetaTests : IClassFixture<OpenApiTestContext<OpenApiStartup<MetaDbContext>, MetaDbContext>> |
| 9 | +{ |
| 10 | + private readonly OpenApiTestContext<OpenApiStartup<MetaDbContext>, MetaDbContext> _testContext; |
| 11 | + |
| 12 | + public MetaTests(OpenApiTestContext<OpenApiStartup<MetaDbContext>, MetaDbContext> testContext, ITestOutputHelper testOutputHelper) |
| 13 | + { |
| 14 | + _testContext = testContext; |
| 15 | + |
| 16 | + testContext.UseController<JigsawPuzzlesController>(); |
| 17 | + testContext.UseController<JigsawPuzzlePicturesController>(); |
| 18 | + testContext.UseController<JigsawPuzzlePiecesController>(); |
| 19 | + testContext.UseController<OperationsController>(); |
| 20 | + |
| 21 | + testContext.SetTestOutputHelper(testOutputHelper); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact] |
| 25 | + public async Task Includes_meta_definition() |
| 26 | + { |
| 27 | + // Act |
| 28 | + JsonElement document = await _testContext.GetSwaggerDocumentAsync(); |
| 29 | + |
| 30 | + // Assert |
| 31 | + document.Should().ContainPath("components.schemas.meta").With(metaElement => |
| 32 | + { |
| 33 | + metaElement.Should().BeJson(""" |
| 34 | + { |
| 35 | + "type": "object", |
| 36 | + "additionalProperties": { |
| 37 | + "nullable": true |
| 38 | + } |
| 39 | + } |
| 40 | + """); |
| 41 | + }); |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [InlineData("atomicOperation")] |
| 46 | + [InlineData("atomicResult")] |
| 47 | + [InlineData("createJigsawPuzzlePictureRequestDocument")] |
| 48 | + [InlineData("createJigsawPuzzlePieceRequestDocument")] |
| 49 | + [InlineData("createJigsawPuzzleRequestDocument")] |
| 50 | + [InlineData("errorObject")] |
| 51 | + [InlineData("errorResponseDocument")] |
| 52 | + [InlineData("identifierInRequest")] |
| 53 | + [InlineData("jigsawPuzzleCollectionResponseDocument")] |
| 54 | + [InlineData("jigsawPuzzleIdentifierInResponse")] |
| 55 | + [InlineData("jigsawPuzzleIdentifierResponseDocument")] |
| 56 | + [InlineData("jigsawPuzzlePictureCollectionResponseDocument")] |
| 57 | + [InlineData("jigsawPuzzlePictureIdentifierInResponse")] |
| 58 | + [InlineData("jigsawPuzzlePictureIdentifierResponseDocument")] |
| 59 | + [InlineData("jigsawPuzzlePieceCollectionResponseDocument")] |
| 60 | + [InlineData("jigsawPuzzlePieceIdentifierCollectionResponseDocument")] |
| 61 | + [InlineData("jigsawPuzzlePieceIdentifierInResponse")] |
| 62 | + [InlineData("nullableJigsawPuzzlePictureIdentifierResponseDocument")] |
| 63 | + [InlineData("nullableSecondaryJigsawPuzzlePictureResponseDocument")] |
| 64 | + [InlineData("nullableToOneJigsawPuzzlePictureInRequest")] |
| 65 | + [InlineData("nullableToOneJigsawPuzzlePictureInResponse")] |
| 66 | + [InlineData("operationsRequestDocument")] |
| 67 | + [InlineData("operationsResponseDocument")] |
| 68 | + [InlineData("primaryJigsawPuzzlePictureResponseDocument")] |
| 69 | + [InlineData("primaryJigsawPuzzlePieceResponseDocument")] |
| 70 | + [InlineData("primaryJigsawPuzzleResponseDocument")] |
| 71 | + [InlineData("resourceInCreateRequest")] |
| 72 | + [InlineData("resourceInResponse")] |
| 73 | + [InlineData("resourceInUpdateRequest")] |
| 74 | + [InlineData("secondaryJigsawPuzzlePictureResponseDocument")] |
| 75 | + [InlineData("secondaryJigsawPuzzleResponseDocument")] |
| 76 | + [InlineData("toManyJigsawPuzzlePieceInRequest")] |
| 77 | + [InlineData("toManyJigsawPuzzlePieceInResponse")] |
| 78 | + [InlineData("toOneJigsawPuzzleInRequest")] |
| 79 | + [InlineData("toOneJigsawPuzzleInResponse")] |
| 80 | + [InlineData("toOneJigsawPuzzlePictureInRequest")] |
| 81 | + [InlineData("toOneJigsawPuzzlePictureInResponse")] |
| 82 | + [InlineData("updateJigsawPuzzlePictureRequestDocument")] |
| 83 | + [InlineData("updateJigsawPuzzlePieceRequestDocument")] |
| 84 | + [InlineData("updateJigsawPuzzleRequestDocument")] |
| 85 | + public async Task Includes_meta_property(string schemaId) |
| 86 | + { |
| 87 | + // Act |
| 88 | + JsonElement document = await _testContext.GetSwaggerDocumentAsync(); |
| 89 | + |
| 90 | + // Assert |
| 91 | + document.Should().ContainPath($"components.schemas.{schemaId}.properties").With(propertiesElement => |
| 92 | + { |
| 93 | + JsonElement metaElement = propertiesElement.Should().ContainPath("meta.allOf[0]"); |
| 94 | + metaElement.Should().HaveProperty("$ref", "#/components/schemas/meta"); |
| 95 | + }); |
| 96 | + } |
| 97 | +} |
0 commit comments