Skip to content

Commit 5bc9cb9

Browse files
committed
Add serialization tests
1 parent 8fc9e2a commit 5bc9cb9

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.OpenApi.Extensions;
99
using Microsoft.OpenApi.Interfaces;
1010
using Microsoft.OpenApi.Models;
11+
using SharpYaml;
1112
using Xunit;
1213

1314
namespace Microsoft.OpenApi.Tests.Models
@@ -29,6 +30,14 @@ public class OpenApiInfoTests
2930
}
3031
};
3132

33+
public static OpenApiInfo InfoWithSummary = new()
34+
{
35+
Title = "Sample Pet Store App",
36+
Summary = "This is a sample server for a pet store.",
37+
Description = "This is a sample server for a pet store.",
38+
Version = "1.1.1",
39+
};
40+
3241
public static OpenApiInfo BasicInfo = new OpenApiInfo
3342
{
3443
Title = "Sample Pet Store App",
@@ -101,6 +110,7 @@ public static IEnumerable<object[]> AdvanceInfoJsonExpect()
101110
specVersion,
102111
@"{
103112
""title"": ""Sample Pet Store App"",
113+
""summary"": ""This is a sample server for a pet store."",
104114
""description"": ""This is a sample server for a pet store."",
105115
""termsOfService"": ""http://example.com/terms/"",
106116
""contact"": {
@@ -195,5 +205,43 @@ public void InfoVersionShouldAcceptDateStyledAsVersions()
195205
expected = expected.MakeLineBreaksEnvironmentNeutral();
196206
actual.Should().Be(expected);
197207
}
208+
209+
[Fact]
210+
public void SerializeInfoObjectWithSummaryAsV3YamlWorks()
211+
{
212+
// Arrange
213+
var expected = @"title: Sample Pet Store App
214+
summary: This is a sample server for a pet store.
215+
description: This is a sample server for a pet store.
216+
version: '1.1.1'";
217+
218+
// Act
219+
var actual = InfoWithSummary.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
220+
221+
// Assert
222+
actual = actual.MakeLineBreaksEnvironmentNeutral();
223+
expected = expected.MakeLineBreaksEnvironmentNeutral();
224+
Assert.Equal(expected, actual);
225+
}
226+
227+
[Fact]
228+
public void SerializeInfoObjectWithSummaryAsV3JsonWorks()
229+
{
230+
// Arrange
231+
var expected = @"{
232+
""title"": ""Sample Pet Store App"",
233+
""summary"": ""This is a sample server for a pet store."",
234+
""description"": ""This is a sample server for a pet store."",
235+
""version"": ""1.1.1""
236+
}";
237+
238+
// Act
239+
var actual = InfoWithSummary.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
240+
241+
// Assert
242+
actual = actual.MakeLineBreaksEnvironmentNeutral();
243+
expected = expected.MakeLineBreaksEnvironmentNeutral();
244+
Assert.Equal(expected, actual);
245+
}
198246
}
199247
}

0 commit comments

Comments
 (0)