AngleSharp.Diffing is a .NET library for comparing AngleSharp control nodes and test nodes to identify differences between HTML DOM trees. This library targets .NET Standard 2.0 and provides a fluent API for HTML comparison and diffing.
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
- Install .NET 8.0+ SDK (already available in GitHub Actions environments)
- Mono is NOT required for standard development (only for legacy Cake build system)
Execute these commands in order from the repository root:
cd src
dotnet restore # ~11 seconds - restores NuGet packages
dotnet build # ~15 seconds - compiles library and tests
dotnet test # ~5 seconds - runs 521 tests. NEVER CANCEL.CRITICAL TIMING EXPECTATIONS:
dotnet restore: 11 seconds - NEVER CANCEL. Set timeout to 60+ seconds minimum.dotnet build: 15 seconds - NEVER CANCEL. Set timeout to 60+ seconds minimum.dotnet test: 5 seconds - runs 521 tests. NEVER CANCEL. Set timeout to 30+ seconds minimum.- Complete clean rebuild: ~20 seconds - NEVER CANCEL. Set timeout to 60+ seconds minimum.
PRIMARY METHOD (Recommended): Use dotnet CLI commands as shown above.
LEGACY METHOD (Not Recommended): The repository includes Cake build scripts (build.sh/build.ps1) but they require Mono and may fail. Only use if specifically needed:
# Install Mono first (if needed)
sudo apt-get update && sudo apt-get install -y mono-complete
./build.sh # May fail - use dotnet commands insteadcd src
dotnet build --configuration Release # ~15 seconds
dotnet pack --configuration Release # ~8 seconds - creates NuGet packagesPackage Output: Creates .nupkg and .snupkg files in src/AngleSharp.Diffing/bin/Release/
ALWAYS validate changes by creating and running a test program to exercise the library:
using AngleSharp.Diffing;
// Test basic HTML diffing functionality
var control = @"<p attr=""foo"">hello <em>world</em></p>";
var test = @"<p attr=""bar"">hello <strong>world</strong></p>";
var diffs = DiffBuilder
.Compare(control)
.WithTest(test)
.Build()
.ToList();
Console.WriteLine($"Found {diffs.Count} differences:");
foreach (var diff in diffs)
{
Console.WriteLine($"- {diff.GetType().Name}: {diff.Result} {diff.Target}");
}- Code Analysis: Project has strict analysis rules enabled (
EnforceCodeStyleInBuild=true) - EditorConfig: Follow the existing
.editorconfigsettings (4-space indentation, CRLF line endings) - Nullable References: Enabled - handle null values appropriately
- Build Warnings: Zero warnings expected - treat warnings as errors for critical types
- Test Framework: xUnit with Shouldly assertions
- Test Count: 521 tests covering core diffing functionality
- Test Runtime: ~5 seconds total
- Test Files Location:
src/AngleSharp.Diffing.Tests/
src/
├── AngleSharp.Diffing/ # Main library project
│ ├── Core/ # Core diffing engine and interfaces
│ ├── Extensions/ # Extension methods
│ ├── Strategies/ # Diffing strategy implementations
│ └── DiffBuilder.cs # Main fluent API entry point
├── AngleSharp.Diffing.Tests/ # Test project
│ ├── Core/ # Core functionality tests
│ └── Strategies/ # Strategy-specific tests
└── AngleSharp.Diffing.sln # Solution file
DiffBuilder: Main entry point with fluent API (DiffBuilder.Compare(control).WithTest(test).Build())IDiff: Base interface for all difference typesHtmlDifferenceEngine: Core comparison engine- Diff Types:
AttrDiff,NodeDiff,MissingNodeDiff,UnexpectedNodeDiff, etc.
- AngleSharp 1.1.2: Core HTML parsing library
- AngleSharp.Css 1.0.0-beta.144: CSS support
- Target Framework: .NET Standard 2.0 (library), .NET 8.0 (tests)
- Always build and test first to establish baseline:
dotnet build && dotnet test - Make your changes to source files in
src/AngleSharp.Diffing/ - Immediately test after changes:
dotnet build && dotnet test - Manual validation: Create a test program to exercise your changes
- Pre-commit validation: Ensure no build warnings or test failures
- Test filtering:
dotnet test --filter "TestMethodName"to run specific tests - Verbose builds:
dotnet build --verbosity normalto see detailed output - Key test files:
DiffBuilderTest.csshows basic API usage patterns
- GitHub Actions: Runs on both Linux and Windows
- Zero warnings policy: Build must complete without warnings
- All tests must pass: 521/521 tests required
- Code formatting: Enforced via EditorConfig and analyzers
var control = "<p>Expected content</p>";
var test = "<p>Actual content</p>";
var diffs = DiffBuilder
.Compare(control)
.WithTest(test)
.Build();var diffs = DiffBuilder
.Compare(control)
.WithTest(test)
.WithOptions(options => {
// Configure diffing strategies
})
.Build();foreach (var diff in diffs)
{
switch (diff.Result)
{
case DiffResult.Different:
case DiffResult.Missing:
case DiffResult.Unexpected:
// Handle different types of differences
break;
}
}- Build failures: Ensure you're in the
src/directory - Cake build failures: Use
dotnetcommands instead ofbuild.sh/build.ps1 - Test failures: Check for environment-specific issues or recent changes
- Package restore issues: Clear NuGet caches with
dotnet nuget locals all --clear
# Clean and rebuild everything
cd src
dotnet clean
rm -rf */bin */obj
dotnet restore
dotnet build
dotnet test- Development builds: ~15 seconds
- Test execution: ~5 seconds for full suite
- Package creation: ~8 seconds
- CI builds: Allow 60+ seconds timeout minimum for each step
CRITICAL: NEVER CANCEL builds or tests that appear slow. Wait at least 60 seconds for builds and 30 seconds for tests before considering alternatives.