Skip to content

Commit 45dc467

Browse files
Pushed updates addressing review comments.
1 parent 845d4ad commit 45dc467

4 files changed

Lines changed: 49 additions & 77 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using JsonApiDotNetCore.Serialization.Objects;
2+
using JsonApiDotNetCore.Serialization.Request.Adapters;
3+
4+
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;
5+
6+
public sealed class CapturingDocumentAdapter : IDocumentAdapter
7+
{
8+
private readonly IDocumentAdapter _innerAdapter;
9+
private readonly RequestDocumentStore _requestDocumentStore;
10+
11+
public CapturingDocumentAdapter(IDocumentAdapter innerAdapter, RequestDocumentStore requestDocumentStore)
12+
{
13+
ArgumentNullException.ThrowIfNull(innerAdapter);
14+
ArgumentNullException.ThrowIfNull(requestDocumentStore);
15+
16+
_innerAdapter = innerAdapter;
17+
_requestDocumentStore = requestDocumentStore;
18+
}
19+
20+
public object? Convert(Document document)
21+
{
22+
_requestDocumentStore.Document = document;
23+
return _innerAdapter.Convert(document);
24+
}
25+
}
26+
27+

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/OperationsRequestMetaTests.cs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public async Task Accepts_meta_in_update_resource_operation_with_ToOne_relations
5050
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
5151

5252
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
53+
string newTicketDescription = _fakers.SupportTicket.GenerateOne().Description;
5354
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
5455

5556
await _testContext.RunOnDatabaseAsync(async dbContext =>
@@ -72,7 +73,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
7273
id = existingTicket.StringId,
7374
attributes = new
7475
{
75-
description = existingTicket.Description
76+
description = newTicketDescription
7677
},
7778
relationships = new
7879
{
@@ -211,8 +212,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
211212

212213
store.Document.Meta.Should().BeEquivalentToJson(documentMeta);
213214

214-
store.Document.Operations.Should().HaveCount(1);
215-
216215
store.Document.Operations.Should().ContainSingle().Which.With(operation =>
217216
{
218217
operation.Should().NotBeNull();
@@ -433,14 +432,14 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
433432
}
434433

435434
[Fact]
436-
public async Task Accepts_meta_in_update_operation_ToOne_relationship()
435+
public async Task Accepts_meta_in_update_ToOne_relationship_operation()
437436
{
438437
// Arrange
439438
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
440439

441440
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
442441
Dictionary<string, object?> operationMeta = _fakers.OperationMeta.GenerateOne();
443-
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
442+
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
444443

445444
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
446445
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -469,7 +468,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
469468
{
470469
type = "productFamilies",
471470
id = existingFamily.StringId,
472-
meta = relationshipMeta
471+
meta = identifierMeta
473472
},
474473
meta = operationMeta
475474
}
@@ -501,7 +500,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
501500
}
502501

503502
[Fact]
504-
public async Task Accepts_meta_in_update_operation_ToMany_relationship()
503+
public async Task Accepts_meta_in_update_ToMany_relationship_operation()
505504
{
506505
// Arrange
507506
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
@@ -583,7 +582,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
583582
}
584583

585584
[Fact]
586-
public async Task Accepts_meta_in_add_operation_ToMany_relationship()
585+
public async Task Accepts_meta_in_add_ToMany_relationship_operation()
587586
{
588587
// Arrange
589588
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
@@ -676,15 +675,11 @@ public async Task Accepts_meta_in_remove_operation_from_ToMany_relationship()
676675
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
677676

678677
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
679-
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
680-
existingTicket1.ProductFamily = existingFamily;
681-
SupportTicket existingTicket2 = _fakers.SupportTicket.GenerateOne();
682-
existingTicket2.ProductFamily = existingFamily;
678+
existingFamily.Tickets = _fakers.SupportTicket.GenerateList(2);
683679

684680
await _testContext.RunOnDatabaseAsync(async dbContext =>
685681
{
686682
dbContext.ProductFamilies.Add(existingFamily);
687-
dbContext.SupportTickets.AddRange(existingTicket1, existingTicket2);
688683
await dbContext.SaveChangesAsync();
689684
});
690685

@@ -706,13 +701,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
706701
new
707702
{
708703
type = "supportTickets",
709-
id = existingTicket1.StringId,
704+
id = existingFamily.Tickets[0].StringId,
710705
meta = identifierMeta1
711706
},
712707
new
713708
{
714709
type = "supportTickets",
715-
id = existingTicket2.StringId,
710+
id = existingFamily.Tickets[1].StringId,
716711
meta = identifierMeta2
717712
}
718713
},
@@ -790,8 +785,6 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
790785
// Assert
791786
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent);
792787

793-
responseDocument.Should().BeEmpty();
794-
795788
store.Document.Should().NotBeNull();
796789

797790
store.Document.Meta.Should().BeEquivalentToJson(documentMeta);
@@ -803,30 +796,4 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
803796
operation.Meta.Should().BeEquivalentToJson(operationMeta);
804797
});
805798
}
806-
807-
private sealed class CapturingDocumentAdapter : IDocumentAdapter
808-
{
809-
private readonly IDocumentAdapter _innerAdapter;
810-
private readonly RequestDocumentStore _requestDocumentStore;
811-
812-
public CapturingDocumentAdapter(IDocumentAdapter innerAdapter, RequestDocumentStore requestDocumentStore)
813-
{
814-
ArgumentNullException.ThrowIfNull(innerAdapter);
815-
ArgumentNullException.ThrowIfNull(requestDocumentStore);
816-
817-
_innerAdapter = innerAdapter;
818-
_requestDocumentStore = requestDocumentStore;
819-
}
820-
821-
public object? Convert(Document document)
822-
{
823-
_requestDocumentStore.Document = document;
824-
return _innerAdapter.Convert(document);
825-
}
826-
}
827-
828-
private sealed class RequestDocumentStore
829-
{
830-
public Document? Document { get; set; }
831-
}
832799
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using JsonApiDotNetCore.Serialization.Objects;
2+
3+
namespace JsonApiDotNetCoreTests.IntegrationTests.Meta;
4+
5+
public sealed class RequestDocumentStore
6+
{
7+
public Document? Document { get; set; }
8+
}

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/RequestMetaTests.cs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ public async Task Accepts_meta_in_add_to_ToMany_relationship_request()
485485
Dictionary<string, object?> identifierMeta1 = _fakers.IdentifierMeta.GenerateOne();
486486
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
487487

488+
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
488489
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
489490
SupportTicket existingTicket2 = _fakers.SupportTicket.GenerateOne();
490-
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
491491

492492
await _testContext.RunOnDatabaseAsync(async dbContext =>
493493
{
@@ -546,15 +546,11 @@ public async Task Accepts_meta_in_remove_from_ToMany_relationship_request()
546546
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
547547

548548
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
549-
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
550-
existingTicket1.ProductFamily = existingFamily;
551-
SupportTicket existingTicket2 = _fakers.SupportTicket.GenerateOne();
552-
existingTicket2.ProductFamily = existingFamily;
549+
existingFamily.Tickets = _fakers.SupportTicket.GenerateList(2);
553550

554551
await _testContext.RunOnDatabaseAsync(async dbContext =>
555552
{
556553
dbContext.ProductFamilies.Add(existingFamily);
557-
dbContext.SupportTickets.AddRange(existingTicket1, existingTicket2);
558554
await dbContext.SaveChangesAsync();
559555
});
560556

@@ -565,13 +561,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
565561
new
566562
{
567563
type = "supportTickets",
568-
id = existingTicket2.StringId,
564+
id = existingFamily.Tickets[0].StringId,
569565
meta = identifierMeta1
570566
},
571567
new
572568
{
573569
type = "supportTickets",
574-
id = existingTicket2.StringId,
570+
id = existingFamily.Tickets[1].StringId,
575571
meta = identifierMeta2
576572
}
577573
},
@@ -595,30 +591,4 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
595591
store.Document.Data.ManyValue[0].Meta.Should().BeEquivalentToJson(identifierMeta1);
596592
store.Document.Data.ManyValue[1].Meta.Should().BeEquivalentToJson(identifierMeta2);
597593
}
598-
599-
private sealed class CapturingDocumentAdapter : IDocumentAdapter
600-
{
601-
private readonly IDocumentAdapter _innerAdapter;
602-
private readonly RequestDocumentStore _requestDocumentStore;
603-
604-
public CapturingDocumentAdapter(IDocumentAdapter innerAdapter, RequestDocumentStore requestDocumentStore)
605-
{
606-
ArgumentNullException.ThrowIfNull(innerAdapter);
607-
ArgumentNullException.ThrowIfNull(requestDocumentStore);
608-
609-
_innerAdapter = innerAdapter;
610-
_requestDocumentStore = requestDocumentStore;
611-
}
612-
613-
public object? Convert(Document document)
614-
{
615-
_requestDocumentStore.Document = document;
616-
return _innerAdapter.Convert(document);
617-
}
618-
}
619-
620-
private sealed class RequestDocumentStore
621-
{
622-
public Document? Document { get; set; }
623-
}
624594
}

0 commit comments

Comments
 (0)