|
3 | 3 |
|
4 | 4 | using System.Globalization;
|
5 | 5 | using System.IO;
|
6 |
| -using FluentAssertions; |
| 6 | +using System.Threading.Tasks; |
7 | 7 | using Microsoft.OpenApi.Any;
|
8 | 8 | using Microsoft.OpenApi.Expressions;
|
9 | 9 | using Microsoft.OpenApi.Models;
|
10 | 10 | using Microsoft.OpenApi.Writers;
|
| 11 | +using VerifyXunit; |
11 | 12 | using Xunit;
|
12 | 13 | using Xunit.Abstractions;
|
13 | 14 |
|
14 | 15 | namespace Microsoft.OpenApi.Tests.Models
|
15 | 16 | {
|
16 | 17 | [Collection("DefaultSettings")]
|
| 18 | + [UsesVerify] |
17 | 19 | public class OpenApiLinkTests
|
18 | 20 | {
|
19 | 21 | public static OpenApiLink AdvancedLink = new OpenApiLink
|
@@ -76,90 +78,58 @@ public OpenApiLinkTests(ITestOutputHelper output)
|
76 | 78 | _output = output;
|
77 | 79 | }
|
78 | 80 |
|
79 |
| - [Fact] |
80 |
| - public void SerializeAdvancedLinkAsV3JsonWorks() |
| 81 | + [Theory] |
| 82 | + [InlineData(true)] |
| 83 | + [InlineData(false)] |
| 84 | + public async Task SerializeAdvancedLinkAsV3JsonWorksAsync(bool produceTerseOutput) |
81 | 85 | {
|
82 | 86 | // Arrange
|
83 | 87 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
84 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
85 |
| - var expected = |
86 |
| - @"{ |
87 |
| - ""operationId"": ""operationId1"", |
88 |
| - ""parameters"": { |
89 |
| - ""parameter1"": ""$request.path.id"" |
90 |
| - }, |
91 |
| - ""requestBody"": { |
92 |
| - ""property1"": true |
93 |
| - }, |
94 |
| - ""description"": ""description1"", |
95 |
| - ""server"": { |
96 |
| - ""description"": ""serverDescription1"" |
97 |
| - } |
98 |
| -}"; |
| 88 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
99 | 89 |
|
100 | 90 | // Act
|
101 | 91 | AdvancedLink.SerializeAsV3(writer);
|
102 | 92 | writer.Flush();
|
103 | 93 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
104 | 94 |
|
105 | 95 | // Assert
|
106 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
107 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
108 |
| - actual.Should().Be(expected); |
| 96 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
109 | 97 | }
|
110 | 98 |
|
111 |
| - [Fact] |
112 |
| - public void SerializeReferencedLinkAsV3JsonWorks() |
| 99 | + [Theory] |
| 100 | + [InlineData(true)] |
| 101 | + [InlineData(false)] |
| 102 | + public async Task SerializeReferencedLinkAsV3JsonWorksAsync(bool produceTerseOutput) |
113 | 103 | {
|
114 | 104 | // Arrange
|
115 | 105 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
116 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
117 |
| - var expected = |
118 |
| - @"{ |
119 |
| - ""$ref"": ""#/components/links/example1"" |
120 |
| -}"; |
| 106 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
121 | 107 |
|
122 | 108 | // Act
|
123 | 109 | ReferencedLink.SerializeAsV3(writer);
|
124 | 110 | writer.Flush();
|
125 | 111 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
126 | 112 |
|
127 | 113 | // Assert
|
128 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
129 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
130 |
| - actual.Should().Be(expected); |
| 114 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
131 | 115 | }
|
132 | 116 |
|
133 |
| - [Fact] |
134 |
| - public void SerializeReferencedLinkAsV3JsonWithoutReferenceWorks() |
| 117 | + [Theory] |
| 118 | + [InlineData(true)] |
| 119 | + [InlineData(false)] |
| 120 | + public async Task SerializeReferencedLinkAsV3JsonWithoutReferenceWorksAsync(bool produceTerseOutput) |
135 | 121 | {
|
136 | 122 | // Arrange
|
137 | 123 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
138 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
139 |
| - var expected = |
140 |
| - @"{ |
141 |
| - ""operationId"": ""operationId1"", |
142 |
| - ""parameters"": { |
143 |
| - ""parameter1"": ""$request.path.id"" |
144 |
| - }, |
145 |
| - ""requestBody"": { |
146 |
| - ""property1"": true |
147 |
| - }, |
148 |
| - ""description"": ""description1"", |
149 |
| - ""server"": { |
150 |
| - ""description"": ""serverDescription1"" |
151 |
| - } |
152 |
| -}"; |
| 124 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
153 | 125 |
|
154 | 126 | // Act
|
155 | 127 | ReferencedLink.SerializeAsV3WithoutReference(writer);
|
156 | 128 | writer.Flush();
|
157 | 129 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
158 | 130 |
|
159 | 131 | // Assert
|
160 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
161 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
162 |
| - actual.Should().Be(expected); |
| 132 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
163 | 133 | }
|
164 | 134 | }
|
165 | 135 | }
|
0 commit comments