|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -using System; |
5 | 4 | using System.Collections.Generic; |
6 | 5 | using System.Globalization; |
7 | 6 | using System.IO; |
8 | | -using System.Linq; |
9 | 7 | using System.Threading.Tasks; |
10 | 8 | using FluentAssertions; |
11 | 9 | using Microsoft.OpenApi.Any; |
@@ -485,6 +483,45 @@ public void OpenApiSchemaCopyConstructorSucceeds() |
485 | 483 | Assert.True(actualSchema.Nullable); |
486 | 484 | } |
487 | 485 |
|
| 486 | + public static TheoryData<IOpenApiAny> SchemaExamples() |
| 487 | + { |
| 488 | + return new() |
| 489 | + { |
| 490 | + new OpenApiArray() { new OpenApiString("example") }, |
| 491 | + new OpenApiBinary([0, 1, 2]), |
| 492 | + new OpenApiBoolean(true), |
| 493 | + new OpenApiByte(42), |
| 494 | + new OpenApiDate(new(2024, 07, 19, 12, 34, 56)), |
| 495 | + new OpenApiDateTime(new(2024, 07, 19, 12, 34, 56, new(01, 00, 00))), |
| 496 | + new OpenApiDouble(42.37), |
| 497 | + new OpenApiFloat(42.37f), |
| 498 | + new OpenApiInteger(42), |
| 499 | + new OpenApiLong(42), |
| 500 | + new OpenApiNull(), |
| 501 | + new OpenApiObject() { ["prop"] = new OpenApiString("example") }, |
| 502 | + new OpenApiPassword("secret"), |
| 503 | + new OpenApiString("example"), |
| 504 | + }; |
| 505 | + } |
| 506 | + |
| 507 | + [Theory] |
| 508 | + [MemberData(nameof(SchemaExamples))] |
| 509 | + public void CloningSchemaExamplesWorks(IOpenApiAny example) |
| 510 | + { |
| 511 | + // Arrange |
| 512 | + var schema = new OpenApiSchema |
| 513 | + { |
| 514 | + Example = example |
| 515 | + }; |
| 516 | + |
| 517 | + // Act && Assert |
| 518 | + var schemaCopy = new OpenApiSchema(schema); |
| 519 | + Assert.NotNull(schemaCopy.Example); |
| 520 | + |
| 521 | + // Act && Assert |
| 522 | + Assert.Equivalent(schema.Example, schemaCopy.Example); |
| 523 | + } |
| 524 | + |
488 | 525 | [Fact] |
489 | 526 | public void CloningSchemaExtensionsWorks() |
490 | 527 | { |
|
0 commit comments