Repository navigation
Description
Problem
AppSettings reads and writes through the static Preferences.Default. That static throws
NotImplementedInReferenceAssemblyException on the plain net10.0 TFM the unit tests build
against, so every code path that reaches AppSettings.Load(), Save(), Clear() or
SyncFromViewer() is untestable.
The concrete casualty today is SettingsPageModel.LoadAsync's authenticated happy path:
PopulateFromUser ends in AppSettings.SyncFromViewer(user) → Save() → Preferences.Default.Set.
A test asserting "successful load → PageState.Content" would actually be asserting on the catch
block, so it was deliberately left unwritten in #62 with a comment saying so. MyAnimePageModel's
list load has the same limit.
Why the obvious fix is bigger than it looks
AppSettings is static for a real reason. Media.DisplayTitle and MediaListEntry.ScoreDisplay
consult it, and those are plain deserialized POCOs that DI never constructs. A full IAppSettings
injection means either threading it through every model, or moving display formatting out of the
models into formatters. Worth doing eventually; not worth blocking test coverage on.
Proposal
Keep the static surface. Make only the storage injectable:
// AppSettings.Storage.cs
internal static IPreferences Storage { get; set; } = Preferences.Default;MauiProgram assigns the real one at startup; tests assign a dictionary-backed fake.
Two things that make this safer than a static-mutable seam usually is:
Preferences.Defaultreturns an implementation off-device and only throws onGet/Set
(verified), so it is safe as a field initializer — no lazy-init dance, and production behaviour is
unchanged if nobody assigns it.- Cross-test pollution is already handled:
AppSettingsCollection(added in Extract AniSprinkles.Core class library to unblock PageModel/Services unit tests #62) serialises every
test class that writes to theAppSettingsstatics.
It is a service locator, which is not lovely — but AppSettings is already a process-wide static, so
this does not make the design worse, and the full injection stays available later.
Acceptance
AppSettings.Load/Save/Clear/SyncFromViewerare exercisable fromtests/AniSprinkles.UnitTests/.SettingsPageModel.LoadAsync's authenticated path has a test assertingPageState.Contentand the
populated profile fields, and the "exception with cached data stays Content" case from Add unit test suite for PageModels, Services, and Converters #52.- A round-trip test: set values,
Save(),Load()into a fresh state, assert they come back. - No production behaviour change — the default storage is still
Preferences.Default.
Related
- Add unit test suite for PageModels, Services, and Converters #52 — this is the named blocker for the last of its Phase 1.
- The original design discussion is in Add unit test suite for PageModels, Services, and Converters #52's first comment (options A/B/C); this is a narrower
version of option A.
Activity
zhollis21 commentedon Aug 23, 2026
Verification notes (checked against
origin/main@ 57d4506):AppSettings.Storage.csreaches the staticPreferences.Defaultat 11 callsites across
Load(:12,18,24,26),Save(:34-37) andClear(:58-60,62).Preferences.Defaultclaim checks out empirically. Ran a throwawaynet10.0consoleagainst
Microsoft.Maui.Essentials10.0.60: theDefaultgetter returnsMicrosoft.Maui.Storage.PreferencesImplementationwithout throwing, andGet,SetandRemoveeach throw
NotImplementedInReferenceAssemblyException. So it is safe as a field initializer —no lazy-init dance needed.
src/AniSprinkles.Core/Properties/AssemblyInfo.cs:7already hasInternalsVisibleTo("AniSprinkles.UnitTests"), so aninternal staticseam is reachable from thetest project without widening the public surface.
SettingsPageModelalready takes an injectedIPreferences(SettingsPageModel.cs:195),registered at
MauiProgram.cs:94— so the DI half of the wiring exists and the seam only needsan assignment at startup.
tests/AniSprinkles.UnitTests/SettingsPageModelTests.cs:11-17(the XML comment explaining theabsent happy-path test) and
AGENTS.md:60("Known gap ... open in Add unit test suite for PageModels, Services, and Converters #52").AppSettingsCollection(tests/AniSprinkles.UnitTests/AppSettingsCollection.cs) exists and isalready applied to
SettingsPageModelTests, so the serialisation the body relies on is in place.Adult-content commit timing, token redaction, AppSettings seam, and C…
Adult-content commit timing, token redaction, AppSettings seam, and C…