Skip to content

Commit e7ff360

Browse files
committed
Update tests
1 parent 1b286e5 commit e7ff360

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using FluentAssertions;
66
using Microsoft.OpenApi.Models;
7+
using Microsoft.OpenApi.Reader;
78
using Xunit;
89

910
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -17,14 +18,16 @@ public class ComparisonTests
1718
[InlineData("minimal")]
1819
[InlineData("basic")]
1920
//[InlineData("definitions")] //Currently broken due to V3 references not behaving the same as V2
20-
public void EquivalentV2AndV3DocumentsShouldProductEquivalentObjects(string fileName)
21+
public void EquivalentV2AndV3DocumentsShouldProduceEquivalentObjects(string fileName)
2122
{
23+
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
2224
using var streamV2 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
2325
using var streamV3 = Resources.GetStream(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
2426
var result1 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml"));
2527
var result2 = OpenApiDocument.Load(Path.Combine(SampleFolderPath, $"{fileName}.v3.yaml"));
2628

27-
result2.OpenApiDocument.Should().BeEquivalentTo(result1.OpenApiDocument);
29+
result2.OpenApiDocument.Should().BeEquivalentTo(result1.OpenApiDocument,
30+
options => options.Excluding(x => x.Workspace));
2831

2932
result1.OpenApiDiagnostic.Errors.Should().BeEquivalentTo(result2.OpenApiDiagnostic.Errors);
3033
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Globalization;
56
using System.IO;
67
using System.Linq;
78
using FluentAssertions;
89
using Json.Schema;
910
using Microsoft.OpenApi.Models;
1011
using Microsoft.OpenApi.Reader;
12+
using Microsoft.OpenApi.Writers;
13+
using VerifyXunit;
1114
using Xunit;
1215

1316
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -147,7 +150,8 @@ public void ShouldParseProducesInAnyOrder()
147150
["Error"] = errorSchema
148151
}
149152
}
150-
});
153+
}, options => options.Excluding(x => x.Workspace));
154+
151155
}
152156

153157

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public class OpenApiDocumentTests
1717
{
1818
private const string SampleFolderPath = "V31Tests/Samples/OpenApiDocument/";
1919

20+
public OpenApiDocumentTests()
21+
{
22+
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
23+
}
24+
2025
public static T Clone<T>(T element) where T : IOpenApiSerializable
2126
{
2227
using var stream = new MemoryStream();
@@ -179,7 +184,7 @@ public void ParseDocumentWithWebhooksShouldSucceed()
179184
// Assert
180185
var schema = actual.OpenApiDocument.Webhooks["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
181186
actual.OpenApiDiagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1 });
182-
actual.OpenApiDocument.Should().BeEquivalentTo(expected);
187+
actual.OpenApiDocument.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.Workspace));
183188
}
184189

185190
[Fact]
@@ -320,24 +325,11 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
320325
};
321326

322327
// Assert
323-
actual.OpenApiDocument.Should().BeEquivalentTo(expected);
328+
actual.OpenApiDocument.Should().BeEquivalentTo(expected, options => options.Excluding(x => x.Workspace));
324329
actual.OpenApiDiagnostic.Should().BeEquivalentTo(
325330
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1 });
326331
}
327332

328-
[Fact]
329-
public void ParseDocumentWithDescriptionInDollarRefsShouldSucceed()
330-
{
331-
// Arrange
332-
var actual = OpenApiDocument.Load(Path.Combine(SampleFolderPath, "documentWithSummaryAndDescriptionInReference.yaml"));
333-
334-
// Act
335-
var header = actual.OpenApiDocument.Components.Responses["Test"].Headers["X-Test"];
336-
337-
// Assert
338-
Assert.True(header.Description == "A referenced X-Test header"); /*response header #ref's description overrides the header's description*/
339-
}
340-
341333
[Fact]
342334
public void ParseDocumentWithExampleInSchemaShouldSucceed()
343335
{

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void ParseDocumentFromInlineStringShouldSucceed()
9494
Version = "0.9.1"
9595
},
9696
Paths = new OpenApiPaths()
97-
});
97+
}, options => options.Excluding(x => x.Workspace));
9898

9999
result.OpenApiDiagnostic.Should().BeEquivalentTo(
100100
new OpenApiDiagnostic()
@@ -145,7 +145,7 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed()
145145
}
146146
},
147147
Paths = new OpenApiPaths()
148-
});
148+
}, options => options.Excluding(x => x.Workspace));
149149
}
150150
[Fact]
151151
public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
@@ -161,7 +161,7 @@ public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
161161
Version = "0.9"
162162
},
163163
Paths = new OpenApiPaths()
164-
});
164+
}, options => options.Excluding(x => x.Workspace));
165165

166166
result.OpenApiDiagnostic.Should().BeEquivalentTo(
167167
new OpenApiDiagnostic
@@ -189,7 +189,7 @@ public void ParseMinimalDocumentShouldSucceed()
189189
Version = "0.9.1"
190190
},
191191
Paths = new OpenApiPaths()
192-
});
192+
}, options => options.Excluding(x => x.Workspace));
193193

194194
result.OpenApiDiagnostic.Should().BeEquivalentTo(
195195
new OpenApiDiagnostic()
@@ -510,7 +510,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed()
510510
Components = components
511511
};
512512

513-
result.OpenApiDocument.Should().BeEquivalentTo(expectedDoc);
513+
result.OpenApiDocument.Should().BeEquivalentTo(expectedDoc, options => options.Excluding(x => x.Workspace));
514514

515515
result.OpenApiDiagnostic.Should().BeEquivalentTo(
516516
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
@@ -943,7 +943,8 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
943943
}
944944
};
945945

946-
actual.OpenApiDocument.Should().BeEquivalentTo(expected, options => options.Excluding(m => m.Name == "HostDocument"));
946+
actual.OpenApiDocument.Should().BeEquivalentTo(expected, options => options.Excluding(m => m.Name == "HostDocument")
947+
.Excluding(x => x.Workspace));
947948

948949
actual.OpenApiDiagnostic.Should().BeEquivalentTo(
949950
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });

0 commit comments

Comments
 (0)