Add comprehensive database test coverage and injectable data manipulation service#55
Conversation
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
…class Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
|
@copilot All data should be handled through a layer. For example: DecrementSleep should not edit Point.SleepHours directly, it should go through another layer first, like what you did with Medication Helpers but don't just stop there. |
Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Done! Created
All direct property manipulation has been removed from |
|
…ntNullException.ThrowIfNull Co-authored-by: danielchalmers <7112040+danielchalmers@users.noreply.github.com>
Completed all requested changes:
The service is now injected via |
Adds 82 tests covering database operations, edge cases, and data integrity, plus an injectable DataPointService to harden the database and ensure all data changes go through testable service methods following proper Blazor patterns.
Database Operation Tests (21)
GetOrCreateDayAndAddPoints: creation, retrieval, disabled/deleted categories, medication auto-markingAddCategory: auto-indexing, explicit index preservation, group isolationMoveCategoryUp: index swapping, boundary conditions, empty groupsFixCategoryIndexes: gap removal, deleted category handling, multi-group independenceGetMissingPoints: point generation, medication date logic, random data handlingBackup/Restore Tests (13)
DeleteDbSets: complete cleanup, idempotencyRestoreDbSets: data restoration, relationship preservation, property retentionReplaceDbSets: atomic delete-and-restore transactionsCreateBackup: snapshot accuracy, relationship inclusionData Integrity Tests (17)
DataPointService - Injectable Data Manipulation Layer
Created an injectable
DataPointServicethat follows proper Blazor dependency injection patterns. All data manipulation goes through this service instead of direct property modifications in UI components.Service Registration
CommonServices@inject DataPointService DataPointService@using JournalApp.Datato_Imports.razorfor cleaner component codeOperations (31 tests total)
DecrementSleep()/IncrementSleep()with min/max bounds (0-24 hours)SetMood()for mood emoji assignmentsGetScaleIndex()/SetScaleIndex()with null handling (0 = no rating)HandleMedicationTakenChanged()for dose reset logicAll methods include:
ArgumentNullException.ThrowIfNullvalidationTest Status
140 total tests (133 passed, 7 skipped due to SQLite constraint differences). No security vulnerabilities detected.
Benefits
ArgumentNullException.ThrowIfNullOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.