Skip to content

Migrate database tests from SQL Server to SQLite#4820

Merged
rockfordlhotka merged 3 commits intoMarimerLLC:mainfrom
rockfordlhotka:claude/database-tests-ci-x3xdF
Feb 14, 2026
Merged

Migrate database tests from SQL Server to SQLite#4820
rockfordlhotka merged 3 commits intoMarimerLLC:mainfrom
rockfordlhotka:claude/database-tests-ci-x3xdF

Conversation

@rockfordlhotka
Copy link
Member

Summary

This PR migrates the CSLA test suite from using SQL Server (System.Data.SqlClient) to SQLite (Microsoft.Data.Sqlite), enabling tests to run without external database dependencies.

Key Changes

  • Replaced SQL Server with SQLite: Updated all test classes to use SqliteConnection and SqliteCommand instead of SqlConnection and SqlCommand

    • SafeDataReaderTests.cs
    • DataPortalTests.cs
    • DataPortalExceptionTests.cs
    • TransactionalRoot.cs
  • Created SqliteTestDb utility class: New helper class that programmatically creates and manages an in-memory SQLite test database with schema and seed data mirroring the original SQL Server DataPortalTestDatabase

    • Automatically initializes test tables (Table1, Table2, MultiDataTypes) with appropriate data
    • Provides cleanup functionality to remove temporary database files
  • Updated WellKnownValues: Refactored to use the new SqliteTestDb instead of reading from app.config connection strings

    • DataPortalTestDatabase now returns the SQLite connection string from SqliteTestDb
    • Simplified configuration management
  • Updated test infrastructure: Modified Startup.cs to initialize and cleanup the SQLite test database during assembly setup/teardown

  • Simplified test code: Removed verbose try-catch-finally blocks and leveraged C# using statements for resource management

    • Improved code readability and reduced boilerplate
  • Updated assertions: Modified schema validation assertions to use column names instead of ordinal indices for better maintainability

  • Updated exception handling: Changed expected exception types from SqlException to SqliteException

  • Updated CI workflow: Re-enabled test execution in GitHub Actions workflow

  • Project file updates: Replaced System.Data.SqlClient NuGet package reference with Microsoft.Data.Sqlite 6.0.0

Implementation Details

  • SQLite schema uses CHECK constraints instead of SQL Server varchar length restrictions to enforce data validation
  • Test database is created in the system temp directory with a unique GUID to avoid conflicts
  • All database operations use proper resource disposal patterns with using statements
  • The solution maintains backward compatibility with existing test logic while removing external dependencies

https://claude.ai/code/session_0123tC2ciU58UgL8jR2d5PBt

@rockfordlhotka rockfordlhotka requested a review from a team as a code owner February 14, 2026 18:00
Replace SQL Server LocalDB dependency with SQLite so database integration
tests can run in CI where no SQL Server instance is available.

Changes:
- Add SqliteTestDb.cs to create/manage a temporary SQLite database with
  the same schema and seed data as the original LocalDB test database
- Replace Microsoft.Data.SqlClient with Microsoft.Data.Sqlite package
- Simplify WellKnownValues.cs to serve the SQLite connection string
- Initialize/cleanup SQLite database in AssemblyInitialize/Cleanup
- Remove #if DEBUG guards and [TestCategory("SkipOnCIServer")] attributes
  from SafeDataReaderTests, DataPortalTests, and DataPortalExceptionTests
- Update exception message assertions for SQLite CHECK constraint errors
- Remove MDF/LDF file copy references from project file

https://claude.ai/code/session_0123tC2ciU58UgL8jR2d5PBt
@rockfordlhotka rockfordlhotka force-pushed the claude/database-tests-ci-x3xdF branch from d88cb56 to a1d32e0 Compare February 14, 2026 18:26
SQLite's SqliteConnection does not automatically enlist in ambient
System.Transactions.TransactionScope the way SQL Server does. Replace
the [Transactional(TransactionalTypes.TransactionScope)] attribute with
an explicit SQLite transaction so the first INSERT is properly rolled
back when the second INSERT fails the CHECK constraint.

https://claude.ai/code/session_0123tC2ciU58UgL8jR2d5PBt
Microsoft.Data.Sqlite does not support System.Transactions.TransactionScope
(EnlistTransaction throws NotSupportedException). Switch to System.Data.SQLite
which properly enlists in ambient TransactionScope, so the
[Transactional(TransactionalTypes.TransactionScope)] attribute test remains
valid and the rollback behavior is tested end-to-end through CSLA.

https://claude.ai/code/session_0123tC2ciU58UgL8jR2d5PBt
@rockfordlhotka rockfordlhotka merged commit f5855ed into MarimerLLC:main Feb 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants