Skip to content

Commit 0d34a18

Browse files
committed
docs: add XML documentation to utilities and configurations
1 parent ac62c9a commit 0d34a18

6 files changed

Lines changed: 93 additions & 0 deletions

File tree

src/Dotnet.Samples.AspNetCore.WebApi/Configurations/AuthorizeCheckOperationFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Configurations
1010
/// </summary>
1111
public class AuthorizeCheckOperationFilter : IOperationFilter
1212
{
13+
/// <summary>
14+
/// Applies the Bearer security requirement to Swagger operations with [Authorize] attributes.
15+
/// </summary>
16+
/// <param name="operation">The OpenAPI operation to modify.</param>
17+
/// <param name="context">The operation filter context containing method metadata.</param>
1318
public void Apply(OpenApiOperation operation, OperationFilterContext context)
1419
{
1520
// Check if [Authorize] is applied at the method or class level

src/Dotnet.Samples.AspNetCore.WebApi/Utilities/PlayerData.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
namespace Dotnet.Samples.AspNetCore.WebApi.Utilities;
66

7+
/// <summary>
8+
/// Provides static player data for database seeding and testing.
9+
/// Single source of truth for all player definitions.
10+
/// </summary>
711
public static class PlayerData
812
{
13+
/// <summary>
14+
/// Returns the starting 11 players without IDs (for EF Core auto-increment).
15+
/// Used for database migrations and seeding.
16+
/// </summary>
17+
/// <returns>List of 11 Player entities representing the starting lineup.</returns>
918
public static List<Player> MakeStarting11()
1019
{
1120
return

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/DatabaseFakes.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Utilities
1414
/// </summary>
1515
public static class DatabaseFakes
1616
{
17+
/// <summary>
18+
/// Creates an in-memory SQLite connection and DbContext options for testing.
19+
/// The connection remains open for the lifetime of the test.
20+
/// </summary>
21+
/// <returns>A tuple containing the SQLite connection and DbContext options.</returns>
1722
public static (DbConnection, DbContextOptions<PlayerDbContext>) CreateSqliteConnection()
1823
{
1924
var dbConnection = new SqliteConnection("Filename=:memory:");
@@ -26,13 +31,23 @@ public static (DbConnection, DbContextOptions<PlayerDbContext>) CreateSqliteConn
2631
return (dbConnection, dbContextOptions);
2732
}
2833

34+
/// <summary>
35+
/// Creates a PlayerDbContext instance with the specified options.
36+
/// </summary>
37+
/// <param name="dbContextOptions">The DbContext options to use.</param>
38+
/// <returns>A new PlayerDbContext instance.</returns>
2939
public static PlayerDbContext CreateDbContext(
3040
DbContextOptions<PlayerDbContext> dbContextOptions
3141
)
3242
{
3343
return new PlayerDbContext(dbContextOptions);
3444
}
3545

46+
/// <summary>
47+
/// Creates the database schema for the test database.
48+
/// Extension method for PlayerDbContext.
49+
/// </summary>
50+
/// <param name="context">The PlayerDbContext instance.</param>
3651
public static void CreateTable(this PlayerDbContext context)
3752
{
3853
using var cmd = context.Database.GetDbConnection().CreateCommand();
@@ -46,6 +61,11 @@ CREATE TABLE players (
4661
cmd.ExecuteNonQuery();
4762
}
4863

64+
/// <summary>
65+
/// Seeds the test database with the starting 11 players.
66+
/// Extension method for PlayerDbContext.
67+
/// </summary>
68+
/// <param name="context">The PlayerDbContext instance.</param>
4969
public static void Seed(this PlayerDbContext context)
5070
{
5171
context.Players.AddRange(PlayerFakes.MakeStarting11());

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerFakes.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public static Player MakeNew()
6868
* Create
6969
* ---------------------------------------------------------------------- */
7070

71+
/// <summary>
72+
/// Creates a PlayerRequestModel for testing create operations.
73+
/// Uses data from a substitute player (Leandro Paredes).
74+
/// </summary>
7175
public static PlayerRequestModel MakeRequestModelForCreate()
7276
{
7377
var player = MakeNew();
@@ -85,6 +89,10 @@ public static PlayerRequestModel MakeRequestModelForCreate()
8589
};
8690
}
8791

92+
/// <summary>
93+
/// Creates a PlayerResponseModel for testing create operation responses.
94+
/// Uses data from a substitute player (Leandro Paredes).
95+
/// </summary>
8896
public static PlayerResponseModel MakeResponseModelForCreate()
8997
{
9098
var player = MakeNew();
@@ -106,6 +114,11 @@ public static PlayerResponseModel MakeResponseModelForCreate()
106114
* Retrieve
107115
* ---------------------------------------------------------------------- */
108116

117+
/// <summary>
118+
/// Creates a PlayerRequestModel for testing retrieve operations.
119+
/// Uses data from the starting 11 based on the specified squad number.
120+
/// </summary>
121+
/// <param name="squadNumber">The squad number of the player to retrieve.</param>
109122
public static PlayerRequestModel MakeRequestModelForRetrieve(int squadNumber)
110123
{
111124
var player =
@@ -127,6 +140,11 @@ public static PlayerRequestModel MakeRequestModelForRetrieve(int squadNumber)
127140
};
128141
}
129142

143+
/// <summary>
144+
/// Creates a PlayerResponseModel for testing retrieve operation responses.
145+
/// Uses data from the starting 11 based on the specified squad number.
146+
/// </summary>
147+
/// <param name="squadNumber">The squad number of the player to retrieve.</param>
130148
public static PlayerResponseModel MakeResponseModelForRetrieve(int squadNumber)
131149
{
132150
var player =
@@ -148,6 +166,10 @@ public static PlayerResponseModel MakeResponseModelForRetrieve(int squadNumber)
148166
};
149167
}
150168

169+
/// <summary>
170+
/// Creates a list of PlayerResponseModel for testing retrieve all operations.
171+
/// Uses all players from the starting 11.
172+
/// </summary>
151173
public static List<PlayerResponseModel> MakeResponseModelsForRetrieve() =>
152174
[
153175
.. PlayerData
@@ -173,11 +195,21 @@ .. PlayerData
173195
* Update
174196
* ---------------------------------------------------------------------- */
175197

198+
/// <summary>
199+
/// Creates a PlayerRequestModel for testing update operations.
200+
/// Delegates to MakeRequestModelForRetrieve.
201+
/// </summary>
202+
/// <param name="squadNumber">The squad number of the player to update.</param>
176203
public static PlayerRequestModel MakeRequestModelForUpdate(int squadNumber)
177204
{
178205
return MakeRequestModelForRetrieve(squadNumber);
179206
}
180207

208+
/// <summary>
209+
/// Creates a PlayerResponseModel for testing update operation responses.
210+
/// Delegates to MakeResponseModelForRetrieve.
211+
/// </summary>
212+
/// <param name="squadNumber">The squad number of the player to update.</param>
181213
public static PlayerResponseModel MakeResponseModelForUpdate(int squadNumber)
182214
{
183215
return MakeResponseModelForRetrieve(squadNumber);

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerMocks.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Utilities
2222
/// </summary>
2323
public static class PlayerMocks
2424
{
25+
/// <summary>
26+
/// Initializes mocks for PlayerController dependencies.
27+
/// </summary>
28+
/// <returns>A tuple containing mocked service, logger, and validator.</returns>
2529
public static (
2630
Mock<IPlayerService> service,
2731
Mock<ILogger<PlayerController>> logger,
@@ -35,6 +39,10 @@ Mock<IValidator<PlayerRequestModel>> validator
3539
return (service, logger, validator);
3640
}
3741

42+
/// <summary>
43+
/// Creates a mock IUrlHelper configured to return any string for Action calls.
44+
/// </summary>
45+
/// <returns>A configured Mock of IUrlHelper.</returns>
3846
public static Mock<IUrlHelper> SetupUrlHelperMock()
3947
{
4048
var mock = new Mock<IUrlHelper>();
@@ -43,6 +51,12 @@ public static Mock<IUrlHelper> SetupUrlHelperMock()
4351
return mock;
4452
}
4553

54+
/// <summary>
55+
/// Initializes mocks for PlayerService dependencies.
56+
/// </summary>
57+
/// <param name="cacheValue">Optional cache value to return from memory cache.</param>
58+
/// <param name="environmentName">The environment name (defaults to "Development").</param>
59+
/// <returns>A tuple containing mocked repository, logger, cache, mapper, and environment.</returns>
4660
public static (
4761
Mock<IPlayerRepository> repository,
4862
Mock<ILogger<PlayerService>> logger,
@@ -60,6 +74,12 @@ Mock<IHostEnvironment> environment
6074
return (repository, logger, memoryCache, mapper, environment);
6175
}
6276

77+
/// <summary>
78+
/// Creates a mock IMemoryCache with configurable behavior.
79+
/// First TryGetValue call returns false, subsequent calls return true with the specified value.
80+
/// </summary>
81+
/// <param name="value">The value to return from cache after the first call.</param>
82+
/// <returns>A configured Mock of IMemoryCache.</returns>
6383
public static Mock<IMemoryCache> SetupMemoryCacheMock(object? value)
6484
{
6585
var cachedValue = false;

test/Dotnet.Samples.AspNetCore.WebApi.Tests/Utilities/PlayerStubs.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Utilities
1414
/// </summary>
1515
public static class PlayerStubs
1616
{
17+
/// <summary>
18+
/// Creates a ModelStateDictionary with a single validation error.
19+
/// Used for testing validation failure scenarios.
20+
/// </summary>
21+
/// <param name="key">The property name or key for the error.</param>
22+
/// <param name="errorMessage">The error message.</param>
23+
/// <returns>A ModelStateDictionary containing the specified error.</returns>
1724
public static ModelStateDictionary CreateModelError(string key, string errorMessage)
1825
{
1926
var modelStateDictionary = new ModelStateDictionary();

0 commit comments

Comments
 (0)