Skip to content

Commit 5596c2e

Browse files
Fix tests
Check `Paths` and `Operations` are not null.
1 parent 8d9131e commit 5596c2e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/Swashbuckle.AspNetCore.ApiTesting/OpenApiDocumentExtensions.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ internal static bool TryFindOperationById(
1111
out string pathTemplate,
1212
out HttpMethod operationType)
1313
{
14-
foreach (var pathEntry in openApiDocument.Paths ?? [])
14+
if (openApiDocument.Paths is { Count: > 0 } paths)
1515
{
16-
var pathItem = pathEntry.Value;
17-
18-
foreach (var operationEntry in pathItem.Operations)
16+
foreach (var pathEntry in paths)
1917
{
20-
if (operationEntry.Value.OperationId == operationId)
18+
var pathItem = pathEntry.Value;
19+
20+
if (pathItem.Operations is { Count: > 0 } operations)
2121
{
22-
pathTemplate = pathEntry.Key;
23-
operationType = operationEntry.Key;
24-
return true;
22+
foreach (var operation in operations)
23+
{
24+
if (operation.Value.OperationId == operationId)
25+
{
26+
pathTemplate = pathEntry.Key;
27+
operationType = operation.Key;
28+
return true;
29+
}
30+
}
2531
}
2632
}
2733
}

test/WebSites/TestFirst.IntegrationTests/ApiTestsSetup.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ private static string GetSolutionRelativeContentRoot(
5656
}
5757

5858
[CollectionDefinition("ApiTests")]
59-
public class ApiTestsCollection : ICollectionFixture<ApiTestRunner>
60-
{}
59+
public class ApiTestsCollection : ICollectionFixture<ApiTestRunner>;

0 commit comments

Comments
 (0)