@@ -262,13 +262,10 @@ public void TestAddingRelationshipWithInvalidTargetEntity()
262
262
) ;
263
263
264
264
RuntimeConfigValidator configValidator = InitializeRuntimeConfigValidator ( ) ;
265
- Mock < ISqlMetadataProvider > _sqlMetadataProvider = new ( ) ;
266
- Mock < IMetadataProviderFactory > _metadataProviderFactory = new ( ) ;
267
- _metadataProviderFactory . Setup ( x => x . GetMetadataProvider ( It . IsAny < string > ( ) ) ) . Returns ( _sqlMetadataProvider . Object ) ;
268
265
269
266
// Assert that expected exception is thrown. Entity used in relationship is Invalid
270
267
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
271
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
268
+ configValidator . ValidateRelationshipConfigCorrectness ( runtimeConfig ) ) ;
272
269
Assert . AreEqual ( $ "Entity: { sampleRelationship . TargetEntity } used for relationship is not defined in the config.", ex . Message ) ;
273
270
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
274
271
}
@@ -325,13 +322,10 @@ public void TestAddingRelationshipWithDisabledGraphQL()
325
322
) ;
326
323
327
324
RuntimeConfigValidator configValidator = InitializeRuntimeConfigValidator ( ) ;
328
- Mock < ISqlMetadataProvider > _sqlMetadataProvider = new ( ) ;
329
- Mock < IMetadataProviderFactory > _metadataProviderFactory = new ( ) ;
330
- _metadataProviderFactory . Setup ( x => x . GetMetadataProvider ( It . IsAny < string > ( ) ) ) . Returns ( _sqlMetadataProvider . Object ) ;
331
325
332
326
// Exception should be thrown as we cannot use an entity (with graphQL disabled) in a relationship.
333
327
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
334
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
328
+ configValidator . ValidateRelationshipConfigCorrectness ( runtimeConfig ) ) ;
335
329
Assert . AreEqual ( $ "Entity: { sampleRelationship . TargetEntity } is disabled for GraphQL.", ex . Message ) ;
336
330
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
337
331
}
@@ -417,7 +411,7 @@ string relationshipEntity
417
411
418
412
// Exception thrown as foreignKeyPair not found in the DB.
419
413
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
420
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
414
+ configValidator . ValidateRelationships ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
421
415
Assert . AreEqual ( $ "Could not find relationship between Linking Object: TEST_SOURCE_LINK"
422
416
+ $ " and entity: { relationshipEntity } .", ex . Message ) ;
423
417
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
@@ -435,7 +429,7 @@ string relationshipEntity
435
429
436
430
// Since, we have defined the relationship in Database,
437
431
// the engine was able to find foreign key relation and validation will pass.
438
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ;
432
+ configValidator . ValidateRelationships ( runtimeConfig , _metadataProviderFactory . Object ) ;
439
433
}
440
434
441
435
/// <summary>
@@ -498,7 +492,7 @@ public void TestRelationshipWithNoLinkingObjectAndEitherSourceOrTargetFieldIsNul
498
492
// Exception is thrown as foreignKey pair is not specified in the config, nor defined
499
493
// in the database.
500
494
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
501
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
495
+ configValidator . ValidateRelationships ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
502
496
Assert . AreEqual ( $ "Could not find relationship between entities:"
503
497
+ $ " SampleEntity1 and SampleEntity2.", ex . Message ) ;
504
498
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
@@ -518,7 +512,7 @@ public void TestRelationshipWithNoLinkingObjectAndEitherSourceOrTargetFieldIsNul
518
512
519
513
// No Exception is thrown as foreignKey Pair was found in the DB between
520
514
// source and target entity.
521
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ;
515
+ configValidator . ValidateRelationships ( runtimeConfig , _metadataProviderFactory . Object ) ;
522
516
}
523
517
524
518
/// <summary>
@@ -566,7 +560,6 @@ public void TestRelationshipWithoutSourceAndTargetFieldsMatching(
566
560
FileSystemRuntimeConfigLoader loader = new ( fileSystem ) ;
567
561
RuntimeConfigProvider provider = new ( loader ) { IsLateConfigured = true } ;
568
562
RuntimeConfigValidator configValidator = new ( provider , fileSystem , new Mock < ILogger < RuntimeConfigValidator > > ( ) . Object ) ;
569
- Mock < ISqlMetadataProvider > _sqlMetadataProvider = new ( ) ;
570
563
571
564
Dictionary < string , DatabaseObject > mockDictionaryForEntityDatabaseObject = new ( )
572
565
{
@@ -581,16 +574,10 @@ public void TestRelationshipWithoutSourceAndTargetFieldsMatching(
581
574
}
582
575
} ;
583
576
584
- _sqlMetadataProvider . Setup < Dictionary < string , DatabaseObject > > ( x =>
585
- x . EntityToDatabaseObject ) . Returns ( mockDictionaryForEntityDatabaseObject ) ;
586
-
587
- Mock < IMetadataProviderFactory > _metadataProviderFactory = new ( ) ;
588
- _metadataProviderFactory . Setup ( x => x . GetMetadataProvider ( It . IsAny < string > ( ) ) ) . Returns ( _sqlMetadataProvider . Object ) ;
589
-
590
577
// Exception is thrown since sourceFields and targetFields do not match in either their existence,
591
578
// or their length.
592
579
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
593
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
580
+ configValidator . ValidateRelationshipConfigCorrectness ( runtimeConfig ) ) ;
594
581
Assert . AreEqual ( expectedExceptionMessage , ex . Message ) ;
595
582
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
596
583
Assert . AreEqual ( DataApiBuilderException . SubStatusCodes . ConfigValidationError , ex . SubStatusCode ) ;
@@ -672,7 +659,7 @@ public void TestRelationshipWithoutSourceAndTargetFieldsAsValidBackingColumns(
672
659
673
660
// Exception is thrown since either source or target field does not exist as a valid backing column in their respective entity.
674
661
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
675
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
662
+ configValidator . ValidateRelationships ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
676
663
Assert . AreEqual ( expectedExceptionMessage , ex . Message ) ;
677
664
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
678
665
Assert . AreEqual ( DataApiBuilderException . SubStatusCodes . ConfigValidationError , ex . SubStatusCode ) ;
@@ -776,7 +763,6 @@ public void TestRelationshipWithoutLinkingSourceAndTargetFieldsMatching(
776
763
FileSystemRuntimeConfigLoader loader = new ( fileSystem ) ;
777
764
RuntimeConfigProvider provider = new ( loader ) { IsLateConfigured = true } ;
778
765
RuntimeConfigValidator configValidator = new ( provider , fileSystem , new Mock < ILogger < RuntimeConfigValidator > > ( ) . Object ) ;
779
- Mock < ISqlMetadataProvider > _sqlMetadataProvider = new ( ) ;
780
766
781
767
Dictionary < string , DatabaseObject > mockDictionaryForEntityDatabaseObject = new ( )
782
768
{
@@ -791,19 +777,10 @@ public void TestRelationshipWithoutLinkingSourceAndTargetFieldsMatching(
791
777
}
792
778
} ;
793
779
794
- _sqlMetadataProvider . Setup < Dictionary < string , DatabaseObject > > ( x =>
795
- x . EntityToDatabaseObject ) . Returns ( mockDictionaryForEntityDatabaseObject ) ;
796
-
797
- string discard ;
798
- _sqlMetadataProvider . Setup ( x => x . TryGetExposedColumnName ( It . IsAny < string > ( ) , It . IsAny < string > ( ) , out discard ) ) . Returns ( true ) ;
799
-
800
- Mock < IMetadataProviderFactory > _metadataProviderFactory = new ( ) ;
801
- _metadataProviderFactory . Setup ( x => x . GetMetadataProvider ( It . IsAny < string > ( ) ) ) . Returns ( _sqlMetadataProvider . Object ) ;
802
-
803
780
// Exception is thrown since linkingSourceFields and linkingTargetFields do not match in either their existence,
804
781
// or their length.
805
782
DataApiBuilderException ex = Assert . ThrowsException < DataApiBuilderException > ( ( ) =>
806
- configValidator . ValidateRelationshipsInConfig ( runtimeConfig , _metadataProviderFactory . Object ) ) ;
783
+ configValidator . ValidateRelationshipConfigCorrectness ( runtimeConfig ) ) ;
807
784
Assert . AreEqual ( expectedExceptionMessage , ex . Message ) ;
808
785
Assert . AreEqual ( HttpStatusCode . ServiceUnavailable , ex . StatusCode ) ;
809
786
Assert . AreEqual ( DataApiBuilderException . SubStatusCodes . ConfigValidationError , ex . SubStatusCode ) ;
0 commit comments