|
4 | 4 | using System.Globalization;
|
5 | 5 | using System.IO;
|
6 | 6 | using System.Text;
|
7 |
| -using FluentAssertions; |
| 7 | +using System.Threading.Tasks; |
8 | 8 | using Microsoft.OpenApi.Any;
|
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 OpenApiExampleTests
|
18 | 20 | {
|
19 | 21 | public static OpenApiExample AdvancedExample = new OpenApiExample
|
@@ -104,118 +106,58 @@ public OpenApiExampleTests(ITestOutputHelper output)
|
104 | 106 | _output = output;
|
105 | 107 | }
|
106 | 108 |
|
107 |
| - [Fact] |
108 |
| - public void SerializeAdvancedExampleAsV3JsonWorks() |
| 109 | + [Theory] |
| 110 | + [InlineData(true)] |
| 111 | + [InlineData(false)] |
| 112 | + public async Task SerializeAdvancedExampleAsV3JsonWorks(bool produceTerseOutput) |
109 | 113 | {
|
110 | 114 | // Arrange
|
111 | 115 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
112 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
113 |
| - var expected = |
114 |
| - @"{ |
115 |
| - ""value"": { |
116 |
| - ""versions"": [ |
117 |
| - { |
118 |
| - ""status"": ""Status1"", |
119 |
| - ""id"": ""v1"", |
120 |
| - ""links"": [ |
121 |
| - { |
122 |
| - ""href"": ""http://example.com/1"", |
123 |
| - ""rel"": ""sampleRel1"", |
124 |
| - ""bytes"": ""AQID"", |
125 |
| - ""binary"": ""Ñ😻😑♮Í☛oƞ♑😲☇éNjžŁ♻😟¥a´Ī♃ƠąøƩ"" |
126 |
| - } |
127 |
| - ] |
128 |
| - }, |
129 |
| - { |
130 |
| - ""status"": ""Status2"", |
131 |
| - ""id"": ""v2"", |
132 |
| - ""links"": [ |
133 |
| - { |
134 |
| - ""href"": ""http://example.com/2"", |
135 |
| - ""rel"": ""sampleRel2"" |
136 |
| - } |
137 |
| - ] |
138 |
| - } |
139 |
| - ] |
140 |
| - } |
141 |
| -}"; |
| 116 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
142 | 117 |
|
143 | 118 | // Act
|
144 | 119 | AdvancedExample.SerializeAsV3(writer);
|
145 | 120 | writer.Flush();
|
146 | 121 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
147 | 122 |
|
148 | 123 | // Assert
|
149 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
150 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
151 |
| - actual.Should().Be(expected); |
| 124 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
152 | 125 | }
|
153 | 126 |
|
154 |
| - [Fact] |
155 |
| - public void SerializeReferencedExampleAsV3JsonWorks() |
| 127 | + [Theory] |
| 128 | + [InlineData(true)] |
| 129 | + [InlineData(false)] |
| 130 | + public async Task SerializeReferencedExampleAsV3JsonWorks(bool produceTerseOutput) |
156 | 131 | {
|
157 | 132 | // Arrange
|
158 | 133 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
159 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
160 |
| - var expected = |
161 |
| - @"{ |
162 |
| - ""$ref"": ""#/components/examples/example1"" |
163 |
| -}"; |
| 134 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
164 | 135 |
|
165 | 136 | // Act
|
166 | 137 | ReferencedExample.SerializeAsV3(writer);
|
167 | 138 | writer.Flush();
|
168 | 139 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
169 | 140 |
|
170 | 141 | // Assert
|
171 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
172 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
173 |
| - actual.Should().Be(expected); |
| 142 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
174 | 143 | }
|
175 | 144 |
|
176 |
| - [Fact] |
177 |
| - public void SerializeReferencedExampleAsV3JsonWithoutReferenceWorks() |
| 145 | + [Theory] |
| 146 | + [InlineData(true)] |
| 147 | + [InlineData(false)] |
| 148 | + public async Task SerializeReferencedExampleAsV3JsonWithoutReferenceWorks(bool produceTerseOutput) |
178 | 149 | {
|
179 | 150 | // Arrange
|
180 | 151 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
181 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
182 |
| - var expected = |
183 |
| - @"{ |
184 |
| - ""value"": { |
185 |
| - ""versions"": [ |
186 |
| - { |
187 |
| - ""status"": ""Status1"", |
188 |
| - ""id"": ""v1"", |
189 |
| - ""links"": [ |
190 |
| - { |
191 |
| - ""href"": ""http://example.com/1"", |
192 |
| - ""rel"": ""sampleRel1"" |
193 |
| - } |
194 |
| - ] |
195 |
| - }, |
196 |
| - { |
197 |
| - ""status"": ""Status2"", |
198 |
| - ""id"": ""v2"", |
199 |
| - ""links"": [ |
200 |
| - { |
201 |
| - ""href"": ""http://example.com/2"", |
202 |
| - ""rel"": ""sampleRel2"" |
203 |
| - } |
204 |
| - ] |
205 |
| - } |
206 |
| - ] |
207 |
| - } |
208 |
| -}"; |
| 152 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
209 | 153 |
|
210 | 154 | // Act
|
211 | 155 | ReferencedExample.SerializeAsV3WithoutReference(writer);
|
212 | 156 | writer.Flush();
|
213 | 157 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
214 | 158 |
|
215 | 159 | // Assert
|
216 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
217 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
218 |
| - actual.Should().Be(expected); |
| 160 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
219 | 161 | }
|
220 | 162 | }
|
221 | 163 | }
|
0 commit comments