@@ -243,26 +243,55 @@ public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
243
243
[ Fact ]
244
244
public void ParseMinimalDocumentShouldSucceed ( )
245
245
{
246
- using ( var stream = Resources . GetStream ( Path . Combine ( SampleFolderPath , "minimalDocument.yaml" ) ) )
247
- {
248
- var openApiDoc = new OpenApiStreamReader ( ) . Read ( stream , out var diagnostic ) ;
246
+ using var stream = Resources . GetStream ( Path . Combine ( SampleFolderPath , "minimalDocument.yaml" ) ) ;
247
+ var openApiDoc = new OpenApiStreamReader ( ) . Read ( stream , out var diagnostic ) ;
249
248
250
- openApiDoc . Should ( ) . BeEquivalentTo (
251
- new OpenApiDocument
249
+ openApiDoc . Should ( ) . BeEquivalentTo (
250
+ new OpenApiDocument
251
+ {
252
+ Info = new OpenApiInfo
252
253
{
253
- Info = new OpenApiInfo
254
- {
255
- Title = "Simple Document" ,
256
- Version = "0.9.1"
257
- } ,
258
- Paths = new OpenApiPaths ( )
259
- } ) ;
254
+ Title = "Simple Document" ,
255
+ Version = "0.9.1"
256
+ } ,
257
+ Paths = new OpenApiPaths ( )
258
+ } ) ;
260
259
261
- diagnostic . Should ( ) . BeEquivalentTo (
262
- new OpenApiDiagnostic ( ) { SpecificationVersion = OpenApiSpecVersion . OpenApi3_0 } ) ;
263
- }
260
+ diagnostic . Should ( ) . BeEquivalentTo (
261
+ new OpenApiDiagnostic ( ) { SpecificationVersion = OpenApiSpecVersion . OpenApi3_0 } ) ;
264
262
}
265
263
264
+ [ Fact ]
265
+ public void TestHashCodesForSimilarOpenApiDocuments ( )
266
+ {
267
+ // Arrange
268
+ using var stream1 = Resources . GetStream ( Path . Combine ( SampleFolderPath , "minimalDocument.yaml" ) ) ;
269
+ using var stream2 = Resources . GetStream ( Path . Combine ( SampleFolderPath , "minimalDocument.yaml" ) ) ;
270
+ using var stream3 = Resources . GetStream ( Path . Combine ( SampleFolderPath , "minimalDocumentWithWhitespace.yaml" ) ) ;
271
+
272
+ // Act
273
+ /*
274
+ Test whether reading in the same document twice yields the same hash code,
275
+ And reading in similar documents but one has a whitespace yields the same hash code
276
+ */
277
+ var openApiDoc1 = new OpenApiStreamReader ( ) . Read ( stream1 , out var diagnostic1 ) ;
278
+ var openApiDoc2 = new OpenApiStreamReader ( ) . Read ( stream2 , out var diagnostic2 ) ;
279
+ var openApiDoc3 = new OpenApiStreamReader ( ) . Read ( stream3 , out var diagnostic3 ) ;
280
+
281
+ // Assert
282
+ /* The assumption is, if doc1.Equals(doc2), then doc1.GetHashCode().Equals(doc2.GetHashCode())*/
283
+ if ( openApiDoc1 . Equals ( openApiDoc2 ) && openApiDoc2 . Equals ( openApiDoc3 ) )
284
+ {
285
+ Assert . Equal ( diagnostic1 . HashCode , diagnostic2 . HashCode ) ;
286
+ Assert . Equal ( diagnostic2 . HashCode , diagnostic3 . HashCode ) ;
287
+ }
288
+
289
+ /*Adding a server object to the original doc to check whether the hash code changes*/
290
+ openApiDoc1 . Servers = new List < OpenApiServer > ( ) ;
291
+ var hash = openApiDoc1 . GetHashCode ( ) ;
292
+ Assert . NotEqual ( diagnostic1 . HashCode , hash ) ;
293
+ }
294
+
266
295
[ Fact ]
267
296
public void ParseStandardPetStoreDocumentShouldSucceed ( )
268
297
{
0 commit comments