@@ -506,6 +506,80 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
506
506
ValidateMetaData ( relationship . Meta ) ;
507
507
}
508
508
509
+ [ Fact ]
510
+ public async Task Accepts_meta_in_relationship_of_atomic_add_resource_operation ( )
511
+ {
512
+ // Arrange
513
+ var store = _testContext . Factory . Services . GetRequiredService < RequestDocumentStore > ( ) ;
514
+
515
+ SupportTicket existingTicket = _fakers . SupportTicket . GenerateOne ( ) ;
516
+ ProductFamily existingProductFamily = _fakers . ProductFamily . GenerateOne ( ) ;
517
+
518
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
519
+ {
520
+ dbContext . ProductFamilies . Add ( existingProductFamily ) ;
521
+ await dbContext . SaveChangesAsync ( ) ;
522
+ } ) ;
523
+
524
+ var requestBody = new
525
+ {
526
+ atomic__operations = new [ ]
527
+ {
528
+ new
529
+ {
530
+ op = "add" ,
531
+ data = new
532
+ {
533
+ type = "supportTickets" ,
534
+ attributes = new
535
+ {
536
+ description = existingTicket . Description
537
+ } ,
538
+ relationships = new
539
+ {
540
+ productFamily = new
541
+ {
542
+ data = new
543
+ {
544
+ type = "productFamilies" ,
545
+ id = existingProductFamily . StringId
546
+ } ,
547
+ meta = GetExampleMetaData ( )
548
+ }
549
+ }
550
+ }
551
+ }
552
+ }
553
+ } ;
554
+
555
+ string route = "/operations" ;
556
+
557
+ // Act
558
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecutePostAtomicAsync < Document > ( route , requestBody ) ;
559
+
560
+ // Assert
561
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . OK ) ;
562
+
563
+ store . Document . Should ( ) . NotBeNull ( ) ;
564
+ store . Document . Operations . Should ( ) . NotBeNull ( ) ;
565
+ store . Document . Operations . Should ( ) . HaveCount ( 1 ) ;
566
+
567
+ var operation = store . Document . Operations [ 0 ] ;
568
+ operation . Should ( ) . NotBeNull ( ) ;
569
+ operation . Data . Should ( ) . NotBeNull ( ) ;
570
+ operation . Data . SingleValue . Should ( ) . NotBeNull ( ) ;
571
+
572
+ var relationships = operation . Data . SingleValue . Relationships ;
573
+ relationships . Should ( ) . NotBeNull ( ) ;
574
+ relationships . Should ( ) . ContainKey ( "productFamily" ) ;
575
+
576
+ var relationship = relationships [ "productFamily" ] ;
577
+ relationship . Should ( ) . NotBeNull ( ) ;
578
+ relationship . Meta . Should ( ) . NotBeNull ( ) ;
579
+
580
+ ValidateMetaData ( relationship . Meta ) ;
581
+ }
582
+
509
583
[ Fact ]
510
584
public async Task Accepts_meta_in_data_of_atomic_add_resource_operation ( )
511
585
{
@@ -555,6 +629,74 @@ public async Task Accepts_meta_in_data_of_atomic_add_resource_operation()
555
629
ValidateMetaData ( operation . Data . SingleValue . Meta ) ;
556
630
}
557
631
632
+ [ Fact ]
633
+ public async Task Accepts_meta_in_relationship_of_atomic_update_resource_operation ( )
634
+ {
635
+ // Arrange
636
+ var store = _testContext . Factory . Services . GetRequiredService < RequestDocumentStore > ( ) ;
637
+
638
+ SupportTicket existingTicket = _fakers . SupportTicket . GenerateOne ( ) ;
639
+ ProductFamily existingProductFamily = _fakers . ProductFamily . GenerateOne ( ) ;
640
+
641
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
642
+ {
643
+ existingTicket . ProductFamily = existingProductFamily ;
644
+ dbContext . SupportTickets . Add ( existingTicket ) ;
645
+ await dbContext . SaveChangesAsync ( ) ;
646
+ } ) ;
647
+
648
+ var requestBody = new
649
+ {
650
+ atomic__operations = new [ ]
651
+ {
652
+ new
653
+ {
654
+ op = "update" ,
655
+ data = new
656
+ {
657
+ type = "supportTickets" ,
658
+ id = existingTicket . StringId ,
659
+ relationships = new
660
+ {
661
+ productFamily = new
662
+ {
663
+ data = ( object ? ) null
664
+ }
665
+ }
666
+ } ,
667
+ meta = GetExampleMetaData ( )
668
+ }
669
+ }
670
+ } ;
671
+
672
+ string route = "/operations" ;
673
+
674
+ // Act
675
+ ( HttpResponseMessage httpResponse , Document responseDocument ) = await _testContext . ExecutePostAtomicAsync < Document > ( route , requestBody ) ;
676
+
677
+ // Assert
678
+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . NoContent ) ;
679
+
680
+ store . Document . Should ( ) . NotBeNull ( ) ;
681
+ store . Document . Operations . Should ( ) . NotBeNull ( ) ;
682
+ store . Document . Operations . Should ( ) . HaveCount ( 1 ) ;
683
+
684
+ var operation = store . Document . Operations [ 0 ] ;
685
+ operation . Should ( ) . NotBeNull ( ) ;
686
+ operation . Meta . Should ( ) . NotBeNull ( ) ;
687
+
688
+ ValidateMetaData ( operation . Meta ) ;
689
+
690
+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
691
+ {
692
+ var ticketInDatabase = await dbContext . SupportTickets
693
+ . Include ( supportTicket => supportTicket . ProductFamily )
694
+ . FirstAsync ( supportTicket => supportTicket . Id == existingTicket . Id ) ;
695
+
696
+ ticketInDatabase . ProductFamily . Should ( ) . BeNull ( ) ;
697
+ } ) ;
698
+ }
699
+
558
700
private static Object GetExampleMetaData ( )
559
701
{
560
702
return new
0 commit comments