Skip to content

Commit 8c8f950

Browse files
committed
Address PR comments
1 parent 05b4ba5 commit 8c8f950

File tree

7 files changed

+79
-53
lines changed

7 files changed

+79
-53
lines changed

test/OpenApiEndToEndTests/ClientIdGenerationModes/PostTests.cs renamed to test/OpenApiEndToEndTests/ClientIdGenerationModes/ClientIdGenerationModesTests.cs

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
namespace OpenApiEndToEndTests.ClientIdGenerationModes;
1212

13-
public sealed class PostTests : IClassFixture<IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDbContext>, ClientIdGenerationModesDbContext>>
13+
public sealed class ClientIdGenerationModesTests
14+
: IClassFixture<IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDbContext>, ClientIdGenerationModesDbContext>>
1415
{
1516
private readonly IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDbContext>, ClientIdGenerationModesDbContext> _testContext;
1617
private readonly ClientIdGenerationModesFakers _fakers = new();
1718

18-
public PostTests(IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDbContext>, ClientIdGenerationModesDbContext> testContext)
19+
public ClientIdGenerationModesTests(IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDbContext>, ClientIdGenerationModesDbContext> testContext)
1920
{
2021
_testContext = testContext;
2122

@@ -25,7 +26,7 @@ public PostTests(IntegrationTestContext<OpenApiStartup<ClientIdGenerationModesDb
2526
}
2627

2728
[Fact]
28-
public async Task Cannot_create_resource_without_ID_when_mode_is_required()
29+
public async Task Cannot_create_resource_without_ID_when_supplying_ID_is_required()
2930
{
3031
// Arrange
3132
Player player = _fakers.Player.Generate();
@@ -52,7 +53,7 @@ public async Task Cannot_create_resource_without_ID_when_mode_is_required()
5253
}
5354

5455
[Fact]
55-
public async Task Can_create_resource_with_ID_when_mode_is_required()
56+
public async Task Can_create_resource_with_ID_when_supplying_ID_is_required()
5657
{
5758
// Arrange
5859
Player player = _fakers.Player.Generate();
@@ -62,7 +63,7 @@ public async Task Can_create_resource_with_ID_when_mode_is_required()
6263
ClientIdGenerationModesClient apiClient = new(httpClient);
6364

6465
// Act
65-
Func<Task<PlayerPrimaryResponseDocument?>> action = () => ApiResponse.TranslateAsync(() => apiClient.PostPlayerAsync(null, new PlayerPostRequestDocument
66+
PlayerPrimaryResponseDocument? doc = await ApiResponse.TranslateAsync(() => apiClient.PostPlayerAsync(null, new PlayerPostRequestDocument
6667
{
6768
Data = new PlayerDataInPostRequest
6869
{
@@ -75,12 +76,18 @@ public async Task Can_create_resource_with_ID_when_mode_is_required()
7576
}));
7677

7778
// Assert
78-
PlayerPrimaryResponseDocument? doc = (await action.Should().NotThrowAsync()).Subject;
7979
doc.Should().BeNull();
80+
81+
await _testContext.RunOnDatabaseAsync(async dbContext =>
82+
{
83+
Player playerInDatabase = await dbContext.Players.FirstWithIdAsync(player.Id);
84+
85+
playerInDatabase.UserName.Should().Be(player.UserName);
86+
});
8087
}
8188

8289
[Fact]
83-
public async Task Can_create_resource_without_ID_when_mode_is_allowed()
90+
public async Task Can_create_resource_without_ID_when_supplying_ID_is_allowed()
8491
{
8592
// Arrange
8693
Game game = _fakers.Game.Generate();
@@ -89,7 +96,7 @@ public async Task Can_create_resource_without_ID_when_mode_is_allowed()
8996
ClientIdGenerationModesClient apiClient = new(httpClient);
9097

9198
// Act
92-
Func<Task<GamePrimaryResponseDocument?>> action = () => ApiResponse.TranslateAsync(() => apiClient.PostGameAsync(null, new GamePostRequestDocument
99+
GamePrimaryResponseDocument? doc = await ApiResponse.TranslateAsync(() => apiClient.PostGameAsync(null, new GamePostRequestDocument
93100
{
94101
Data = new GameDataInPostRequest
95102
{
@@ -103,12 +110,19 @@ public async Task Can_create_resource_without_ID_when_mode_is_allowed()
103110
}));
104111

105112
// Assert
106-
GamePrimaryResponseDocument? doc = (await action.Should().NotThrowAsync()).Subject;
107113
doc?.Data.Id.Should().NotBeNullOrEmpty();
114+
115+
await _testContext.RunOnDatabaseAsync(async dbContext =>
116+
{
117+
Game gameInDatabase = await dbContext.Games.FirstWithIdAsync(Guid.Parse(doc!.Data.Id));
118+
119+
gameInDatabase.Title.Should().Be(game.Title);
120+
gameInDatabase.PurchasePrice.Should().Be(game.PurchasePrice);
121+
});
108122
}
109123

110124
[Fact]
111-
public async Task Can_create_resource_with_ID_when_mode_is_allowed()
125+
public async Task Can_create_resource_with_ID_when_supplying_ID_is_allowed()
112126
{
113127
// Arrange
114128
Game game = _fakers.Game.Generate();
@@ -118,7 +132,7 @@ public async Task Can_create_resource_with_ID_when_mode_is_allowed()
118132
ClientIdGenerationModesClient apiClient = new(httpClient);
119133

120134
// Act
121-
Func<Task<GamePrimaryResponseDocument?>> action = () => ApiResponse.TranslateAsync(() => apiClient.PostGameAsync(null, new GamePostRequestDocument
135+
GamePrimaryResponseDocument? doc = await ApiResponse.TranslateAsync(() => apiClient.PostGameAsync(null, new GamePostRequestDocument
122136
{
123137
Data = new GameDataInPostRequest
124138
{
@@ -132,12 +146,19 @@ public async Task Can_create_resource_with_ID_when_mode_is_allowed()
132146
}));
133147

134148
// Assert
135-
GamePrimaryResponseDocument? doc = (await action.Should().NotThrowAsync()).Subject;
136149
doc.Should().BeNull();
150+
151+
await _testContext.RunOnDatabaseAsync(async dbContext =>
152+
{
153+
Game gameInDatabase = await dbContext.Games.FirstWithIdAsync(game.Id);
154+
155+
gameInDatabase.Title.Should().Be(game.Title);
156+
gameInDatabase.PurchasePrice.Should().Be(game.PurchasePrice);
157+
});
137158
}
138159

139160
[Fact]
140-
public async Task Can_create_resource_without_ID_when_mode_is_forbidden()
161+
public async Task Can_create_resource_without_ID_when_supplying_ID_is_forbidden()
141162
{
142163
// Arrange
143164
PlayerGroup playerGroup = _fakers.Group.Generate();
@@ -146,20 +167,25 @@ public async Task Can_create_resource_without_ID_when_mode_is_forbidden()
146167
ClientIdGenerationModesClient apiClient = new(httpClient);
147168

148169
// Act
149-
Func<Task<PlayerGroupPrimaryResponseDocument?>> action = () => ApiResponse.TranslateAsync(() => apiClient.PostPlayerGroupAsync(null,
150-
new PlayerGroupPostRequestDocument
170+
PlayerGroupPrimaryResponseDocument? doc = await ApiResponse.TranslateAsync(() => apiClient.PostPlayerGroupAsync(null, new PlayerGroupPostRequestDocument
171+
{
172+
Data = new PlayerGroupDataInPostRequest
151173
{
152-
Data = new PlayerGroupDataInPostRequest
174+
Attributes = new PlayerGroupAttributesInPostRequest
153175
{
154-
Attributes = new PlayerGroupAttributesInPostRequest
155-
{
156-
Name = playerGroup.Name
157-
}
176+
Name = playerGroup.Name
158177
}
159-
}));
178+
}
179+
}));
160180

161181
// Assert
162-
PlayerGroupPrimaryResponseDocument? doc = (await action.Should().NotThrowAsync()).Subject;
163182
doc?.Data.Id.Should().NotBeNullOrEmpty();
183+
184+
await _testContext.RunOnDatabaseAsync(async dbContext =>
185+
{
186+
PlayerGroup playerGroupInDatabase = await dbContext.PlayerGroups.FirstWithIdAsync(long.Parse(doc!.Data.Id));
187+
188+
playerGroupInDatabase.Name.Should().Be(playerGroup.Name);
189+
});
164190
}
165191
}

test/OpenApiEndToEndTests/ClientIdGenerationModes/swagger.g.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,13 +2192,13 @@
21922192
}
21932193
}
21942194
},
2195-
"/players/{id}/groupMemberships": {
2195+
"/players/{id}/memberOf": {
21962196
"get": {
21972197
"tags": [
21982198
"players"
21992199
],
2200-
"summary": "Retrieves the related playerGroups of an individual player's groupMemberships relationship.",
2201-
"operationId": "getPlayerGroupMemberships",
2200+
"summary": "Retrieves the related playerGroups of an individual player's memberOf relationship.",
2201+
"operationId": "getPlayerMemberOf",
22022202
"parameters": [
22032203
{
22042204
"name": "id",
@@ -2289,9 +2289,9 @@
22892289
"tags": [
22902290
"players"
22912291
],
2292-
"summary": "Retrieves the related playerGroups of an individual player's groupMemberships relationship without returning them.",
2292+
"summary": "Retrieves the related playerGroups of an individual player's memberOf relationship without returning them.",
22932293
"description": "Compare the returned ETag HTTP header with an earlier one to determine if the response has changed since it was fetched.",
2294-
"operationId": "headPlayerGroupMemberships",
2294+
"operationId": "headPlayerMemberOf",
22952295
"parameters": [
22962296
{
22972297
"name": "id",
@@ -2366,13 +2366,13 @@
23662366
}
23672367
}
23682368
},
2369-
"/players/{id}/relationships/groupMemberships": {
2369+
"/players/{id}/relationships/memberOf": {
23702370
"get": {
23712371
"tags": [
23722372
"players"
23732373
],
2374-
"summary": "Retrieves the related playerGroup identities of an individual player's groupMemberships relationship.",
2375-
"operationId": "getPlayerGroupMembershipsRelationship",
2374+
"summary": "Retrieves the related playerGroup identities of an individual player's memberOf relationship.",
2375+
"operationId": "getPlayerMemberOfRelationship",
23762376
"parameters": [
23772377
{
23782378
"name": "id",
@@ -2463,9 +2463,9 @@
24632463
"tags": [
24642464
"players"
24652465
],
2466-
"summary": "Retrieves the related playerGroup identities of an individual player's groupMemberships relationship without returning them.",
2466+
"summary": "Retrieves the related playerGroup identities of an individual player's memberOf relationship without returning them.",
24672467
"description": "Compare the returned ETag HTTP header with an earlier one to determine if the response has changed since it was fetched.",
2468-
"operationId": "headPlayerGroupMembershipsRelationship",
2468+
"operationId": "headPlayerMemberOfRelationship",
24692469
"parameters": [
24702470
{
24712471
"name": "id",
@@ -2543,8 +2543,8 @@
25432543
"tags": [
25442544
"players"
25452545
],
2546-
"summary": "Adds existing playerGroups to the groupMemberships relationship of an individual player.",
2547-
"operationId": "postPlayerGroupMembershipsRelationship",
2546+
"summary": "Adds existing playerGroups to the memberOf relationship of an individual player.",
2547+
"operationId": "postPlayerMemberOfRelationship",
25482548
"parameters": [
25492549
{
25502550
"name": "id",
@@ -2557,7 +2557,7 @@
25572557
}
25582558
],
25592559
"requestBody": {
2560-
"description": "The identities of the playerGroups to add to the groupMemberships relationship.",
2560+
"description": "The identities of the playerGroups to add to the memberOf relationship.",
25612561
"content": {
25622562
"application/vnd.api+json": {
25632563
"schema": {
@@ -2610,21 +2610,21 @@
26102610
"tags": [
26112611
"players"
26122612
],
2613-
"summary": "Assigns existing playerGroups to the groupMemberships relationship of an individual player.",
2614-
"operationId": "patchPlayerGroupMembershipsRelationship",
2613+
"summary": "Assigns existing playerGroups to the memberOf relationship of an individual player.",
2614+
"operationId": "patchPlayerMemberOfRelationship",
26152615
"parameters": [
26162616
{
26172617
"name": "id",
26182618
"in": "path",
2619-
"description": "The identifier of the player whose groupMemberships relationship to assign.",
2619+
"description": "The identifier of the player whose memberOf relationship to assign.",
26202620
"required": true,
26212621
"schema": {
26222622
"type": "string"
26232623
}
26242624
}
26252625
],
26262626
"requestBody": {
2627-
"description": "The identities of the playerGroups to assign to the groupMemberships relationship, or an empty array to clear the relationship.",
2627+
"description": "The identities of the playerGroups to assign to the memberOf relationship, or an empty array to clear the relationship.",
26282628
"content": {
26292629
"application/vnd.api+json": {
26302630
"schema": {
@@ -2639,7 +2639,7 @@
26392639
},
26402640
"responses": {
26412641
"204": {
2642-
"description": "The groupMemberships relationship was successfully updated, which did not result in additional changes."
2642+
"description": "The memberOf relationship was successfully updated, which did not result in additional changes."
26432643
},
26442644
"400": {
26452645
"description": "The request body is missing or malformed.",
@@ -2677,8 +2677,8 @@
26772677
"tags": [
26782678
"players"
26792679
],
2680-
"summary": "Removes existing playerGroups from the groupMemberships relationship of an individual player.",
2681-
"operationId": "deletePlayerGroupMembershipsRelationship",
2680+
"summary": "Removes existing playerGroups from the memberOf relationship of an individual player.",
2681+
"operationId": "deletePlayerMemberOfRelationship",
26822682
"parameters": [
26832683
{
26842684
"name": "id",
@@ -2691,7 +2691,7 @@
26912691
}
26922692
],
26932693
"requestBody": {
2694-
"description": "The identities of the playerGroups to remove from the groupMemberships relationship.",
2694+
"description": "The identities of the playerGroups to remove from the memberOf relationship.",
26952695
"content": {
26962696
"application/vnd.api+json": {
26972697
"schema": {
@@ -4436,7 +4436,7 @@
44364436
}
44374437
]
44384438
},
4439-
"groupMemberships": {
4439+
"memberOf": {
44404440
"allOf": [
44414441
{
44424442
"$ref": "#/components/schemas/toManyPlayerGroupInRequest"
@@ -4456,7 +4456,7 @@
44564456
}
44574457
]
44584458
},
4459-
"groupMemberships": {
4459+
"memberOf": {
44604460
"allOf": [
44614461
{
44624462
"$ref": "#/components/schemas/toManyPlayerGroupInRequest"
@@ -4476,7 +4476,7 @@
44764476
}
44774477
]
44784478
},
4479-
"groupMemberships": {
4479+
"memberOf": {
44804480
"allOf": [
44814481
{
44824482
"$ref": "#/components/schemas/toManyPlayerGroupInResponse"

test/OpenApiTests/ClientIdGenerationModes/ClientGeneratedIdDbContext.cs renamed to test/OpenApiTests/ClientIdGenerationModes/ClientIdGenerationModesDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public sealed class ClientIdGenerationModesDbContext(DbContextOptions<ClientIdGe
99
{
1010
public DbSet<Player> Players => Set<Player>();
1111
public DbSet<Game> Games => Set<Game>();
12-
public DbSet<PlayerGroup> Groups => Set<PlayerGroup>();
12+
public DbSet<PlayerGroup> PlayerGroups => Set<PlayerGroup>();
1313
}

test/OpenApiTests/ClientIdGenerationModes/ClientGeneratedIdFakers.cs renamed to test/OpenApiTests/ClientIdGenerationModes/ClientIdGenerationModesFakers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class ClientIdGenerationModesFakers : FakerContainer
1717
private readonly Lazy<Faker<Game>> _lazyGameFaker = new(() => new Faker<Game>()
1818
.UseSeed(GetFakerSeed())
1919
.RuleFor(game => game.Title, faker => faker.Commerce.ProductName())
20-
.RuleFor(game => game.PurchasePrice, faker => decimal.Parse(faker.Commerce.Price())));
20+
.RuleFor(game => game.PurchasePrice, faker => faker.Finance.Amount(1, 80)));
2121

2222
private readonly Lazy<Faker<PlayerGroup>> _lazyGroupFaker = new(() => new Faker<PlayerGroup>()
2323
.UseSeed(GetFakerSeed())

test/OpenApiTests/ClientIdGenerationModes/ClientGeneratedIdTests.cs renamed to test/OpenApiTests/ClientIdGenerationModes/ClientIdGenerationModesTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ClientIdGenerationModesTests(OpenApiTestContext<OpenApiStartup<ClientIdGe
2121
}
2222

2323
[Fact]
24-
public async Task Post_data_should_have_required_id()
24+
public async Task Schema_property_for_ID_is_required_in_post_request()
2525
{
2626
// Act
2727
JsonElement document = await _testContext.GetSwaggerDocumentAsync();
@@ -39,7 +39,7 @@ public async Task Post_data_should_have_required_id()
3939
}
4040

4141
[Fact]
42-
public async Task Post_data_should_have_non_required_id()
42+
public async Task Schema_property_for_ID_is_optional_in_post_request()
4343
{
4444
// Act
4545
JsonElement document = await _testContext.GetSwaggerDocumentAsync();
@@ -57,7 +57,7 @@ public async Task Post_data_should_have_non_required_id()
5757
}
5858

5959
[Fact]
60-
public async Task Post_data_should_not_have_id()
60+
public async Task Schema_property_for_ID_is_omitted_in_post_request()
6161
{
6262
// Act
6363
JsonElement document = await _testContext.GetSwaggerDocumentAsync();

test/OpenApiTests/ClientIdGenerationModes/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ public sealed class Player : Identifiable<Guid>
1616
public List<Game> OwnedGames { get; set; } = [];
1717

1818
[HasMany]
19-
public List<PlayerGroup> GroupMemberships { get; set; } = [];
19+
public List<PlayerGroup> MemberOf { get; set; } = [];
2020
}

test/OpenApiTests/ClientIdGenerationModes/PlayerGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace OpenApiTests.ClientIdGenerationModes;
77

88
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
99
[Resource(ControllerNamespace = "OpenApiTests.ClientIdGenerationModes", ClientIdGeneration = ClientIdGenerationMode.Forbidden)]
10-
public sealed class PlayerGroup : Identifiable<Guid>
10+
public sealed class PlayerGroup : Identifiable<long>
1111
{
1212
[Attr]
1313
public string Name { get; set; } = null!;

0 commit comments

Comments
 (0)