Skip to content

Commit 539382b

Browse files
Pushed updates addressing review comments.
1 parent fdac076 commit 539382b

2 files changed

Lines changed: 40 additions & 73 deletions

File tree

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/MetaFakers.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,30 @@ internal sealed class MetaFakers
3737
.CustomInstantiator(faker => new Dictionary<string, object?>
3838
{
3939
["source"] = faker.PickRandom("ui", "api", "import"),
40-
["confidence"] = faker.Random.Double(0.1)
40+
["confidence"] = faker.Random.Double(0.1),
41+
["details"] = null
4142
}));
4243

43-
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyRelationshipIdentifierMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
44+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyIdentifierMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
4445
.MakeDeterministic()
4546
.CustomInstantiator(faker => new Dictionary<string, object?>
4647
{
4748
["index"] = faker.IndexFaker,
4849
["optionalNote"] = faker.Lorem.Word()
4950
}));
5051

52+
private readonly Lazy<Faker<Dictionary<string, object?>>> _lazyOperationMetaFaker = new(() => new Faker<Dictionary<string, object?>>()
53+
.MakeDeterministic()
54+
.CustomInstantiator(faker => new Dictionary<string, object?>
55+
{
56+
["version"] = faker.Random.Int(1, 10)
57+
}));
58+
5159
public Faker<ProductFamily> ProductFamily => _lazyProductFamilyFaker.Value;
5260
public Faker<SupportTicket> SupportTicket => _lazySupportTicketFaker.Value;
5361
public Faker<Dictionary<string, object?>> DocumentMeta => _lazyDocumentMetaFaker.Value;
5462
public Faker<Dictionary<string, object?>> ResourceMeta => _lazyResourceMetaFaker.Value;
5563
public Faker<Dictionary<string, object?>> RelationshipMeta => _lazyRelationshipMetaFaker.Value;
56-
public Faker<Dictionary<string, object?>> RelationshipIdentifierMeta => _lazyRelationshipIdentifierMetaFaker.Value;
64+
public Faker<Dictionary<string, object?>> IdentifierMeta => _lazyIdentifierMetaFaker.Value;
65+
public Faker<Dictionary<string, object?>> OperationMeta => _lazyOperationMetaFaker.Value;
5766
}

test/JsonApiDotNetCoreTests/IntegrationTests/Meta/RequestMetaTests.cs

Lines changed: 28 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ public RequestMetaTests(IntegrationTestContext<TestableStartup<MetaDbContext>, M
3838
}
3939

4040
[Fact]
41-
public async Task Accepts_meta_in_update_resource_request_with_to_one_relationship()
41+
public async Task Accepts_meta_in_update_resource_request_with_ToOne_relationship()
4242
{
4343
// Arrange
4444
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
4545

4646
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
4747
Dictionary<string, object?> resourceMeta = _fakers.ResourceMeta.GenerateOne();
4848
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
49-
Dictionary<string, object?> identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
49+
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
5050

5151
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
5252
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
5353

54-
await _testContext.RunOnDatabaseAsync(async dbContex =>
54+
await _testContext.RunOnDatabaseAsync(async dbContext =>
5555
{
56-
dbContex.ProductFamilies.Add(existingFamily);
57-
dbContex.SupportTickets.Add(existingTicket);
58-
await dbContex.SaveChangesAsync();
56+
dbContext.ProductFamilies.Add(existingFamily);
57+
dbContext.SupportTickets.Add(existingTicket);
58+
await dbContext.SaveChangesAsync();
5959
});
6060

6161
var requestBody = new
@@ -92,7 +92,6 @@ await _testContext.RunOnDatabaseAsync(async dbContex =>
9292

9393
store.Document.Should().NotBeNull();
9494

95-
store.Document.Meta.Should().HaveCount(documentMeta.Count);
9695
store.Document.Meta.Should().BeEquivalentToJson(documentMeta);
9796

9897
store.Document.Data.Should().NotBeNull();
@@ -110,16 +109,16 @@ await _testContext.RunOnDatabaseAsync(async dbContex =>
110109
}
111110

112111
[Fact]
113-
public async Task Accepts_meta_in_update_resource_request_with_to_many_relationship()
112+
public async Task Accepts_meta_in_update_resource_request_with_ToMany_relationship()
114113
{
115114
// Arrange
116115
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
117116

118117
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
119118
Dictionary<string, object?> resourceMeta = _fakers.ResourceMeta.GenerateOne();
120119
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
121-
Dictionary<string, object?> identifierMeta1 = _fakers.RelationshipIdentifierMeta.GenerateOne();
122-
Dictionary<string, object?> identifierMeta2 = _fakers.RelationshipIdentifierMeta.GenerateOne();
120+
Dictionary<string, object?> identifierMeta1 = _fakers.IdentifierMeta.GenerateOne();
121+
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
123122

124123
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
125124
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
@@ -196,15 +195,15 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
196195
}
197196

198197
[Fact]
199-
public async Task Accepts_meta_in_add_resource_request_with_to_one_relationship()
198+
public async Task Accepts_meta_in_add_resource_request_with_ToOne_relationship()
200199
{
201200
// Arrange
202201
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
203202

204203
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
205204
Dictionary<string, object?> resourceMeta = _fakers.ResourceMeta.GenerateOne();
206205
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
207-
Dictionary<string, object?> identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
206+
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
208207

209208
string newTicketDescription = _fakers.SupportTicket.GenerateOne().Description;
210209
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -272,16 +271,16 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
272271
}
273272

274273
[Fact]
275-
public async Task Accepts_meta_in_add_resource_request_with_to_many_relationship()
274+
public async Task Accepts_meta_in_add_resource_request_with_ToMany_relationship()
276275
{
277276
// Arrange
278277
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
279278

280279
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
281280
Dictionary<string, object?> resourceMeta = _fakers.ResourceMeta.GenerateOne();
282281
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
283-
Dictionary<string, object?> identifierMeta1 = _fakers.RelationshipIdentifierMeta.GenerateOne();
284-
Dictionary<string, object?> identifierMeta2 = _fakers.RelationshipIdentifierMeta.GenerateOne();
282+
Dictionary<string, object?> identifierMeta1 = _fakers.IdentifierMeta.GenerateOne();
283+
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
285284

286285
string newFamilyName = _fakers.ProductFamily.GenerateOne().Name;
287286
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
@@ -361,13 +360,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
361360
}
362361

363362
[Fact]
364-
public async Task Accepts_meta_in_update_to_one_relationship_request()
363+
public async Task Accepts_meta_in_update_ToOne_relationship_request()
365364
{
366365
// Arrange
367366
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
368367

369368
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
370-
Dictionary<string, object?> relationshipMeta = _fakers.RelationshipMeta.GenerateOne();
369+
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
371370

372371
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
373372
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
@@ -385,7 +384,7 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
385384
{
386385
type = "productFamilies",
387386
id = existingFamily.StringId,
388-
meta = relationshipMeta
387+
meta = identifierMeta
389388
},
390389
meta = documentMeta
391390
};
@@ -404,18 +403,18 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
404403

405404
store.Document.Data.SingleValue.Should().NotBeNull();
406405

407-
store.Document.Data.SingleValue.Meta.Should().BeEquivalentToJson(relationshipMeta);
406+
store.Document.Data.SingleValue.Meta.Should().BeEquivalentToJson(identifierMeta);
408407
}
409408

410409
[Fact]
411-
public async Task Accepts_meta_in_update_to_many_relationship_request()
410+
public async Task Accepts_meta_in_update_ToMany_relationship_request()
412411
{
413412
// Arrange
414413
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
415414

416415
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
417-
Dictionary<string, object?> identifierMeta1 = _fakers.RelationshipIdentifierMeta.GenerateOne();
418-
Dictionary<string, object?> identifierMeta2 = _fakers.RelationshipIdentifierMeta.GenerateOne();
416+
Dictionary<string, object?> identifierMeta1 = _fakers.IdentifierMeta.GenerateOne();
417+
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
419418

420419
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
421420
SupportTicket existingTicket2 = _fakers.SupportTicket.GenerateOne();
@@ -424,8 +423,7 @@ public async Task Accepts_meta_in_update_to_many_relationship_request()
424423
await _testContext.RunOnDatabaseAsync(async dbContext =>
425424
{
426425
dbContext.ProductFamilies.Add(existingFamily);
427-
dbContext.SupportTickets.Add(existingTicket1);
428-
dbContext.SupportTickets.Add(existingTicket2);
426+
dbContext.SupportTickets.AddRange(existingTicket1, existingTicket2);
429427
await dbContext.SaveChangesAsync();
430428
});
431429

@@ -469,14 +467,14 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
469467
}
470468

471469
[Fact]
472-
public async Task Accepts_meta_in_add_relationship_request()
470+
public async Task Accepts_meta_in_add_ToMany_relationship_request()
473471
{
474472
// Arrange
475473
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
476474

477475
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
478-
Dictionary<string, object?> identifierMeta1 = _fakers.RelationshipIdentifierMeta.GenerateOne();
479-
Dictionary<string, object?> identifierMeta2 = _fakers.RelationshipIdentifierMeta.GenerateOne();
476+
Dictionary<string, object?> identifierMeta1 = _fakers.IdentifierMeta.GenerateOne();
477+
Dictionary<string, object?> identifierMeta2 = _fakers.IdentifierMeta.GenerateOne();
480478

481479
SupportTicket existingTicket1 = _fakers.SupportTicket.GenerateOne();
482480
SupportTicket existingTicket2 = _fakers.SupportTicket.GenerateOne();
@@ -485,8 +483,7 @@ public async Task Accepts_meta_in_add_relationship_request()
485483
await _testContext.RunOnDatabaseAsync(async dbContext =>
486484
{
487485
dbContext.ProductFamilies.Add(existingFamily);
488-
dbContext.SupportTickets.Add(existingTicket1);
489-
dbContext.SupportTickets.Add(existingTicket2);
486+
dbContext.SupportTickets.AddRange(existingTicket1, existingTicket2);
490487
await dbContext.SaveChangesAsync();
491488
});
492489

@@ -530,52 +527,13 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
530527
}
531528

532529
[Fact]
533-
public async Task Accepts_meta_in_remove_relationship_request()
534-
{
535-
// Arrange
536-
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
537-
538-
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
539-
540-
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
541-
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();
542-
543-
await _testContext.RunOnDatabaseAsync(async dbContext =>
544-
{
545-
existingTicket.ProductFamily = existingFamily;
546-
dbContext.SupportTickets.Add(existingTicket);
547-
await dbContext.SaveChangesAsync();
548-
});
549-
550-
var requestBody = new
551-
{
552-
data = (object?)null,
553-
meta = documentMeta
554-
};
555-
556-
string route = $"/supportTickets/{existingTicket.StringId}/relationships/productFamily";
557-
558-
// Act
559-
(HttpResponseMessage httpResponse, _) = await _testContext.ExecutePatchAsync<Document>(route, requestBody);
560-
561-
// Assert
562-
httpResponse.ShouldHaveStatusCode(HttpStatusCode.NoContent);
563-
564-
store.Document.Should().NotBeNull();
565-
566-
store.Document.Data.SingleValue.Should().BeNull();
567-
568-
store.Document.Meta.Should().BeEquivalentToJson(documentMeta);
569-
}
570-
571-
[Fact]
572-
public async Task Accepts_meta_in_delete_relationship_request_with_identifier_meta()
530+
public async Task Accepts_meta_in_remove_from_ToMany_relationship_request()
573531
{
574532
// Arrange
575533
var store = _testContext.Factory.Services.GetRequiredService<RequestDocumentStore>();
576534

577535
Dictionary<string, object?> documentMeta = _fakers.DocumentMeta.GenerateOne();
578-
Dictionary<string, object?> identifierMeta = _fakers.RelationshipIdentifierMeta.GenerateOne();
536+
Dictionary<string, object?> identifierMeta = _fakers.IdentifierMeta.GenerateOne();
579537

580538
SupportTicket existingTicket = _fakers.SupportTicket.GenerateOne();
581539
ProductFamily existingFamily = _fakers.ProductFamily.GenerateOne();

0 commit comments

Comments
 (0)