This test project contains unit tests for Screenbox.Core focusing on SQL database services, JSON serialization, legacy JSON-to-SQL data migration, and Native AOT compatibility.
-
SQL Database Services (
DatabaseService):- Verification of SQLite table schema initialization (
library_folders,media_records,playback_progress,playlists,playlist_items). - Schema drift detection and automatic table rebuilds.
- Library cache saving and loading operations.
- Playlist management (
SavePlaylistAsync,LoadPlaylistAsync,ListPlaylistsAsync,DeletePlaylistAsync). - Playback progress tracking state management.
- Verification of SQLite table schema initialization (
-
Legacy JSON Migration to SQL:
- Verification of importing legacy JSON playlist files (e.g.
Playlists/*.json) containingPlaylistRecordDtoandRawMediaRecordDtointo SQLite database tables (playlistsandplaylist_items). - Automated post-migration cleanup of legacy
.jsonfiles and temporary migration artifacts.
- Verification of importing legacy JSON playlist files (e.g.
-
JSON Serialization & System.Text.Json Source Generation:
- Direct testing of
CoreJsonContext(JsonSerializerContextsource generator). - Guaranteeing reflection-free serialization/deserialization for DTOs (
PlaylistRecordDto,RawMediaRecordDto).
- Direct testing of
-
⚡ Native AOT Compatibility:
- The test project is configured with Roslyn AOT & trimming analyzers:
<IsAotCompatible>true</IsAotCompatible><EnableTrimAnalyzer>true</EnableTrimAnalyzer><EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
- The test project is configured with Roslyn AOT & trimming analyzers:
-
✨ Modern C# Features:
- Target Framework:
net10.0-windows10.0.26100.0. - C# 12+ features used throughout test files:
- File-scoped namespaces
- Primary constructors
- Collection expressions (
[ item1, item2 ]) - Raw string literals (
"""...""") - Pattern matching and slice operators
- Target Framework:
The test project relies strictly on the x64, ARM64, or x86 build architectures to align with the Screenbox UWP environments. Standard AnyCPU configuration is intentionally overridden.
"C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\MSBuild.exe" Screenbox.Core.Tests\Screenbox.Core.Tests.csproj /p:Configuration=Release /p:Platform=x64 /restoreUsing dotnet run:
dotnet run --project Screenbox.Core.Tests/Screenbox.Core.Tests.csprojOr by running the built test executable directly:
Screenbox.Core.Tests\bin\x64\Release\net10.0-windows10.0.26100.0\Screenbox.Core.Tests.exe- Source Generated JSON: When adding new DTOs or JSON contracts in
Screenbox.Core, ensure you add[JsonSerializable(typeof(YourDto))]toCoreJsonContextinScreenbox.Core/Models/Serialization/CoreJsonContext.cs. Never use reflection-basedJsonSerializer.Deserialize<T>(json)without passingJsonSerializerContextorJsonTypeInfo<T>generated metadata. - Isolating WinRT for JIT: Unit tests execute on generic
.NET, lacking UWP runtime elements likeApplicationData.Current. The core library explicitly isolates WinRT calls into unique methods using[MethodImpl(MethodImplOptions.NoInlining)]. This securely bypasses JITPlatformNotSupportedExceptioncrashes since test execution won't trigger the compiler to load UWP references. - Database Initialization for Testing: Instead of relying on WinRT to resolve database folders, unit tests instantiate
DatabaseServiceand set the public propertyDbFolderPath = TestDirectoryPathto force SQLite interactions into isolated, volatile temporary directories.