Skip to content

Commit 4801b06

Browse files
committed
chore: make new unit tests build
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent c6b1b0e commit 4801b06

File tree

2 files changed

+231
-239
lines changed

2 files changed

+231
-239
lines changed

test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiPathItemTests.cs

Lines changed: 81 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,30 @@ public async Task ParsePathItemWithQueryAndAdditionalOperationsV32Works()
2727
Assert.Equal("Operations available for pets", pathItem.Description);
2828

2929
// Regular operations
30-
Assert.True(pathItem.Operations?.ContainsKey(HttpMethod.Get));
3130
var getOp = pathItem.Operations[HttpMethod.Get];
31+
Assert.NotNull(getOp);
3232
Assert.Equal("getPets", getOp.OperationId);
3333

34-
Assert.True(pathItem.Operations?.ContainsKey(HttpMethod.Post));
3534
var postOp = pathItem.Operations[HttpMethod.Post];
35+
Assert.NotNull(postOp);
3636
Assert.Equal("createPet", postOp.OperationId);
3737

3838
// Query operation should now be on one of the operations
3939
// Since the YAML structure changed, we need to check which operation has the query
40-
Assert.NotNull(getOp.Query);
41-
Assert.Equal("Query pets with complex filters", getOp.Query.Summary);
42-
Assert.Equal("queryPets", getOp.Query.OperationId);
43-
Assert.Single(getOp.Query.Parameters);
44-
Assert.Equal("filter", getOp.Query.Parameters[0].Name);
45-
46-
// Additional operations should now be on one of the operations
47-
Assert.NotNull(getOp.AdditionalOperations);
48-
Assert.Equal(2, getOp.AdditionalOperations.Count);
49-
50-
Assert.True(getOp.AdditionalOperations.ContainsKey("notify"));
51-
var notifyOp = getOp.AdditionalOperations["notify"];
40+
var queryOp = pathItem.Operations[new HttpMethod("Query")];
41+
Assert.NotNull(queryOp);
42+
Assert.Equal("Query pets with complex filters", queryOp.Summary);
43+
Assert.Equal("queryPets", queryOp.OperationId);
44+
Assert.Single(queryOp.Parameters);
45+
Assert.Equal("filter", queryOp.Parameters[0].Name);
46+
47+
var notifyOp = Assert.Contains(new HttpMethod("notify"), pathItem.Operations);
5248
Assert.Equal("Notify about pet updates", notifyOp.Summary);
5349
Assert.Equal("notifyPetUpdates", notifyOp.OperationId);
5450
Assert.NotNull(notifyOp.RequestBody);
55-
56-
Assert.True(getOp.AdditionalOperations.ContainsKey("subscribe"));
57-
var subscribeOp = getOp.AdditionalOperations["subscribe"];
51+
52+
var subscribeOp = pathItem.Operations[new HttpMethod("subscribe")];
53+
Assert.NotNull(subscribeOp);
5854
Assert.Equal("Subscribe to pet events", subscribeOp.Summary);
5955
Assert.Equal("subscribePetEvents", subscribeOp.OperationId);
6056
Assert.Single(subscribeOp.Parameters);
@@ -78,15 +74,13 @@ public async Task ParsePathItemWithV32ExtensionsWorks()
7874
Assert.Equal("getPets", getOp.OperationId);
7975

8076
// Query operation from extension should now be on the operation
81-
Assert.NotNull(getOp.Query);
82-
Assert.Equal("Query pets with complex filters", getOp.Query.Summary);
83-
Assert.Equal("queryPets", getOp.Query.OperationId);
77+
var queryOp = pathItem.Operations[new HttpMethod("Query")];
78+
Assert.NotNull(queryOp);
79+
Assert.Equal("Query pets with complex filters", queryOp.Summary);
80+
Assert.Equal("queryPets", queryOp.OperationId);
8481

8582
// Additional operations from extension should now be on the operation
86-
Assert.NotNull(getOp.AdditionalOperations);
87-
Assert.Single(getOp.AdditionalOperations);
88-
Assert.True(getOp.AdditionalOperations.ContainsKey("notify"));
89-
var notifyOp = getOp.AdditionalOperations["notify"];
83+
var notifyOp = pathItem.Operations[new HttpMethod("notify")];
9084
Assert.Equal("Notify about pet updates", notifyOp.Summary);
9185
Assert.Equal("notifyPetUpdates", notifyOp.OperationId);
9286
}
@@ -104,27 +98,24 @@ public async Task SerializeV32PathItemToV31ProducesExtensions()
10498
{
10599
Summary = "Get operation",
106100
OperationId = "getOp",
107-
Query = new OpenApiOperation
101+
Responses = new OpenApiResponses
108102
{
109-
Summary = "Query operation",
110-
OperationId = "queryOp",
111-
Responses = new OpenApiResponses
112-
{
113-
["200"] = new OpenApiResponse { Description = "Success" }
114-
}
115-
},
116-
AdditionalOperations = new Dictionary<string, OpenApiOperation>
103+
["200"] = new OpenApiResponse { Description = "Success" }
104+
}
105+
},
106+
[new HttpMethod("Query")] = new OpenApiOperation
107+
{
108+
Summary = "Query operation",
109+
OperationId = "queryOp",
110+
Responses = new OpenApiResponses
117111
{
118-
["notify"] = new OpenApiOperation
119-
{
120-
Summary = "Notify operation",
121-
OperationId = "notifyOp",
122-
Responses = new OpenApiResponses
123-
{
124-
["200"] = new OpenApiResponse { Description = "Success" }
125-
}
126-
}
127-
},
112+
["200"] = new OpenApiResponse { Description = "Success" }
113+
}
114+
},
115+
[new HttpMethod("notify")] = new OpenApiOperation
116+
{
117+
Summary = "Notify operation",
118+
OperationId = "notifyOp",
128119
Responses = new OpenApiResponses
129120
{
130121
["200"] = new OpenApiResponse { Description = "Success" }
@@ -156,27 +147,24 @@ public async Task SerializeV32PathItemToV3ProducesExtensions()
156147
{
157148
Summary = "Get operation",
158149
OperationId = "getOp",
159-
Query = new OpenApiOperation
150+
Responses = new OpenApiResponses
160151
{
161-
Summary = "Query operation",
162-
OperationId = "queryOp",
163-
Responses = new OpenApiResponses
164-
{
165-
["200"] = new OpenApiResponse { Description = "Success" }
166-
}
167-
},
168-
AdditionalOperations = new Dictionary<string, OpenApiOperation>
152+
["200"] = new OpenApiResponse { Description = "Success" }
153+
}
154+
},
155+
[new HttpMethod("Query")] = new OpenApiOperation
156+
{
157+
Summary = "Query operation",
158+
OperationId = "queryOp",
159+
Responses = new OpenApiResponses
169160
{
170-
["notify"] = new OpenApiOperation
171-
{
172-
Summary = "Notify operation",
173-
OperationId = "notifyOp",
174-
Responses = new OpenApiResponses
175-
{
176-
["200"] = new OpenApiResponse { Description = "Success" }
177-
}
178-
}
179-
},
161+
["200"] = new OpenApiResponse { Description = "Success" }
162+
}
163+
},
164+
[new HttpMethod("notify")] = new OpenApiOperation
165+
{
166+
Summary = "Notify operation",
167+
OperationId = "notifyOp",
180168
Responses = new OpenApiResponses
181169
{
182170
["200"] = new OpenApiResponse { Description = "Success" }
@@ -208,20 +196,17 @@ public void PathItemShallowCopyIncludesV32Fields()
208196
{
209197
Summary = "Get operation",
210198
OperationId = "getOp",
211-
Query = new OpenApiOperation
212-
{
213-
Summary = "Query operation",
214-
OperationId = "queryOp"
215-
},
216-
AdditionalOperations = new Dictionary<string, OpenApiOperation>
217-
{
218-
["notify"] = new OpenApiOperation
219-
{
220-
Summary = "Notify operation",
221-
OperationId = "notifyOp"
222-
}
223-
},
224199
Responses = new OpenApiResponses()
200+
},
201+
[new HttpMethod("Query")] = new OpenApiOperation
202+
{
203+
Summary = "Query operation",
204+
OperationId = "queryOp"
205+
},
206+
[new HttpMethod("notify")] = new OpenApiOperation
207+
{
208+
Summary = "Notify operation",
209+
OperationId = "notifyOp"
225210
}
226211
}
227212
};
@@ -230,17 +215,27 @@ public void PathItemShallowCopyIncludesV32Fields()
230215
var copy = original.CreateShallowCopy();
231216

232217
// Assert
233-
var originalGetOp = original.Operations![HttpMethod.Get];
234-
var copyGetOp = copy.Operations![HttpMethod.Get];
235-
236-
Assert.NotNull(copyGetOp.Query);
237-
Assert.Equal("Query operation", copyGetOp.Query.Summary);
238-
Assert.Equal("queryOp", copyGetOp.Query.OperationId);
239-
240-
Assert.NotNull(copyGetOp.AdditionalOperations);
241-
Assert.Single(copyGetOp.AdditionalOperations);
242-
Assert.Equal("Notify operation", copyGetOp.AdditionalOperations["notify"].Summary);
243-
Assert.Equal("notifyOp", copyGetOp.AdditionalOperations["notify"].OperationId);
218+
Assert.NotNull(original.Operations);
219+
Assert.NotNull(copy.Operations);
220+
var originalGetOp = original.Operations[HttpMethod.Get];
221+
var copyGetOp = copy.Operations[HttpMethod.Get];
222+
Assert.NotNull(originalGetOp);
223+
Assert.NotNull(copyGetOp);
224+
225+
var copyQueryOp = copy.Operations[new HttpMethod("Query")];
226+
var originalQueryOp = original.Operations[new HttpMethod("Query")];
227+
Assert.NotNull(originalQueryOp);
228+
Assert.NotNull(copyQueryOp);
229+
Assert.Equal("Query operation", copyQueryOp.Summary);
230+
Assert.Equal("queryOp", copyQueryOp.OperationId);
231+
232+
233+
var originalNotifyOp = original.Operations[new HttpMethod("notify")];
234+
var copyNotifyOp = copy.Operations[new HttpMethod("notify")];
235+
Assert.NotNull(originalNotifyOp);
236+
Assert.NotNull(copyNotifyOp);
237+
Assert.Equal("Notify operation", copyNotifyOp.Summary);
238+
Assert.Equal("notifyOp", copyNotifyOp.OperationId);
244239
}
245240
}
246241
}

0 commit comments

Comments
 (0)