|
4 | 4 | using System.Collections.Generic;
|
5 | 5 | using System.Globalization;
|
6 | 6 | using System.IO;
|
| 7 | +using System.Threading.Tasks; |
7 | 8 | using FluentAssertions;
|
8 | 9 | using Microsoft.OpenApi.Any;
|
9 | 10 | using Microsoft.OpenApi.Extensions;
|
10 | 11 | using Microsoft.OpenApi.Interfaces;
|
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 OpenApiResponseTests
|
20 | 23 | {
|
21 | 24 | public static OpenApiResponse BasicResponse = new OpenApiResponse();
|
@@ -279,132 +282,76 @@ public void SerializeAdvancedResponseAsV2YamlWorks()
|
279 | 282 | actual.Should().Be(expected);
|
280 | 283 | }
|
281 | 284 |
|
282 |
| - [Fact] |
283 |
| - public void SerializeReferencedResponseAsV3JsonWorks() |
| 285 | + [Theory] |
| 286 | + [InlineData(true)] |
| 287 | + [InlineData(false)] |
| 288 | + public async Task SerializeReferencedResponseAsV3JsonWorksAsync(bool produceTerseOutput) |
284 | 289 | {
|
285 | 290 | // Arrange
|
286 | 291 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
287 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
288 |
| - var expected = |
289 |
| - @"{ |
290 |
| - ""$ref"": ""#/components/responses/example1"" |
291 |
| -}"; |
| 292 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
292 | 293 |
|
293 | 294 | // Act
|
294 | 295 | ReferencedResponse.SerializeAsV3(writer);
|
295 | 296 | writer.Flush();
|
296 | 297 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
297 | 298 |
|
298 | 299 | // Assert
|
299 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
300 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
301 |
| - actual.Should().Be(expected); |
| 300 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
302 | 301 | }
|
303 | 302 |
|
304 |
| - [Fact] |
305 |
| - public void SerializeReferencedResponseAsV3JsonWithoutReferenceWorks() |
| 303 | + [Theory] |
| 304 | + [InlineData(true)] |
| 305 | + [InlineData(false)] |
| 306 | + public async Task SerializeReferencedResponseAsV3JsonWithoutReferenceWorksAsync(bool produceTerseOutput) |
306 | 307 | {
|
307 | 308 | // Arrange
|
308 | 309 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
309 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
310 |
| - var expected = |
311 |
| - @"{ |
312 |
| - ""description"": ""A complex object array response"", |
313 |
| - ""headers"": { |
314 |
| - ""X-Rate-Limit-Limit"": { |
315 |
| - ""description"": ""The number of allowed requests in the current period"", |
316 |
| - ""schema"": { |
317 |
| - ""type"": ""integer"" |
318 |
| - } |
319 |
| - }, |
320 |
| - ""X-Rate-Limit-Reset"": { |
321 |
| - ""description"": ""The number of seconds left in the current period"", |
322 |
| - ""schema"": { |
323 |
| - ""type"": ""integer"" |
324 |
| - } |
325 |
| - } |
326 |
| - }, |
327 |
| - ""content"": { |
328 |
| - ""text/plain"": { |
329 |
| - ""schema"": { |
330 |
| - ""type"": ""array"", |
331 |
| - ""items"": { |
332 |
| - ""$ref"": ""#/components/schemas/customType"" |
333 |
| - } |
334 |
| - } |
335 |
| - } |
336 |
| - } |
337 |
| -}"; |
| 310 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
338 | 311 |
|
339 | 312 | // Act
|
340 | 313 | ReferencedResponse.SerializeAsV3WithoutReference(writer);
|
341 | 314 | writer.Flush();
|
342 | 315 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
343 | 316 |
|
344 | 317 | // Assert
|
345 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
346 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
347 |
| - actual.Should().Be(expected); |
| 318 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
348 | 319 | }
|
349 | 320 |
|
350 |
| - [Fact] |
351 |
| - public void SerializeReferencedResponseAsV2JsonWorks() |
| 321 | + [Theory] |
| 322 | + [InlineData(true)] |
| 323 | + [InlineData(false)] |
| 324 | + public async Task SerializeReferencedResponseAsV2JsonWorksAsync(bool produceTerseOutput) |
352 | 325 | {
|
353 | 326 | // Arrange
|
354 | 327 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
355 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
356 |
| - var expected = |
357 |
| - @"{ |
358 |
| - ""$ref"": ""#/responses/example1"" |
359 |
| -}"; |
| 328 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
360 | 329 |
|
361 | 330 | // Act
|
362 | 331 | ReferencedResponse.SerializeAsV2(writer);
|
363 | 332 | writer.Flush();
|
364 | 333 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
365 | 334 |
|
366 | 335 | // Assert
|
367 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
368 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
369 |
| - actual.Should().Be(expected); |
| 336 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
370 | 337 | }
|
371 | 338 |
|
372 |
| - [Fact] |
373 |
| - public void SerializeReferencedResponseAsV2JsonWithoutReferenceWorks() |
| 339 | + [Theory] |
| 340 | + [InlineData(true)] |
| 341 | + [InlineData(false)] |
| 342 | + public async Task SerializeReferencedResponseAsV2JsonWithoutReferenceWorksAsync(bool produceTerseOutput) |
374 | 343 | {
|
375 | 344 | // Arrange
|
376 | 345 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
377 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
378 |
| - var expected = |
379 |
| - @"{ |
380 |
| - ""description"": ""A complex object array response"", |
381 |
| - ""schema"": { |
382 |
| - ""type"": ""array"", |
383 |
| - ""items"": { |
384 |
| - ""$ref"": ""#/definitions/customType"" |
385 |
| - } |
386 |
| - }, |
387 |
| - ""headers"": { |
388 |
| - ""X-Rate-Limit-Limit"": { |
389 |
| - ""description"": ""The number of allowed requests in the current period"", |
390 |
| - ""type"": ""integer"" |
391 |
| - }, |
392 |
| - ""X-Rate-Limit-Reset"": { |
393 |
| - ""description"": ""The number of seconds left in the current period"", |
394 |
| - ""type"": ""integer"" |
395 |
| - } |
396 |
| - } |
397 |
| -}"; |
| 346 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
398 | 347 |
|
399 | 348 | // Act
|
400 | 349 | ReferencedResponse.SerializeAsV2WithoutReference(writer);
|
401 | 350 | writer.Flush();
|
402 | 351 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
403 | 352 |
|
404 | 353 | // Assert
|
405 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
406 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
407 |
| - actual.Should().Be(expected); |
| 354 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
408 | 355 | }
|
409 | 356 | }
|
410 | 357 | }
|
0 commit comments