-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiContactTests.cs
More file actions
97 lines (86 loc) · 3.2 KB
/
OpenApiContactTests.cs
File metadata and controls
97 lines (86 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Xunit;
namespace Microsoft.OpenApi.Tests.Models
{
[Collection("DefaultSettings")]
public class OpenApiContactTests
{
public static OpenApiContact BasicContact = new();
public static OpenApiContact AdvanceContact = new()
{
Name = "API Support",
Url = new("http://www.example.com/support"),
Email = "support@example.com",
Extensions = new()
{
{"x-internal-id", new OpenApiAny(42)}
}
};
[Theory]
[InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json, "{ }")]
[InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json, "{ }")]
[InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Yaml, "{ }")]
[InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Yaml, "{ }")]
public async Task SerializeBasicContactWorks(
OpenApiSpecVersion version,
string format,
string expected)
{
// Arrange & Act
var actual = await BasicContact.SerializeAsync(version, format);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
[InlineData(OpenApiSpecVersion.OpenApi2_0)]
public async Task SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version)
{
// Arrange
var expected =
"""
{
"name": "API Support",
"url": "http://www.example.com/support",
"email": "support@example.com",
"x-internal-id": 42
}
""";
// Act
var actual = await AdvanceContact.SerializeAsJsonAsync(version);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
[InlineData(OpenApiSpecVersion.OpenApi2_0)]
public async Task SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version)
{
// Arrange
var expected =
"""
name: API Support
url: http://www.example.com/support
email: support@example.com
x-internal-id: 42
""";
// Act
var actual = await AdvanceContact.SerializeAsYamlAsync(version);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
Assert.Equal(expected, actual);
}
}
}