Skip to content

Commit 0d51847

Browse files
committed
Clean up tests
1 parent 07f8f08 commit 0d51847

File tree

5 files changed

+129
-76
lines changed

5 files changed

+129
-76
lines changed

test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void BrokenSimpleList()
2828
diagnostic.Errors.Should().BeEquivalentTo(new List<OpenApiError>() {
2929
new OpenApiError(new OpenApiReaderException("Expected a value.") {
3030
Pointer = "#line=4"
31-
})
31+
}),
32+
new OpenApiError("", "Paths is a REQUIRED field at #/")
3233
});
3334
}
3435

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
152152
});
153153

154154
context.Should().BeEquivalentTo(
155-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi2_0 });
155+
new OpenApiDiagnostic()
156+
{
157+
SpecificationVersion = OpenApiSpecVersion.OpenApi2_0,
158+
Errors = new List<OpenApiError>()
159+
{
160+
new OpenApiError("", "Paths is a REQUIRED field at #/")
161+
}
162+
});
156163
}
157164

158165
[Fact]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ public void InvalidHostShouldYieldError()
285285
{
286286
Errors =
287287
{
288-
new OpenApiError("#/", "Invalid host")
288+
new OpenApiError("#/", "Invalid host"),
289+
new OpenApiError("", "Paths is a REQUIRED field at #/")
289290
},
290291
SpecificationVersion = OpenApiSpecVersion.OpenApi2_0
291292
});

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

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ public void ParseDocumentFromInlineStringShouldSucceed()
100100
});
101101

102102
context.Should().BeEquivalentTo(
103-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
103+
new OpenApiDiagnostic()
104+
{
105+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
106+
Errors = new List<OpenApiError>()
107+
{
108+
new OpenApiError("", "Paths is a REQUIRED field at #/")
109+
}
110+
});
104111
}
105112

106113
[Theory]
@@ -172,7 +179,14 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
172179
});
173180

174181
context.Should().BeEquivalentTo(
175-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
182+
new OpenApiDiagnostic()
183+
{
184+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
185+
Errors = new List<OpenApiError>()
186+
{
187+
new OpenApiError("", "Paths is a REQUIRED field at #/")
188+
}
189+
});
176190
}
177191

178192
[Fact]
@@ -183,7 +197,14 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed()
183197
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
184198

185199
diagnostic.Should().BeEquivalentTo(
186-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
200+
new OpenApiDiagnostic()
201+
{
202+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
203+
Errors = new List<OpenApiError>()
204+
{
205+
new OpenApiError("", "Paths is a REQUIRED field at #/")
206+
}
207+
});
187208

188209
openApiDoc.Should().BeEquivalentTo(
189210
new OpenApiDocument
@@ -214,30 +235,29 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed()
214235
[Fact]
215236
public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
216237
{
217-
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "brokenMinimalDocument.yaml")))
218-
{
219-
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
238+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "brokenMinimalDocument.yaml"));
239+
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
220240

221-
openApiDoc.Should().BeEquivalentTo(
222-
new OpenApiDocument
241+
openApiDoc.Should().BeEquivalentTo(
242+
new OpenApiDocument
243+
{
244+
Info = new OpenApiInfo
223245
{
224-
Info = new OpenApiInfo
225-
{
226-
Version = "0.9"
227-
},
228-
Paths = new OpenApiPaths()
229-
});
246+
Version = "0.9"
247+
},
248+
Paths = new OpenApiPaths()
249+
});
230250

231-
diagnostic.Should().BeEquivalentTo(
232-
new OpenApiDiagnostic
251+
diagnostic.Should().BeEquivalentTo(
252+
new OpenApiDiagnostic
253+
{
254+
Errors =
233255
{
234-
Errors =
235-
{
256+
new OpenApiError("", "Paths is a REQUIRED field at #/"),
236257
new OpenApiValidatorError(nameof(OpenApiInfoRules.InfoRequiredFields),"#/info/title", "The field 'title' in 'info' object is REQUIRED.")
237-
},
238-
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
239-
});
240-
}
258+
},
259+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0
260+
});
241261
}
242262

243263
[Fact]
@@ -259,7 +279,14 @@ public void ParseMinimalDocumentShouldSucceed()
259279
});
260280

261281
diagnostic.Should().BeEquivalentTo(
262-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
282+
new OpenApiDiagnostic()
283+
{
284+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
285+
Errors = new List<OpenApiError>()
286+
{
287+
new OpenApiError("", "Paths is a REQUIRED field at #/")
288+
}
289+
});
263290
}
264291
}
265292

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

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using System.Linq;
77
using FluentAssertions;
88
using Microsoft.OpenApi.Any;
9+
using Microsoft.OpenApi.Exceptions;
910
using Microsoft.OpenApi.Models;
11+
using Microsoft.OpenApi.Readers.Exceptions;
1012
using Microsoft.OpenApi.Readers.ParseNodes;
1113
using Microsoft.OpenApi.Readers.V3;
1214
using SharpYaml.Serialization;
@@ -324,22 +326,28 @@ public void ParseBasicSchemaWithExampleShouldSucceed()
324326
[Fact]
325327
public void ParseBasicSchemaWithReferenceShouldSucceed()
326328
{
327-
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "basicSchemaWithReference.yaml")))
328-
{
329-
// Act
330-
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
329+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "basicSchemaWithReference.yaml"));
330+
// Act
331+
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
331332

332-
// Assert
333-
var components = openApiDoc.Components;
333+
// Assert
334+
var components = openApiDoc.Components;
334335

335-
diagnostic.Should().BeEquivalentTo(
336-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
336+
diagnostic.Should().BeEquivalentTo(
337+
new OpenApiDiagnostic()
338+
{
339+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
340+
Errors = new List<OpenApiError>()
341+
{
342+
new OpenApiError("", "Paths is a REQUIRED field at #/")
343+
}
344+
});
337345

338-
components.Should().BeEquivalentTo(
339-
new OpenApiComponents
346+
components.Should().BeEquivalentTo(
347+
new OpenApiComponents
348+
{
349+
Schemas =
340350
{
341-
Schemas =
342-
{
343351
["ErrorModel"] = new OpenApiSchema
344352
{
345353
Type = "object",
@@ -422,30 +430,35 @@ public void ParseBasicSchemaWithReferenceShouldSucceed()
422430
}
423431
}
424432
}
425-
}
426-
}, options => options.Excluding(m => m.Name == "HostDocument"));
427-
}
433+
}
434+
}, options => options.Excluding(m => m.Name == "HostDocument"));
428435
}
429436

430437
[Fact]
431438
public void ParseAdvancedSchemaWithReferenceShouldSucceed()
432439
{
433-
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "advancedSchemaWithReference.yaml")))
434-
{
435-
// Act
436-
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
440+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "advancedSchemaWithReference.yaml"));
441+
// Act
442+
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
437443

438-
// Assert
439-
var components = openApiDoc.Components;
444+
// Assert
445+
var components = openApiDoc.Components;
440446

441-
diagnostic.Should().BeEquivalentTo(
442-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
447+
diagnostic.Should().BeEquivalentTo(
448+
new OpenApiDiagnostic()
449+
{
450+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
451+
Errors = new List<OpenApiError>()
452+
{
453+
new OpenApiError("", "Paths is a REQUIRED field at #/")
454+
}
455+
});
443456

444-
components.Should().BeEquivalentTo(
445-
new OpenApiComponents
457+
components.Should().BeEquivalentTo(
458+
new OpenApiComponents
459+
{
460+
Schemas =
446461
{
447-
Schemas =
448-
{
449462
["Pet"] = new OpenApiSchema
450463
{
451464
Type = "object",
@@ -602,29 +615,34 @@ public void ParseAdvancedSchemaWithReferenceShouldSucceed()
602615
HostDocument = openApiDoc
603616
}
604617
}
605-
}
606-
}, options => options.Excluding(m => m.Name == "HostDocument"));
607-
}
618+
}
619+
}, options => options.Excluding(m => m.Name == "HostDocument"));
608620
}
609621

610622

611623
[Fact]
612624
public void ParseSelfReferencingSchemaShouldNotStackOverflow()
613625
{
614-
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "selfReferencingSchema.yaml")))
615-
{
616-
// Act
617-
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
626+
using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "selfReferencingSchema.yaml"));
627+
// Act
628+
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
618629

619-
// Assert
620-
var components = openApiDoc.Components;
630+
// Assert
631+
var components = openApiDoc.Components;
621632

622-
diagnostic.Should().BeEquivalentTo(
623-
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
633+
diagnostic.Should().BeEquivalentTo(
634+
new OpenApiDiagnostic()
635+
{
636+
SpecificationVersion = OpenApiSpecVersion.OpenApi3_0,
637+
Errors = new List<OpenApiError>()
638+
{
639+
new OpenApiError("", "Paths is a REQUIRED field at #/")
640+
}
641+
});
624642

625-
var schemaExtension = new OpenApiSchema()
626-
{
627-
AllOf = { new OpenApiSchema()
643+
var schemaExtension = new OpenApiSchema()
644+
{
645+
AllOf = { new OpenApiSchema()
628646
{
629647
Title = "schemaExtension",
630648
Type = "object",
@@ -642,17 +660,16 @@ public void ParseSelfReferencingSchemaShouldNotStackOverflow()
642660
}
643661
}
644662
},
645-
Reference = new OpenApiReference()
646-
{
647-
Type = ReferenceType.Schema,
648-
Id = "microsoft.graph.schemaExtension"
649-
}
650-
};
663+
Reference = new OpenApiReference()
664+
{
665+
Type = ReferenceType.Schema,
666+
Id = "microsoft.graph.schemaExtension"
667+
}
668+
};
651669

652-
schemaExtension.AllOf[0].Properties["child"] = schemaExtension;
670+
schemaExtension.AllOf[0].Properties["child"] = schemaExtension;
653671

654-
components.Schemas["microsoft.graph.schemaExtension"].Should().BeEquivalentTo(components.Schemas["microsoft.graph.schemaExtension"].AllOf[0].Properties["child"]);
655-
}
672+
components.Schemas["microsoft.graph.schemaExtension"].Should().BeEquivalentTo(components.Schemas["microsoft.graph.schemaExtension"].AllOf[0].Properties["child"]);
656673
}
657674
}
658675
}

0 commit comments

Comments
 (0)