@@ -17,12 +17,14 @@ public ResourceDefinitionReadTests(IntegrationTestContext<TestableStartup<Univer
17
17
{
18
18
_testContext = testContext ;
19
19
20
+ testContext . UseController < ConstellationsController > ( ) ;
20
21
testContext . UseController < StarsController > ( ) ;
21
22
testContext . UseController < PlanetsController > ( ) ;
22
23
testContext . UseController < MoonsController > ( ) ;
23
24
24
25
testContext . ConfigureServices ( services =>
25
26
{
27
+ services . AddResourceDefinition < ConstellationDefinition > ( ) ;
26
28
services . AddResourceDefinition < StarDefinition > ( ) ;
27
29
services . AddResourceDefinition < PlanetDefinition > ( ) ;
28
30
services . AddResourceDefinition < MoonDefinition > ( ) ;
@@ -323,7 +325,6 @@ public async Task Filter_from_resource_definition_is_applied_at_secondary_endpoi
323
325
324
326
await _testContext . RunOnDatabaseAsync ( async dbContext =>
325
327
{
326
- await dbContext . ClearTableAsync < Planet > ( ) ;
327
328
dbContext . Stars . Add ( star ) ;
328
329
await dbContext . SaveChangesAsync ( ) ;
329
330
} ) ;
@@ -375,7 +376,6 @@ public async Task Filter_from_resource_definition_is_applied_at_relationship_end
375
376
376
377
await _testContext . RunOnDatabaseAsync ( async dbContext =>
377
378
{
378
- await dbContext . ClearTableAsync < Planet > ( ) ;
379
379
dbContext . Stars . Add ( star ) ;
380
380
await dbContext . SaveChangesAsync ( ) ;
381
381
} ) ;
@@ -409,6 +409,198 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
409
409
} , options => options . WithStrictOrdering ( ) ) ;
410
410
}
411
411
412
+ [ Fact ]
413
+ public async Task No_total_when_resource_definition_has_filter_on_inverse_ManyToOne_at_secondary_endpoint ( )
414
+ {
415
+ // Arrange
416
+ var hitCounter = _testContext . Factory . Services . GetRequiredService < ResourceDefinitionHitCounter > ( ) ;
417
+
418
+ var settingsProvider = ( TestClientSettingsProvider ) _testContext . Factory . Services . GetRequiredService < IClientSettingsProvider > ( ) ;
419
+ settingsProvider . HideVeryLargeStars ( ) ;
420
+
421
+ Star star = _fakers . Star . GenerateOne ( ) ;
422
+ star . Planets = _fakers . Planet . GenerateSet ( 1 ) ;
423
+
424
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
425
+ {
426
+ dbContext . Stars . Add ( star ) ;
427
+ await dbContext . SaveChangesAsync ( ) ;
428
+ } ) ;
429
+
430
+ string route = $ "/stars/{ star . StringId } /planets";
431
+
432
+ // Act
433
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
434
+
435
+ // Assert
436
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . OK ) ;
437
+
438
+ responseDocument . Data . ManyValue . Should ( ) . HaveCount ( 1 ) ;
439
+ responseDocument . Data . ManyValue [ 0 ] . Id . Should ( ) . Be ( star . Planets . ElementAt ( 0 ) . StringId ) ;
440
+
441
+ responseDocument . Meta . Should ( ) . BeNull ( ) ;
442
+
443
+ hitCounter . HitExtensibilityPoints . Should ( ) . BeEquivalentTo ( new [ ]
444
+ {
445
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
446
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyPagination ) ,
447
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
448
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySort ) ,
449
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
450
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyIncludes ) ,
451
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
452
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
453
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
454
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . GetMeta )
455
+ } , options => options . WithStrictOrdering ( ) ) ;
456
+ }
457
+
458
+ [ Fact ]
459
+ public async Task Has_total_when_resource_definition_has_filter_on_inverse_ManyToMany_at_secondary_endpoint ( )
460
+ {
461
+ // Arrange
462
+ var hitCounter = _testContext . Factory . Services . GetRequiredService < ResourceDefinitionHitCounter > ( ) ;
463
+
464
+ var settingsProvider = ( TestClientSettingsProvider ) _testContext . Factory . Services . GetRequiredService < IClientSettingsProvider > ( ) ;
465
+ settingsProvider . HideConstellationsVisibleDuringWinter ( ) ;
466
+
467
+ Constellation constellation = _fakers . Constellation . GenerateOne ( ) ;
468
+ constellation . VisibleDuring = Season . Winter ;
469
+ constellation . Stars = _fakers . Star . GenerateSet ( 1 ) ;
470
+
471
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
472
+ {
473
+ dbContext . Constellations . Add ( constellation ) ;
474
+ await dbContext . SaveChangesAsync ( ) ;
475
+ } ) ;
476
+
477
+ string route = $ "/constellations/{ constellation . StringId } /stars";
478
+
479
+ // Act
480
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
481
+
482
+ // Assert
483
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . NotFound ) ;
484
+
485
+ responseDocument . Errors . Should ( ) . HaveCount ( 1 ) ;
486
+
487
+ ErrorObject error = responseDocument . Errors [ 0 ] ;
488
+ error . StatusCode . Should ( ) . Be ( HttpStatusCode . NotFound ) ;
489
+ error . Title . Should ( ) . Be ( "The requested resource does not exist." ) ;
490
+ error . Detail . Should ( ) . Be ( $ "Resource of type 'constellations' with ID '{ constellation . StringId } ' does not exist.") ;
491
+
492
+ responseDocument . Meta . Should ( ) . ContainTotal ( 0 ) ;
493
+
494
+ hitCounter . HitExtensibilityPoints . Should ( ) . BeEquivalentTo ( new [ ]
495
+ {
496
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
497
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
498
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyPagination ) ,
499
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
500
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySort ) ,
501
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
502
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyIncludes ) ,
503
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
504
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter )
505
+ } , options => options . WithStrictOrdering ( ) ) ;
506
+ }
507
+
508
+ [ Fact ]
509
+ public async Task No_total_when_resource_definition_has_filter_on_inverse_ManyToOne_at_relationship_endpoint ( )
510
+ {
511
+ // Arrange
512
+ var hitCounter = _testContext . Factory . Services . GetRequiredService < ResourceDefinitionHitCounter > ( ) ;
513
+
514
+ var settingsProvider = ( TestClientSettingsProvider ) _testContext . Factory . Services . GetRequiredService < IClientSettingsProvider > ( ) ;
515
+ settingsProvider . HideVeryLargeStars ( ) ;
516
+
517
+ Star star = _fakers . Star . GenerateOne ( ) ;
518
+ star . Planets = _fakers . Planet . GenerateSet ( 1 ) ;
519
+
520
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
521
+ {
522
+ dbContext . Stars . Add ( star ) ;
523
+ await dbContext . SaveChangesAsync ( ) ;
524
+ } ) ;
525
+
526
+ string route = $ "/stars/{ star . StringId } /relationships/planets";
527
+
528
+ // Act
529
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
530
+
531
+ // Assert
532
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . OK ) ;
533
+
534
+ responseDocument . Data . ManyValue . Should ( ) . HaveCount ( 1 ) ;
535
+ responseDocument . Data . ManyValue [ 0 ] . Id . Should ( ) . Be ( star . Planets . ElementAt ( 0 ) . StringId ) ;
536
+
537
+ responseDocument . Meta . Should ( ) . BeNull ( ) ;
538
+
539
+ hitCounter . HitExtensibilityPoints . Should ( ) . BeEquivalentTo ( new [ ]
540
+ {
541
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
542
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyPagination ) ,
543
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
544
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySort ) ,
545
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
546
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplyIncludes ) ,
547
+ ( typeof ( Planet ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
548
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
549
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter )
550
+ } , options => options . WithStrictOrdering ( ) ) ;
551
+ }
552
+
553
+ [ Fact ]
554
+ public async Task Has_total_when_resource_definition_has_filter_on_inverse_ManyToMany_at_relationship_endpoint ( )
555
+ {
556
+ // Arrange
557
+ var hitCounter = _testContext . Factory . Services . GetRequiredService < ResourceDefinitionHitCounter > ( ) ;
558
+
559
+ var settingsProvider = ( TestClientSettingsProvider ) _testContext . Factory . Services . GetRequiredService < IClientSettingsProvider > ( ) ;
560
+ settingsProvider . HideConstellationsVisibleDuringWinter ( ) ;
561
+
562
+ Constellation constellation = _fakers . Constellation . GenerateOne ( ) ;
563
+ constellation . VisibleDuring = Season . Winter ;
564
+ constellation . Stars = _fakers . Star . GenerateSet ( 1 ) ;
565
+
566
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
567
+ {
568
+ dbContext . Constellations . Add ( constellation ) ;
569
+ await dbContext . SaveChangesAsync ( ) ;
570
+ } ) ;
571
+
572
+ string route = $ "/constellations/{ constellation . StringId } /relationships/stars";
573
+
574
+ // Act
575
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecuteGetAsync < Document > ( route ) ;
576
+
577
+ // Assert
578
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . NotFound ) ;
579
+
580
+ responseDocument . Errors . Should ( ) . HaveCount ( 1 ) ;
581
+
582
+ ErrorObject error = responseDocument . Errors [ 0 ] ;
583
+ error . StatusCode . Should ( ) . Be ( HttpStatusCode . NotFound ) ;
584
+ error . Title . Should ( ) . Be ( "The requested resource does not exist." ) ;
585
+ error . Detail . Should ( ) . Be ( $ "Resource of type 'constellations' with ID '{ constellation . StringId } ' does not exist.") ;
586
+
587
+ responseDocument . Meta . Should ( ) . ContainTotal ( 0 ) ;
588
+
589
+ hitCounter . HitExtensibilityPoints . Should ( ) . BeEquivalentTo ( new [ ]
590
+ {
591
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
592
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
593
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyPagination ) ,
594
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter ) ,
595
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySort ) ,
596
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
597
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplyIncludes ) ,
598
+ ( typeof ( Star ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
599
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplySparseFieldSet ) ,
600
+ ( typeof ( Constellation ) , ResourceDefinitionExtensibilityPoints . OnApplyFilter )
601
+ } , options => options . WithStrictOrdering ( ) ) ;
602
+ }
603
+
412
604
[ Fact ]
413
605
public async Task Sort_from_resource_definition_is_applied ( )
414
606
{
0 commit comments