Skip to content

Conversation

@davideme
Copy link
Owner

@davideme davideme commented Jan 2, 2026

  • Initial plan

  • Implement C# PostgreSQL storage support with Entity Framework Core

  • Fix C# tests by using environment-based PostgreSQL configuration

  • Add PostgreSQL implementation guide for remaining languages

  • Address code review feedback: simplify repository pattern and fix paths

  • Add comprehensive implementation summary and complete C# PostgreSQL support

  • Remove PostgreSQL implementation documentation

Deleted POSTGRESQL_IMPLEMENTATION_GUIDE.md and POSTGRESQL_IMPLEMENTATION_SUMMARY.md, which contained implementation steps, patterns, and summary reports for PostgreSQL support across multiple language stacks.

  • Add unit tests for database and repository logic

Added Microsoft.EntityFrameworkCore.InMemory as a test dependency. Introduced unit tests for LampControlDbContext, LampDbEntity, and PostgresLampRepository to verify entity behavior, soft delete logic, CRUD operations, and error handling using the in-memory database provider.

  • Address PR review feedback: simplify config, clarify health checks, use DB trigger for timestamps, apply actual schema in tests

* Initial plan

* Implement C# PostgreSQL storage support with Entity Framework Core

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Fix C# tests by using environment-based PostgreSQL configuration

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Add PostgreSQL implementation guide for remaining languages

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Address code review feedback: simplify repository pattern and fix paths

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Add comprehensive implementation summary and complete C# PostgreSQL support

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Remove PostgreSQL implementation documentation

Deleted POSTGRESQL_IMPLEMENTATION_GUIDE.md and POSTGRESQL_IMPLEMENTATION_SUMMARY.md, which contained implementation steps, patterns, and summary reports for PostgreSQL support across multiple language stacks.

* Add unit tests for database and repository logic

Added Microsoft.EntityFrameworkCore.InMemory as a test dependency. Introduced unit tests for LampControlDbContext, LampDbEntity, and PostgresLampRepository to verify entity behavior, soft delete logic, CRUD operations, and error handling using the in-memory database provider.

* Address PR review feedback: simplify config, clarify health checks, use DB trigger for timestamps, apply actual schema in tests

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
Co-authored-by: Davide Mendolia <davide@gokarumi.com>
Copilot AI review requested due to automatic review settings January 2, 2026 15:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements PostgreSQL storage support for the C# Lamp Control API using Entity Framework Core, providing a production-ready database backend as an alternative to the default in-memory storage.

Key Changes:

  • Adds Entity Framework Core with Npgsql provider for PostgreSQL database support
  • Implements database context, entities, and repository with soft delete functionality
  • Includes comprehensive unit tests using in-memory provider and integration tests with Testcontainers

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/csharp/README.md Adds extensive PostgreSQL setup documentation including Docker setup, configuration options, schema management, health checks, and troubleshooting guidance
src/csharp/LampControlApi/packages.lock.json Adds EF Core, Npgsql, health checks, design tools, and Testcontainers dependencies with their transitive packages
src/csharp/LampControlApi/appsettings.Development.example.json Provides example configuration file with commented-out PostgreSQL connection string template
src/csharp/LampControlApi/Tests/Infrastructure/PostgresLampRepositoryUnitTests.cs Implements unit tests for repository error handling, null checks, and edge cases using in-memory database
src/csharp/LampControlApi/Tests/Infrastructure/PostgresLampRepositoryTests.cs Implements integration tests using Testcontainers to verify CRUD operations against real PostgreSQL database
src/csharp/LampControlApi/Tests/Infrastructure/LampDbEntityTests.cs Tests database entity record behavior including immutability, soft delete support, and value equality
src/csharp/LampControlApi/Tests/Infrastructure/LampControlDbContextTests.cs Tests EF Core context configuration, soft delete query filters, and entity tracking behavior
src/csharp/LampControlApi/Services/PostgresLampRepository.cs Implements ILampRepository using EF Core with soft delete support, timestamp management, and proper logging
src/csharp/LampControlApi/Program.cs Adds conditional database configuration based on connection string presence, registers appropriate repository implementation, and configures health checks
src/csharp/LampControlApi/LampControlApi.csproj Adds package references for Npgsql.EntityFrameworkCore.PostgreSQL, EF Core design tools, health checks, Testcontainers, and in-memory provider
src/csharp/LampControlApi/Infrastructure/Database/LampDbEntity.cs Defines database entity as sealed record with init properties for EF Core compatibility and immutability
src/csharp/LampControlApi/Infrastructure/Database/LampControlDbContext.cs Configures EF Core context with table/column mappings, indexes, and global query filter for soft deletes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Jan 2, 2026

@davideme I've opened a new pull request, #251, to work on those changes. Once the pull request is ready, I'll request review from you.

…ostgreSQL tests (#251)

* Initial plan

* Replace brittle path construction with robust FindRepositoryRoot method

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

* Fix XML documentation issues in test files

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
@davideme
Copy link
Owner Author

davideme commented Jan 2, 2026

@copilot fix
Run dotnet test --configuration Release --logger trx --results-directory ./TestResults
Determining projects to restore...
All projects are up-to-date for restore.
LampControlApi -> /home/runner/work/lamp-control-api-reference/lamp-control-api-reference/src/csharp/LampControlApi/bin/Release/net8.0/LampControlApi.dll
[coverlet] _mapping file name: 'CoverletSourceRootsMapping_LampControlApi'
Test run for /home/runner/work/lamp-control-api-reference/lamp-control-api-reference/src/csharp/LampControlApi/bin/Release/net8.0/LampControlApi.dll (.NETCoreApp,Version=v8.0)
VSTest version 17.11.1 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Failed CreateAsync_ShouldPersistLamp [10 s]
Error Message:
Assert.IsTrue failed.
Stack Trace:
at LampControlApi.Tests.Infrastructure.PostgresLampRepositoryTests.CreateAsync_ShouldPersistLamp() in /home/runner/work/lamp-control-api-reference/lamp-control-api-reference/src/csharp/LampControlApi/Tests/Infrastructure/PostgresLampRepositoryTests.cs:line 100

Copy link
Contributor

Copilot AI commented Jan 2, 2026

@davideme I've opened a new pull request, #252, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 9 commits January 2, 2026 17:25
…eGenerated configuration (#252)

* Initial plan

* Fix EF Core timestamp generation by using set accessors and ValueGenerated configuration

Co-authored-by: davideme <858090+davideme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: davideme <858090+davideme@users.noreply.github.com>
Added Docker-in-Docker feature to the devcontainer configuration. Updated Microsoft.AspNetCore.Mvc.Testing NuGet package to version 8.0.11 and refreshed transitive dependencies in the lock file for improved compatibility and security.
Bump several Microsoft.AspNetCore and Microsoft.Extensions package versions to latest 8.0.x releases in packages.lock.json for LampControlApi. This ensures compatibility with recent bug fixes and improvements from upstream dependencies.
Upgraded Moq, Npgsql.EntityFrameworkCore.PostgreSQL, Microsoft.EntityFrameworkCore.Design, Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore, and Microsoft.EntityFrameworkCore.InMemory to latest versions. Added BouncyCastle.Cryptography as a new package dependency.
Renamed and relocated all test files from 'src/csharp/LampControlApi/Tests' to 'src/csharp/LampControlApi.Tests' for better project organization. Added a new test project file 'LampControlApi.Tests.csproj' with necessary dependencies and project references. Updated the solution file to include the new test project.
Updated the GitHub Actions workflow to operate from the src/csharp directory and explicitly target both LampControlApi and LampControlApi.Tests projects for restore, build, format, test, and security scan steps. Improved dependency caching, artifact paths, and reporting to handle both main and test projects, enabling more robust CI for multi-project solutions.
Renamed and relocated LampControlApi.sln to src/csharp/LampControlApi.sln. Updated project paths within the solution file to reflect the new location.
Refactored the GitHub Actions workflow to use more generic dotnet CLI commands, reducing repetition and improving maintainability. Updated dependency caching to include both main and test project lock files. Consolidated package listing and security scanning steps to operate on the solution as a whole rather than individual projects.
Updated all 'dotnet restore' commands in the csharp-ci GitHub Actions workflow to use the '--locked-mode' flag. This ensures that dependency resolution strictly follows the lock file, improving build reproducibility and reliability.
@davideme davideme merged commit d2f1aaf into main Jan 5, 2026
6 checks passed
@davideme davideme deleted the feature/csharp-postgresql-storage branch January 5, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants