You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new in-memory SQLite detection in PrepareDbAsync only checks SqliteConnection.DataSource for "" or ":memory:", which will not match shared-cache in-memory connection strings like Data Source=JobScraperTest;Mode=Memory;Cache=Shared. This may incorrectly call EnsureDbDirectoryExists for an in-memory DB and potentially create unexpected directories or fail on startup. Consider detecting Mode=Memory via SqliteConnectionStringBuilder instead of relying on DataSource.
publicstaticasyncTaskPrepareDbAsync(thisIServiceProviderservices){usingvarscope=services.CreateScope();vardbContext=scope.ServiceProvider.GetRequiredService<JobsDbContext>();if(dbContext.Database.GetDbConnection()is not SqliteConnection{DataSource:"" or ":memory:"})EnsureDbDirectoryExists(dbContext);awaitdbContext.Database.MigrateAsync();
DbContext.Companies.Find(companyName) assumes companyName is the primary key and non-null. If Company is keyed by something else (e.g., Id) or if companyName is null, this can fail or silently behave incorrectly, leading to duplicate companies or runtime exceptions. Prefer querying by the actual key (or by Name via SingleOrDefault) and make companyName non-nullable if it’s required.
The test writes output.pdf into the project directory. This can pollute the working tree, cause flaky failures in parallel runs, or fail in read-only CI environments. Prefer writing to a temp directory (e.g., Path.GetTempPath() / ITestOutputHelper attachments) and/or ensure cleanup after the test.
The current in-memory detection is incorrect for SQLite connection strings using Mode=Memory;Cache=Shared because DataSource won’t be :memory:. This can cause EnsureDbDirectoryExists to run for an in-memory database and create unexpected files/directories. Parse the SQLite connection string and check SqliteOpenMode.Memory instead.
-if (dbContext.Database.GetDbConnection() is not SqliteConnection { DataSource: "" or ":memory:" })+if (dbContext.Database.GetDbConnection() is SqliteConnection sqliteConn)+{+ var csb = new SqliteConnectionStringBuilder(sqliteConn.ConnectionString);+ var isInMemory = csb.Mode == SqliteOpenMode.Memory || csb.DataSource is "" or ":memory:";+ if (!isInMemory)+ EnsureDbDirectoryExists(dbContext);+}+else+{
EnsureDbDirectoryExists(dbContext);
+}
Suggestion importance[1-10]: 7
__
Why: The current check only treats DataSource == "" or ":memory:" as in-memory, but SQLite in-memory via Mode=Memory;Cache=Shared typically has a non-:memory:DataSource, so EnsureDbDirectoryExists(dbContext) may run unnecessarily. Parsing the connection string via SqliteConnectionStringBuilder makes the in-memory detection correct and avoids unintended filesystem side effects.
Medium
Fix company lookup and nulls
DbSet.Find(companyName) will only work if Company is keyed by Name; otherwise it can throw or always return null, causing duplicates and flaky tests. Also, companyName is nullable and can propagate into EF lookups and required fields. Normalize companyName to a non-null value and query by the Name column.
Why: Using DbSet.Find(companyName) is only correct if companyName is the primary key; otherwise it will always return null (or error on null), potentially creating duplicate Company rows and making tests flaky. Normalizing companyName to non-null and querying by c.Name aligns the lookup with the intended semantics.
Medium
Dispose shared SQLite connection
AddTestPersistence opens a keep-alive SQLite connection, but it is currently not stored/disposed, which can leak connections and keep resources open across the test run. Keep the returned connection in WebApiTestFactory and dispose it when the factory is disposed. This prevents file locks/resource exhaustion in longer runs.
Why: AddTestPersistence opens a long-lived SQLite connection to keep the in-memory DB alive, and not disposing it can leak resources across the test run. Holding that connection on WebApiTestFactory and disposing it in Dispose(bool) is a reasonable fix to prevent lingering connections/file locks.
Low
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.