Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Build and test ASP.NET Core projects targeting .NET 8 on Linux.
# https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core

# Trigger pipeline on commits to master and pull requests (equivalent to GitHub Actions 'on: [push, pull_request]')
# Pipeline triggers:
# - Runs on pushes to master (production deployments)
# - Runs on all pull requests to master (validation before merge)
# - Does NOT run on pushes to development branches (cost optimization)
# Development branches (refactor/*, fix/*, feat/*, etc.) are validated only when a PR is opened
trigger:
- master
Comment thread
nanotaboada marked this conversation as resolved.
- feature/*

pr:
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Configurations
/// </summary>
public class AuthorizeCheckOperationFilter : IOperationFilter
{
/// <summary>
/// Applies the Bearer security requirement to Swagger operations with [Authorize] attributes.
/// </summary>
/// <param name="operation">The OpenAPI operation to modify.</param>
/// <param name="context">The operation filter context containing method metadata.</param>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// Check if [Authorize] is applied at the method or class level
Expand Down
9 changes: 9 additions & 0 deletions src/Dotnet.Samples.AspNetCore.WebApi/Utilities/PlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@

namespace Dotnet.Samples.AspNetCore.WebApi.Utilities;

/// <summary>
/// Provides static player data for database seeding and testing.
/// Single source of truth for all player definitions.
/// </summary>
public static class PlayerData
{
/// <summary>
/// Returns the starting 11 players without IDs (for EF Core auto-increment).
/// Used for database migrations and seeding.
/// </summary>
/// <returns>List of 11 Player entities representing the starting lineup.</returns>
public static List<Player> MakeStarting11()
{
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Tests.Utilities
/// </summary>
public static class DatabaseFakes
{
/// <summary>
/// Creates an in-memory SQLite connection and DbContext options for testing.
/// The connection remains open for the lifetime of the test.
/// </summary>
/// <returns>A tuple containing the SQLite connection and DbContext options.</returns>
public static (DbConnection, DbContextOptions<PlayerDbContext>) CreateSqliteConnection()
{
var dbConnection = new SqliteConnection("Filename=:memory:");
Expand All @@ -26,13 +31,23 @@ public static (DbConnection, DbContextOptions<PlayerDbContext>) CreateSqliteConn
return (dbConnection, dbContextOptions);
}

/// <summary>
/// Creates a PlayerDbContext instance with the specified options.
/// </summary>
/// <param name="dbContextOptions">The DbContext options to use.</param>
/// <returns>A new PlayerDbContext instance.</returns>
public static PlayerDbContext CreateDbContext(
DbContextOptions<PlayerDbContext> dbContextOptions
)
{
return new PlayerDbContext(dbContextOptions);
}

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

/// <summary>
/// Seeds the test database with the starting 11 players.
/// Extension method for PlayerDbContext.
/// </summary>
/// <param name="context">The PlayerDbContext instance.</param>
public static void Seed(this PlayerDbContext context)
{
context.Players.AddRange(PlayerFakes.MakeStarting11());
Expand Down
Loading