Skip to content

Commit 5dc7876

Browse files
committed
code cleanup
1 parent f407702 commit 5dc7876

File tree

13 files changed

+38
-50
lines changed

13 files changed

+38
-50
lines changed

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44
using Microsoft.Extensions.Logging;
55
using Microsoft.OpenApi.Models;
6-
using Microsoft.OpenApi.Readers;
76
using Microsoft.OpenApi.Services;
87
using Microsoft.OpenApi.Tests.UtilityFiles;
98
using Moq;
10-
using SharpYaml.Tokens;
119
using Xunit;
1210

1311
namespace Microsoft.OpenApi.Hidi.Tests

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.CommandLine;
@@ -335,7 +335,7 @@ public async Task InvokeShowCommandAsync()
335335
var openApi = Path.Combine(".", "UtilityFiles", "SampleOpenApi.yml");
336336
var args = new[] { "show", "-d", openApi, "-o", "sample.md" };
337337
var parseResult = rootCommand.Parse(args);
338-
var handler = rootCommand.Subcommands.Where(c => c.Name == "show").First().Handler;
338+
var handler = rootCommand.Subcommands.First(c => c.Name == "show").Handler;
339339
var context = new InvocationContext(parseResult);
340340

341341
await handler!.InvokeAsync(context);
@@ -351,7 +351,7 @@ public async Task InvokePluginCommandAsync()
351351
var manifest = Path.Combine(".", "UtilityFiles", "exampleapimanifest.json");
352352
var args = new[] { "plugin", "-m", manifest, "--of", AppDomain.CurrentDomain.BaseDirectory };
353353
var parseResult = rootCommand.Parse(args);
354-
var handler = rootCommand.Subcommands.Where(c => c.Name == "plugin").First().Handler;
354+
var handler = rootCommand.Subcommands.First(c => c.Name == "plugin").Handler;
355355
var context = new InvocationContext(parseResult);
356356

357357
await handler!.InvokeAsync(context);

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Linq;
1+
using System.Linq;
22
using FluentAssertions;
33
using Microsoft.OpenApi.Models;
44
using Microsoft.OpenApi.Reader;
@@ -63,7 +63,7 @@ public void JustHostNoDefault()
6363
""";
6464
var result = OpenApiDocument.Parse(input, "yaml");
6565

66-
var server = result.OpenApiDocument.Servers.First();
66+
var server = result.OpenApiDocument.Servers[0];
6767
Assert.Single(result.OpenApiDocument.Servers);
6868
Assert.Equal("//www.foo.com", server.Url);
6969
}
@@ -88,7 +88,7 @@ public void NoBasePath()
8888
};
8989

9090
var result = OpenApiDocument.Parse(input, "yaml", settings);
91-
var server = result.OpenApiDocument.Servers.First();
91+
var server = result.OpenApiDocument.Servers[0];
9292
Assert.Single(result.OpenApiDocument.Servers);
9393
Assert.Equal("http://www.foo.com", server.Url);
9494
}
@@ -107,7 +107,7 @@ public void JustBasePathNoDefault()
107107
""";
108108
var result = OpenApiDocument.Parse(input, "yaml");
109109

110-
var server = result.OpenApiDocument.Servers.First();
110+
var server = result.OpenApiDocument.Servers[0];
111111
Assert.Single(result.OpenApiDocument.Servers);
112112
Assert.Equal("/baz", server.Url);
113113
}
@@ -132,7 +132,7 @@ public void JustSchemeWithCustomHost()
132132

133133
var result = OpenApiDocument.Parse(input, "yaml", settings);
134134

135-
var server = result.OpenApiDocument.Servers.First();
135+
var server = result.OpenApiDocument.Servers[0];
136136
Assert.Single(result.OpenApiDocument.Servers);
137137
Assert.Equal("http://bing.com/foo", server.Url);
138138
}
@@ -157,7 +157,7 @@ public void JustSchemeWithCustomHostWithEmptyPath()
157157

158158
var result = OpenApiDocument.Parse(input, "yaml", settings);
159159

160-
var server = result.OpenApiDocument.Servers.First();
160+
var server = result.OpenApiDocument.Servers[0];
161161
Assert.Single(result.OpenApiDocument.Servers);
162162
Assert.Equal("http://bing.com", server.Url);
163163
}
@@ -181,7 +181,7 @@ public void JustBasePathWithCustomHost()
181181

182182
var result = OpenApiDocument.Parse(input, "yaml", settings);
183183

184-
var server = result.OpenApiDocument.Servers.First();
184+
var server = result.OpenApiDocument.Servers[0];
185185
Assert.Single(result.OpenApiDocument.Servers);
186186
Assert.Equal("https://bing.com/api", server.Url);
187187
}
@@ -205,7 +205,7 @@ public void JustHostWithCustomHost()
205205

206206
var result = OpenApiDocument.Parse(input, "yaml", settings);
207207

208-
var server = result.OpenApiDocument.Servers.First();
208+
var server = result.OpenApiDocument.Servers[0];
209209
Assert.Single(result.OpenApiDocument.Servers);
210210
Assert.Equal("https://www.example.com", server.Url);
211211
}
@@ -229,7 +229,7 @@ public void JustHostWithCustomHostWithApi()
229229
};
230230

231231
var result = OpenApiDocument.Parse(input, "yaml", settings);
232-
var server = result.OpenApiDocument.Servers.First();
232+
var server = result.OpenApiDocument.Servers[0];
233233
Assert.Single(result.OpenApiDocument.Servers);
234234
Assert.Equal("https://prod.bing.com", server.Url);
235235
}
@@ -255,7 +255,7 @@ public void MultipleServers()
255255
};
256256

257257
var result = OpenApiDocument.Parse(input, "yaml", settings);
258-
var server = result.OpenApiDocument.Servers.First();
258+
var server = result.OpenApiDocument.Servers[0];
259259
Assert.Equal(2, result.OpenApiDocument.Servers.Count);
260260
Assert.Equal("http://dev.bing.com/api", server.Url);
261261
Assert.Equal("https://dev.bing.com/api", result.OpenApiDocument.Servers.Last().Url);
@@ -281,7 +281,7 @@ public void LocalHostWithCustomHost()
281281

282282
var result = OpenApiDocument.Parse(input, "yaml", settings);
283283

284-
var server = result.OpenApiDocument.Servers.First();
284+
var server = result.OpenApiDocument.Servers[0];
285285
Assert.Single(result.OpenApiDocument.Servers);
286286
Assert.Equal("https://localhost:23232", server.Url);
287287
}

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Globalization;
33
using System.IO;
44
using System.Threading.Tasks;
@@ -396,7 +396,6 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
396396
var outputWriter = new StringWriter(CultureInfo.InvariantCulture);
397397
var writer = new OpenApiJsonWriter(outputWriter, new() { InlineLocalReferences = true });
398398
actual.OpenApiDocument.SerializeAsV31(writer);
399-
var serialized = outputWriter.ToString();
400399
}
401400

402401
[Fact]

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiInfoTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using FluentAssertions;
@@ -22,7 +22,7 @@ public void ParseBasicInfoShouldSucceed()
2222
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "basicInfo.yaml"));
2323
var yamlStream = new YamlStream();
2424
yamlStream.Load(new StreamReader(stream));
25-
var yamlNode = yamlStream.Documents.First().RootNode;
25+
var yamlNode = yamlStream.Documents[0].RootNode;
2626

2727
var diagnostic = new OpenApiDiagnostic();
2828
var context = new ParsingContext(diagnostic);

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiLicenseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.IO;
@@ -25,7 +25,7 @@ public void ParseLicenseWithSpdxIdentifierShouldSucceed()
2525
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "licenseWithSpdxIdentifier.yaml"));
2626
var yamlStream = new YamlStream();
2727
yamlStream.Load(new StreamReader(stream));
28-
var yamlNode = yamlStream.Documents.First().RootNode;
28+
var yamlNode = yamlStream.Documents[0].RootNode;
2929

3030
var diagnostic = new OpenApiDiagnostic();
3131
var context = new ParsingContext(diagnostic);

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -1118,7 +1118,7 @@ public void GlobalSecurityRequirementShouldReferenceSecurityScheme()
11181118
{
11191119
var result = OpenApiDocument.Load(System.IO.Path.Combine(SampleFolderPath, "securedApi.yaml"));
11201120

1121-
var securityRequirement = result.OpenApiDocument.SecurityRequirements.First();
1121+
var securityRequirement = result.OpenApiDocument.SecurityRequirements[0];
11221122

11231123
securityRequirement.Keys.First().Should().BeEquivalentTo(result.OpenApiDocument.Components.SecuritySchemes.First().Value,
11241124
options => options.Excluding(x => x.Reference));
@@ -1331,10 +1331,9 @@ public void ParseDocWithRefsUsingProxyReferencesSucceeds()
13311331

13321332
// Act
13331333
var doc = OpenApiDocument.Load(stream, "yaml").OpenApiDocument;
1334-
var actualParam = doc.Paths["/pets"].Operations[OperationType.Get].Parameters.First();
1334+
var actualParam = doc.Paths["/pets"].Operations[OperationType.Get].Parameters[0];
13351335
var outputDoc = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0).MakeLineBreaksEnvironmentNeutral();
1336-
var output = actualParam.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
1337-
var expectedParam = expected.Paths["/pets"].Operations[OperationType.Get].Parameters.First();
1336+
var expectedParam = expected.Paths["/pets"].Operations[OperationType.Get].Parameters[0];
13381337

13391338
// Assert
13401339
actualParam.Should().BeEquivalentTo(expectedParam, options => options

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiExampleTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.IO;
@@ -63,9 +63,6 @@ public void ParseAdvancedExampleShouldSucceed()
6363
}
6464
};
6565

66-
var actualRoot = example.Value["versions"][0]["status"].Root;
67-
var expectedRoot = expected.Value["versions"][0]["status"].Root;
68-
6966
diagnostic.Errors.Should().BeEmpty();
7067

7168
example.Should().BeEquivalentTo(expected, options => options.IgnoringCyclicReferences()

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.IO;
@@ -26,7 +26,7 @@ public void OperationWithSecurityRequirementShouldReferenceSecurityScheme()
2626
{
2727
var result = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "securedOperation.yaml"));
2828

29-
var securityScheme = result.OpenApiDocument.Paths["/"].Operations[OperationType.Get].Security.First().Keys.First();
29+
var securityScheme = result.OpenApiDocument.Paths["/"].Operations[OperationType.Get].Security[0].Keys.First();
3030

3131
securityScheme.Should().BeEquivalentTo(result.OpenApiDocument.Components.SecuritySchemes.First().Value,
3232
options => options.Excluding(x => x.Reference));

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -36,7 +36,7 @@ public void ParsePrimitiveSchemaShouldSucceed()
3636
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "primitiveSchema.yaml"));
3737
var yamlStream = new YamlStream();
3838
yamlStream.Load(new StreamReader(stream));
39-
var yamlNode = yamlStream.Documents.First().RootNode;
39+
var yamlNode = yamlStream.Documents[0].RootNode;
4040

4141
var diagnostic = new OpenApiDiagnostic();
4242
var context = new ParsingContext(diagnostic);
@@ -66,10 +66,9 @@ public void ParseExampleStringFragmentShouldSucceed()
6666
""foo"": ""bar"",
6767
""baz"": [ 1,2]
6868
}";
69-
var diagnostic = new OpenApiDiagnostic();
7069

7170
// Act
72-
var openApiAny = OpenApiModelFactory.Parse<OpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
71+
var openApiAny = OpenApiModelFactory.Parse<OpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
7372

7473
// Assert
7574
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -90,10 +89,9 @@ public void ParseEnumFragmentShouldSucceed()
9089
""foo"",
9190
""baz""
9291
]";
93-
var diagnostic = new OpenApiDiagnostic();
9492

9593
// Act
96-
var openApiAny = OpenApiModelFactory.Parse<OpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);
94+
var openApiAny = OpenApiModelFactory.Parse<OpenApiAny>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic);
9795

9896
// Assert
9997
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -116,10 +114,9 @@ public void ParsePathFragmentShouldSucceed()
116114
'200':
117115
description: Ok
118116
";
119-
var diagnostic = new OpenApiDiagnostic();
120117

121118
// Act
122-
var openApiAny = OpenApiModelFactory.Parse<OpenApiPathItem>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic, "yaml");
119+
var openApiAny = OpenApiModelFactory.Parse<OpenApiPathItem>(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic, "yaml");
123120

124121
// Assert
125122
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());
@@ -151,7 +148,7 @@ public void ParseDictionarySchemaShouldSucceed()
151148
{
152149
var yamlStream = new YamlStream();
153150
yamlStream.Load(new StreamReader(stream));
154-
var yamlNode = yamlStream.Documents.First().RootNode;
151+
var yamlNode = yamlStream.Documents[0].RootNode;
155152

156153
var diagnostic = new OpenApiDiagnostic();
157154
var context = new ParsingContext(diagnostic);
@@ -183,7 +180,7 @@ public void ParseBasicSchemaWithExampleShouldSucceed()
183180
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "basicSchemaWithExample.yaml"));
184181
var yamlStream = new YamlStream();
185182
yamlStream.Load(new StreamReader(stream));
186-
var yamlNode = yamlStream.Documents.First().RootNode;
183+
var yamlNode = yamlStream.Documents[0].RootNode;
187184

188185
var diagnostic = new OpenApiDiagnostic();
189186
var context = new ParsingContext(diagnostic);

0 commit comments

Comments
 (0)