Skip to content

Commit 76a7cc1

Browse files
committed
Ensure OpenApiCallbackTests cover terse output
1 parent 9868348 commit 76a7cc1

7 files changed

+67
-65
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$request.body#/url": {
3+
"post": {
4+
"requestBody": {
5+
"content": {
6+
"application/json": {
7+
"schema": {
8+
"type": "object"
9+
}
10+
}
11+
}
12+
},
13+
"responses": {
14+
"200": {
15+
"description": "Success"
16+
}
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$request.body#/url":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"Success"}}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$request.body#/url": {
3+
"post": {
4+
"requestBody": {
5+
"content": {
6+
"application/json": {
7+
"schema": {
8+
"type": "object"
9+
}
10+
}
11+
}
12+
},
13+
"responses": {
14+
"200": {
15+
"description": "Success"
16+
}
17+
}
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$request.body#/url":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"Success"}}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"$ref": "#/components/callbacks/simpleHook"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"$ref":"#/components/callbacks/simpleHook"}

test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
using System.Globalization;
55
using System.IO;
6-
using FluentAssertions;
6+
using System.Threading.Tasks;
77
using Microsoft.OpenApi.Expressions;
88
using Microsoft.OpenApi.Models;
99
using Microsoft.OpenApi.Writers;
10+
using VerifyXunit;
1011
using Xunit;
1112
using Xunit.Abstractions;
1213

1314
namespace Microsoft.OpenApi.Tests.Models
1415
{
1516
[Collection("DefaultSettings")]
17+
[UsesVerify]
1618
public class OpenApiCallbackTests
1719
{
1820
public static OpenApiCallback AdvancedCallback = new OpenApiCallback
@@ -103,104 +105,58 @@ public OpenApiCallbackTests(ITestOutputHelper output)
103105
_output = output;
104106
}
105107

106-
[Fact]
107-
public void SerializeAdvancedCallbackAsV3JsonWorks()
108+
[Theory]
109+
[InlineData(true)]
110+
[InlineData(false)]
111+
public async Task SerializeAdvancedCallbackAsV3JsonWorks(bool produceTerseOutput)
108112
{
109113
// Arrange
110114
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 });
133116

134117
// Act
135118
AdvancedCallback.SerializeAsV3(writer);
136119
writer.Flush();
137120
var actual = outputStringWriter.GetStringBuilder().ToString();
138121

139122
// Assert
140-
actual = actual.MakeLineBreaksEnvironmentNeutral();
141-
expected = expected.MakeLineBreaksEnvironmentNeutral();
142-
actual.Should().Be(expected);
123+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
143124
}
144125

145-
[Fact]
146-
public void SerializeReferencedCallbackAsV3JsonWorks()
126+
[Theory]
127+
[InlineData(true)]
128+
[InlineData(false)]
129+
public async Task SerializeReferencedCallbackAsV3JsonWorks(bool produceTerseOutput)
147130
{
148131
// Arrange
149132
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 });
155134

156135
// Act
157136
ReferencedCallback.SerializeAsV3(writer);
158137
writer.Flush();
159138
var actual = outputStringWriter.GetStringBuilder().ToString();
160139

161140
// Assert
162-
actual = actual.MakeLineBreaksEnvironmentNeutral();
163-
expected = expected.MakeLineBreaksEnvironmentNeutral();
164-
actual.Should().Be(expected);
141+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
165142
}
166143

167-
[Fact]
168-
public void SerializeReferencedCallbackAsV3JsonWithoutReferenceWorks()
144+
[Theory]
145+
[InlineData(true)]
146+
[InlineData(false)]
147+
public async Task SerializeReferencedCallbackAsV3JsonWithoutReferenceWorks(bool produceTerseOutput)
169148
{
170149
// Arrange
171150
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 });
194152

195153
// Act
196154
ReferencedCallback.SerializeAsV3WithoutReference(writer);
197155
writer.Flush();
198156
var actual = outputStringWriter.GetStringBuilder().ToString();
199157

200158
// Assert
201-
actual = actual.MakeLineBreaksEnvironmentNeutral();
202-
expected = expected.MakeLineBreaksEnvironmentNeutral();
203-
actual.Should().Be(expected);
159+
await Verifier.Verify(actual).UseParameters(produceTerseOutput);
204160
}
205161
}
206162
}

0 commit comments

Comments
 (0)