-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiHeaderTests.cs
More file actions
82 lines (74 loc) · 2.64 KB
/
OpenApiHeaderTests.cs
File metadata and controls
82 lines (74 loc) · 2.64 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.IO;
using FluentAssertions;
using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader.ParseNodes;
using Microsoft.OpenApi.Reader.V2;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
{
[Collection("DefaultSettings")]
public class OpenApiHeaderTests
{
private const string SampleFolderPath = "V2Tests/Samples/OpenApiHeader/";
[Fact]
public void ParseHeaderWithDefaultShouldSucceed()
{
// Arrange
MapNode node;
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "headerWithDefault.yaml")))
{
node = TestHelper.CreateYamlMapNode(stream);
}
// Act
var header = OpenApiV2Deserializer.LoadHeader(node, new());
// Assert
header.Should().BeEquivalentTo(
new OpenApiHeader
{
Schema = new OpenApiSchema()
{
Type = JsonSchemaType.Number,
Format = "float",
Default = new OpenApiAny(5).Node
}
},
options => options
.IgnoringCyclicReferences()
.Excluding(x => x.Schema.Default.Parent));
}
[Fact]
public void ParseHeaderWithEnumShouldSucceed()
{
// Arrange
MapNode node;
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "headerWithEnum.yaml")))
{
node = TestHelper.CreateYamlMapNode(stream);
}
// Act
var header = OpenApiV2Deserializer.LoadHeader(node, new());
// Assert
header.Should().BeEquivalentTo(
new OpenApiHeader
{
Schema = new OpenApiSchema()
{
Type = JsonSchemaType.Number,
Format = "float",
Enum =
[
new OpenApiAny(7).Node,
new OpenApiAny(8).Node,
new OpenApiAny(9).Node
]
}
}, options => options.IgnoringCyclicReferences()
.Excluding((IMemberInfo memberInfo) =>
memberInfo.Path.EndsWith("Parent")));
}
}
}