|
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.Expressions;
|
8 | 8 | using Microsoft.OpenApi.Models;
|
9 | 9 | using Microsoft.OpenApi.Writers;
|
| 10 | +using VerifyXunit; |
10 | 11 | using Xunit;
|
11 | 12 | using Xunit.Abstractions;
|
12 | 13 |
|
13 | 14 | namespace Microsoft.OpenApi.Tests.Models
|
14 | 15 | {
|
15 | 16 | [Collection("DefaultSettings")]
|
| 17 | + [UsesVerify] |
16 | 18 | public class OpenApiCallbackTests
|
17 | 19 | {
|
18 | 20 | public static OpenApiCallback AdvancedCallback = new OpenApiCallback
|
@@ -103,104 +105,58 @@ public OpenApiCallbackTests(ITestOutputHelper output)
|
103 | 105 | _output = output;
|
104 | 106 | }
|
105 | 107 |
|
106 |
| - [Fact] |
107 |
| - public void SerializeAdvancedCallbackAsV3JsonWorks() |
| 108 | + [Theory] |
| 109 | + [InlineData(true)] |
| 110 | + [InlineData(false)] |
| 111 | + public async Task SerializeAdvancedCallbackAsV3JsonWorks(bool produceTerseOutput) |
108 | 112 | {
|
109 | 113 | // Arrange
|
110 | 114 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
111 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
112 |
| - var expected = |
113 |
| - @"{ |
114 |
| - ""$request.body#/url"": { |
115 |
| - ""post"": { |
116 |
| - ""requestBody"": { |
117 |
| - ""content"": { |
118 |
| - ""application/json"": { |
119 |
| - ""schema"": { |
120 |
| - ""type"": ""object"" |
121 |
| - } |
122 |
| - } |
123 |
| - } |
124 |
| - }, |
125 |
| - ""responses"": { |
126 |
| - ""200"": { |
127 |
| - ""description"": ""Success"" |
128 |
| - } |
129 |
| - } |
130 |
| - } |
131 |
| - } |
132 |
| -}"; |
| 115 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
133 | 116 |
|
134 | 117 | // Act
|
135 | 118 | AdvancedCallback.SerializeAsV3(writer);
|
136 | 119 | writer.Flush();
|
137 | 120 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
138 | 121 |
|
139 | 122 | // Assert
|
140 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
141 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
142 |
| - actual.Should().Be(expected); |
| 123 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
143 | 124 | }
|
144 | 125 |
|
145 |
| - [Fact] |
146 |
| - public void SerializeReferencedCallbackAsV3JsonWorks() |
| 126 | + [Theory] |
| 127 | + [InlineData(true)] |
| 128 | + [InlineData(false)] |
| 129 | + public async Task SerializeReferencedCallbackAsV3JsonWorks(bool produceTerseOutput) |
147 | 130 | {
|
148 | 131 | // Arrange
|
149 | 132 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
150 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
151 |
| - var expected = |
152 |
| - @"{ |
153 |
| - ""$ref"": ""#/components/callbacks/simpleHook"" |
154 |
| -}"; |
| 133 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
155 | 134 |
|
156 | 135 | // Act
|
157 | 136 | ReferencedCallback.SerializeAsV3(writer);
|
158 | 137 | writer.Flush();
|
159 | 138 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
160 | 139 |
|
161 | 140 | // Assert
|
162 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
163 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
164 |
| - actual.Should().Be(expected); |
| 141 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
165 | 142 | }
|
166 | 143 |
|
167 |
| - [Fact] |
168 |
| - public void SerializeReferencedCallbackAsV3JsonWithoutReferenceWorks() |
| 144 | + [Theory] |
| 145 | + [InlineData(true)] |
| 146 | + [InlineData(false)] |
| 147 | + public async Task SerializeReferencedCallbackAsV3JsonWithoutReferenceWorks(bool produceTerseOutput) |
169 | 148 | {
|
170 | 149 | // Arrange
|
171 | 150 | var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture);
|
172 |
| - var writer = new OpenApiJsonWriter(outputStringWriter); |
173 |
| - var expected = |
174 |
| - @"{ |
175 |
| - ""$request.body#/url"": { |
176 |
| - ""post"": { |
177 |
| - ""requestBody"": { |
178 |
| - ""content"": { |
179 |
| - ""application/json"": { |
180 |
| - ""schema"": { |
181 |
| - ""type"": ""object"" |
182 |
| - } |
183 |
| - } |
184 |
| - } |
185 |
| - }, |
186 |
| - ""responses"": { |
187 |
| - ""200"": { |
188 |
| - ""description"": ""Success"" |
189 |
| - } |
190 |
| - } |
191 |
| - } |
192 |
| - } |
193 |
| -}"; |
| 151 | + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput }); |
194 | 152 |
|
195 | 153 | // Act
|
196 | 154 | ReferencedCallback.SerializeAsV3WithoutReference(writer);
|
197 | 155 | writer.Flush();
|
198 | 156 | var actual = outputStringWriter.GetStringBuilder().ToString();
|
199 | 157 |
|
200 | 158 | // Assert
|
201 |
| - actual = actual.MakeLineBreaksEnvironmentNeutral(); |
202 |
| - expected = expected.MakeLineBreaksEnvironmentNeutral(); |
203 |
| - actual.Should().Be(expected); |
| 159 | + await Verifier.Verify(actual).UseParameters(produceTerseOutput); |
204 | 160 | }
|
205 | 161 | }
|
206 | 162 | }
|
0 commit comments