Skip to content

Commit 8980a05

Browse files
authored
Merge pull request #352 from nanotaboada/refactor/issue-210-consolidate-player-data-ssot
refactor: consolidate player data into single source of truth (#210)
2 parents a766e4e + 0d34a18 commit 8980a05

7 files changed

Lines changed: 153 additions & 186 deletions

File tree

azure-pipelines.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
# Build and test ASP.NET Core projects targeting .NET 8 on Linux.
33
# https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core
44

5-
# Trigger pipeline on commits to master and pull requests (equivalent to GitHub Actions 'on: [push, pull_request]')
5+
# Pipeline triggers:
6+
# - Runs on pushes to master (production deployments)
7+
# - Runs on all pull requests to master (validation before merge)
8+
# - Does NOT run on pushes to development branches (cost optimization)
9+
# Development branches (refactor/*, fix/*, feat/*, etc.) are validated only when a PR is opened
610
trigger:
711
- master
8-
- feature/*
912

1013
pr:
1114
- master

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());

0 commit comments

Comments
 (0)