|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.Globalization;
|
7 | 7 | using System.IO;
|
| 8 | +using System.Threading.Tasks; |
8 | 9 | using FluentAssertions;
|
9 | 10 | using Microsoft.OpenApi.Any;
|
10 | 11 | using Microsoft.OpenApi.Extensions;
|
11 | 12 | using Microsoft.OpenApi.Models;
|
12 | 13 | using Microsoft.OpenApi.Writers;
|
| 14 | +using VerifyXunit; |
13 | 15 | using Xunit;
|
14 | 16 | using Xunit.Abstractions;
|
15 | 17 |
|
16 | 18 | namespace Microsoft.OpenApi.Tests.Models
|
17 | 19 | {
|
18 | 20 | [Collection("DefaultSettings")]
|
| 21 | + [UsesVerify] |
19 | 22 | public class OpenApiSchemaTests
|
20 | 23 | {
|
21 | 24 | public static OpenApiSchema BasicSchema = new OpenApiSchema();
|
@@ -365,117 +368,59 @@ public void SerializeAdvancedSchemaWithAllOfAsV3JsonWorks()
|
365 | 368 | actual.Should().Be(expected);
|
366 | 369 | }
|
367 | 370 |
|
368 |
| - [Fact] |
369 |
| - public void SerializeReferencedSchemaAsV3WithoutReferenceJsonWorks() |
| 371 | + [Theory] |
| 372 | + [InlineData(true)] |
| 373 | + [InlineData(false)] |
| 374 | + public async Task SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync(bool produceTerseOutput) |
370 | 375 | {
|
371 | 376 | // Arrange
|
372 | 377 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
373 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
| 378 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
374 | 379 |
|
375 |
| - var expected = @"{ |
376 |
| - ""title"": ""title1"", |
377 |
| - ""multipleOf"": 3, |
378 |
| - ""maximum"": 42, |
379 |
| - ""minimum"": 10, |
380 |
| - ""exclusiveMinimum"": true, |
381 |
| - ""type"": ""integer"", |
382 |
| - ""default"": 15, |
383 |
| - ""nullable"": true, |
384 |
| - ""externalDocs"": { |
385 |
| - ""url"": ""http://example.com/externalDocs"" |
386 |
| - } |
387 |
| -}"; |
388 | 380 |
|
389 | 381 | // Act
|
390 | 382 | ReferencedSchema.SerializeAsV3WithoutReference(writer);
|
391 | 383 | writer.Flush();
|
392 | 384 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
393 | 385 |
|
394 | 386 | // Assert
|
395 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
396 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
397 |
| - actual.Should().Be(expected); |
| 387 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
398 | 388 | }
|
399 | 389 |
|
400 |
| - [Fact] |
401 |
| - public void SerializeReferencedSchemaAsV3JsonWorks() |
| 390 | + [Theory] |
| 391 | + [InlineData(true)] |
| 392 | + [InlineData(false)] |
| 393 | + public async Task SerializeReferencedSchemaAsV3JsonWorksAsync(bool produceTerseOutput) |
402 | 394 | {
|
403 | 395 | // Arrange
|
404 | 396 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
405 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
406 |
| - |
407 |
| - var expected = @"{ |
408 |
| - ""$ref"": ""#/components/schemas/schemaObject1"" |
409 |
| -}"; |
| 397 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
410 | 398 |
|
411 | 399 | // Act
|
412 | 400 | ReferencedSchema.SerializeAsV3(writer);
|
413 | 401 | writer.Flush();
|
414 | 402 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
415 | 403 |
|
416 | 404 | // Assert
|
417 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
418 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
419 |
| - actual.Should().Be(expected); |
| 405 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
420 | 406 | }
|
421 | 407 |
|
422 |
| - [Fact] |
423 |
| - public void SerializeSchemaWRequiredPropertiesAsV2JsonWorks() |
| 408 | + [Theory] |
| 409 | + [InlineData(true)] |
| 410 | + [InlineData(false)] |
| 411 | + public async Task SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync(bool produceTerseOutput) |
424 | 412 | {
|
425 | 413 | // Arrange
|
426 | 414 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
427 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
428 |
| - var expected = @"{ |
429 |
| - ""title"": ""title1"", |
430 |
| - ""required"": [ |
431 |
| - ""property1"" |
432 |
| - ], |
433 |
| - ""properties"": { |
434 |
| - ""property1"": { |
435 |
| - ""required"": [ |
436 |
| - ""property3"" |
437 |
| - ], |
438 |
| - ""properties"": { |
439 |
| - ""property2"": { |
440 |
| - ""type"": ""integer"" |
441 |
| - }, |
442 |
| - ""property3"": { |
443 |
| - ""maxLength"": 15, |
444 |
| - ""type"": ""string"" |
445 |
| - } |
446 |
| - } |
447 |
| - }, |
448 |
| - ""property4"": { |
449 |
| - ""properties"": { |
450 |
| - ""property5"": { |
451 |
| - ""properties"": { |
452 |
| - ""property6"": { |
453 |
| - ""type"": ""boolean"" |
454 |
| - } |
455 |
| - } |
456 |
| - }, |
457 |
| - ""property7"": { |
458 |
| - ""minLength"": 2, |
459 |
| - ""type"": ""string"" |
460 |
| - } |
461 |
| - }, |
462 |
| - ""readOnly"": true |
463 |
| - } |
464 |
| - }, |
465 |
| - ""externalDocs"": { |
466 |
| - ""url"": ""http://example.com/externalDocs"" |
467 |
| - } |
468 |
| -}"; |
| 415 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
469 | 416 |
|
470 | 417 | // Act
|
471 | 418 | AdvancedSchemaWithRequiredPropertiesObject.SerializeAsV2(writer);
|
472 | 419 | writer.Flush();
|
473 | 420 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
474 | 421 |
|
475 | 422 | // Assert
|
476 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
477 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
478 |
| - actual.Should().Be(expected); |
| 423 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
479 | 424 | }
|
480 | 425 | }
|
481 | 426 | }
|
0 commit comments