-
Notifications
You must be signed in to change notification settings - Fork 0
Implement PostgreSQL storage with Entity Framework Core for C# (#248) #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* 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>
There was a problem hiding this 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.
src/csharp/LampControlApi.Tests/Infrastructure/PostgresLampRepositoryTests.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…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>
|
@copilot fix Starting test execution, please wait... |
…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.
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.
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.