@@ -264,7 +264,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
264264 }
265265
266266 [ Fact ]
267- public async Task Accepts_meta_in_post_resource_request_with_relationship ( )
267+ public async Task Accepts_meta_in_post_resource_request_with_to_one_relationship ( )
268268 {
269269 // Arrange
270270 var store = _testContext . Factory . Services . GetRequiredService < RequestDocumentStore > ( ) ;
@@ -333,6 +333,96 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
333333 } ) ;
334334 }
335335
336+ [ Fact ]
337+ public async Task Accepts_meta_in_post_resource_request_with_to_many_relationship ( )
338+ {
339+ // Arrange
340+ var store = _testContext . Factory . Services . GetRequiredService < RequestDocumentStore > ( ) ;
341+
342+ var documentMeta = _fakers . DocumentMeta . Generate ( ) ;
343+ var resourceMeta = _fakers . ResourceMeta . Generate ( ) ;
344+ var identifierMeta1 = _fakers . RelationshipIdentifierMeta . Generate ( ) ;
345+ var identifierMeta2 = _fakers . RelationshipIdentifierMeta . Generate ( ) ;
346+
347+ string newFamilyName = _fakers . ProductFamily . GenerateOne ( ) . Name ;
348+ SupportTicket existingTicket1 = _fakers . SupportTicket . GenerateOne ( ) ;
349+ SupportTicket existingTicket2 = _fakers . SupportTicket . GenerateOne ( ) ;
350+
351+ await _testContext . RunOnDatabaseAsync ( async dbContext =>
352+ {
353+ dbContext . SupportTickets . AddRange ( existingTicket1 , existingTicket2 ) ;
354+ await dbContext . SaveChangesAsync ( ) ;
355+ } ) ;
356+
357+ var requestBody = new
358+ {
359+ data = new
360+ {
361+ type = "productFamilies" ,
362+ attributes = new
363+ {
364+ name = newFamilyName
365+ } ,
366+ relationships = new
367+ {
368+ tickets = new
369+ {
370+ data = new [ ]
371+ {
372+ new
373+ {
374+ type = "supportTickets" ,
375+ id = existingTicket1 . StringId ,
376+ description = existingTicket1 . Description ,
377+ meta = identifierMeta1
378+ } ,
379+ new
380+ {
381+ type = "supportTickets" ,
382+ id = existingTicket2 . StringId ,
383+ description = existingTicket2 . Description ,
384+ meta = identifierMeta2
385+ }
386+ } ,
387+ meta = resourceMeta
388+ }
389+ }
390+ } ,
391+ meta = documentMeta
392+ } ;
393+
394+ const string route = "/productFamilies" ;
395+
396+ // Act
397+ ( HttpResponseMessage httpResponse , _ ) = await _testContext . ExecutePostAsync < Document > ( route , requestBody ) ;
398+
399+ // Assert
400+ httpResponse . ShouldHaveStatusCode ( HttpStatusCode . Created ) ;
401+
402+ store . Document . Should ( ) . NotBeNull ( ) ;
403+
404+ // document meta explicit validation
405+ store . Document . Meta . Should ( ) . HaveCount ( documentMeta . Count ) ;
406+ store . Document . Meta . Should ( ) . ContainKey ( "requestId" ) . WhoseValue . With ( value =>
407+ {
408+ JsonElement element = value . Should ( ) . BeOfType < JsonElement > ( ) . Subject ;
409+ element . GetString ( ) . Should ( ) . Be ( ( string ) documentMeta [ "requestId" ] ) ;
410+ } ) ;
411+
412+ store . Document . Data . SingleValue . Should ( ) . NotBeNull ( ) ;
413+ store . Document . Data . SingleValue . Relationships . Should ( ) . ContainKey ( "tickets" ) . WhoseValue . With ( value =>
414+ {
415+ value . Should ( ) . NotBeNull ( ) ;
416+ value . Data . ManyValue . Should ( ) . HaveCount ( 2 ) ;
417+
418+ value . Data . ManyValue [ 0 ] . Type . Should ( ) . Be ( "supportTickets" ) ;
419+ value . Data . ManyValue [ 0 ] . Id . Should ( ) . Be ( existingTicket1 . StringId ) ;
420+
421+ value . Data . ManyValue [ 1 ] . Type . Should ( ) . Be ( "supportTickets" ) ;
422+ value . Data . ManyValue [ 1 ] . Id . Should ( ) . Be ( existingTicket2 . StringId ) ;
423+ } ) ;
424+ }
425+
336426 [ Fact ]
337427 public async Task Accepts_meta_in_delete_relationship_request ( )
338428 {
0 commit comments