forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenApiTagComparerTests.cs
More file actions
154 lines (132 loc) · 4.36 KB
/
OpenApiTagComparerTests.cs
File metadata and controls
154 lines (132 loc) · 4.36 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Xunit;
namespace Microsoft.OpenApi.Tests;
public class OpenApiTagComparerTests
{
private readonly OpenApiTagComparer _comparer = OpenApiTagComparer.Instance;
[Fact]
public void Defensive()
{
Assert.NotNull(_comparer);
Assert.True(_comparer.Equals(null, null));
Assert.False(_comparer.Equals(null, new OpenApiTag()));
Assert.Equal(0, _comparer.GetHashCode(null));
Assert.Equal(0, _comparer.GetHashCode(new OpenApiTag()));
}
[Fact]
public void SameNamesAreEqual()
{
var openApiTag1 = new OpenApiTag { Name = "tag" };
var openApiTag2 = new OpenApiTag { Name = "tag" };
Assert.True(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact]
public void SameInstanceAreEqual()
{
var openApiTag = new OpenApiTag { Name = "tag" };
Assert.True(_comparer.Equals(openApiTag, openApiTag));
}
[Fact]
public void DifferentCasingAreNotEquals()
{
var openApiTag1 = new OpenApiTag { Name = "tag" };
var openApiTag2 = new OpenApiTag { Name = "TAG" };
Assert.False(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact]
public void WorksCorrectlyWithHashSetOfTags()
{
var tags = new HashSet<OpenApiTag>(_comparer)
{
new() { Name = "one" },
new() { Name = "two" },
new() { Name = "two" },
new() { Name = "three" }
};
Assert.Equal(["one", "two", "three"], [.. tags.Select(t => t.Name)]);
}
[Fact]
public void SameReferenceInstanceAreEqual()
{
var openApiTag = new OpenApiTagReference("tag");
Assert.True(_comparer.Equals(openApiTag, openApiTag));
}
[Fact]
public void SameReferenceIdsAreEqual()
{
var openApiTag1 = new OpenApiTagReference("tag");
var openApiTag2 = new OpenApiTagReference("tag");
Assert.True(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact]
public void SameReferenceIdAreEqualWithValidTagReferences()
{
var document = new OpenApiDocument
{
Tags = [new() { Name = "tag" }]
};
var openApiTag1 = new OpenApiTagReference("tag", document);
var openApiTag2 = new OpenApiTagReference("tag", document);
Assert.True(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact]
public void DifferentReferenceIdAreNotEqualWithValidTagReferences()
{
var document = new OpenApiDocument
{
Tags =
[
new() { Name = "one" },
new() { Name = "two" },
]
};
var openApiTag1 = new OpenApiTagReference("one", document);
var openApiTag2 = new OpenApiTagReference("two", document);
Assert.False(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact]
public void DifferentCasingReferenceIdsAreNotEqual()
{
var openApiTag1 = new OpenApiTagReference("tag");
var openApiTag2 = new OpenApiTagReference("TAG");
Assert.False(_comparer.Equals(openApiTag1, openApiTag2));
}
[Fact] // See https://github.com/microsoft/OpenAPI.NET/issues/2319
public void WorksCorrectlyWithHashSetOfReferences()
{
// The document intentionally does not contain the actual tags
var document = new OpenApiDocument();
var tags = new HashSet<OpenApiTagReference>(_comparer)
{
new("one", document),
new("two", document),
new("two", document),
new("three", document)
};
Assert.Equal(["one", "two", "three"], [..tags.Select(t => t.Reference.Id)]);
}
[Fact]
public void WorksCorrectlyWithHashSetOfReferencesToValidTags()
{
var document = new OpenApiDocument
{
Tags =
[
new() { Name = "one" },
new() { Name = "two" },
new() { Name = "three" }
]
};
var tags = new HashSet<OpenApiTagReference>(_comparer)
{
new("one", document),
new("two", document),
new("two", document),
new("three", document)
};
Assert.Equal(["one", "two", "three"], [.. tags.Select(t => t.Reference.Id)]);
}
}