- Solution:
PicView.sln/PicView.slnxin thesrc/root. - Target framework:
net11.0(withnet10.0-windows11.0.22621for Win32 project). Language version set topreview. - Platforms:
x64andarm64only — all projects specify<Platforms>x64;arm64</Platforms>. - AOT:
PicView.Coreis configured for Native AOT (PublishAot,Trimming=full,IsAotCompatible). Keep new Core code AOT-compatible (no reflection-heavy patterns). - Directory.Build.props (solution root) sets shared properties:
Nullable=enable,AvaloniaVersion, and version info. - MacOS project has pre-existing build errors on Windows — the test project already excludes its reference. When building the full solution on Windows, MacOS build failures are expected and unrelated to your changes.
cd src
dotnet build PicView.Tests\PicView.Tests.csproj- Framework: xUnit 2.9.3 with
Microsoft.NET.Test.Sdk 18.5.1. - Avalonia UI tests:
Avalonia.Headless.XUnitis available for tests that need the Avalonia rendering pipeline. - Test project:
PicView.Tests/PicView.Tests.csproj— referencesPicView.CoreandPicView.Avalonia. - Global usings (
GlobalUsings.cs):xunit.v3,SettingsManager(static),System.Collections.Generic,System. - InternalsVisibleTo:
PicView.Coreexposes internals toPicView.Tests.
Run all tests:
cd src
dotnet test PicView.Tests\PicView.Tests.csprojRun a specific test by fully qualified name:
dotnet test PicView.Tests\PicView.Tests.csproj --filter "FullyQualifiedName=PicView.Tests.FileFunctionTest.TestTemporaryFiles"Run tests in a specific class:
dotnet test PicView.Tests\PicView.Tests.csproj --filter "FullyQualifiedName~PicView.Tests.Navigation.SharedImageCacheTests"- Create a
.csfile inPicView.Tests/(or a subdirectory for organization, e.g.,Navigation/). - Use file-scoped namespace
PicView.Tests(orPicView.Tests.SubFolder). - No need to import
Xunit— it's inGlobalUsings.cs. - Use
[Fact]for simple tests,[Theory]with[InlineData]for parameterized tests. - If settings are needed, call
SettingsManager.SetDefaults()in the constructor.
Example test:
using PicView.Core.FileHandling;
namespace PicView.Tests;
public class TempFileTests
{
[Fact]
public void TempDirectory_CreateAndDelete_ShouldSucceed()
{
var created = TempFileHelper.CreateTempDirectory();
Assert.True(created);
Assert.True(Directory.Exists(TempFileHelper.TempFilePath));
var path = TempFileHelper.TempFilePath;
TempFileHelper.DeleteTempFiles();
Assert.False(Directory.Exists(path));
}
}- File-scoped namespaces (
namespace X;not block-scoped). - Nullable reference types enabled globally.
- Implicit usings enabled — no need for
using System;etc. - Naming: PascalCase for public members,
_camelCasefor private fields. Test methods useMethodOrScenario_Condition_ExpectedResultpattern. - Async patterns:
async Task/ValueTaskused extensively; avoidasync void. - Reactive extensions: R3 (
ObservableCollections.R3,R3) used for reactive patterns in ViewModels.
| Project | Purpose |
|---|---|
PicView.Core |
Platform-independent core logic (navigation, config, file handling, image models). AOT-compatible. |
PicView.Avalonia |
Shared Avalonia UI layer (views, controls, themes) (view models herein are deprecated). |
PicView.Avalonia.Win32 |
Windows-specific UI and platform services. |
PicView.Avalonia.Linux |
Linux-specific UI and platform services. |
PicView.Avalonia.MacOS |
macOS-specific UI. |
PicView.Core.WindowsNT |
Windows-specific core utilities. |
PicView.Core.Linux |
Linux-specific core utilities. |
PicView.Core.MacOS |
macOS-specific core utilities. |
PicView.Benchmarks |
BenchmarkDotNet performance benchmarks. |
PicView.Tests |
xUnit test project. |