diff --git a/.docfx/BuildDocfxImage.ps1 b/.docfx/BuildDocfxImage.ps1 index 6628a96..d8beea6 100644 --- a/.docfx/BuildDocfxImage.ps1 +++ b/.docfx/BuildDocfxImage.ps1 @@ -1,4 +1,12 @@ $version = minver -i -t v -v w docfx metadata docfx.json -docker buildx build -t xunit-docfx:$version --platform linux/arm64,linux/amd64 --load -f Dockerfile.docfx . -get-childItem -recurse -path api -include *.yml, .manifest | remove-item +& (Join-Path $PSScriptRoot 'BuildRunActions.ps1') +try { + docker buildx build -t xunit-docfx:$version --platform linux/arm64,linux/amd64 --load -f Dockerfile.docfx . +} +finally { + get-childItem -recurse -path api -include *.yml, .manifest | remove-item + if (Test-Path -LiteralPath (Join-Path $PSScriptRoot 'run-actions')) { + Remove-Item -LiteralPath (Join-Path $PSScriptRoot 'run-actions') -Recurse -Force + } +} diff --git a/.docfx/BuildRunActions.ps1 b/.docfx/BuildRunActions.ps1 new file mode 100644 index 0000000..7a2680b --- /dev/null +++ b/.docfx/BuildRunActions.ps1 @@ -0,0 +1,283 @@ +#requires -Version 7.0 +[CmdletBinding()] +param( + [string] $ManifestPath = (Join-Path $PSScriptRoot 'run-actions.manifest.json'), + [string] $OutputRoot = (Join-Path $PSScriptRoot 'run-actions') +) +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $false +Set-StrictMode -Version Latest + +if (-not (Test-Path -LiteralPath $ManifestPath -PathType Leaf)) { + if ($PSBoundParameters.ContainsKey('ManifestPath')) { + throw "Run-actions manifest not found: $ManifestPath" + } + Write-Host "No run-actions manifest found at $ManifestPath; skipping." + return +} + +$CsrunTestVerificationTemplate = @' +function Assert-CsrunTestOutput([string] $Output) { + $lines = @($Output -split '\r?\n') + $headers = @($lines | Where-Object { $_ -match '^Test run summary: Passed! - .+\)$' }) + if ($headers.Count -ne 1) { throw 'Expected exactly one completed xUnit test summary.' } + $headerIndex = [Array]::IndexOf($lines, $headers[0]) + $summaryLines = @($lines | Select-Object -Skip ($headerIndex + 1) -First 4) + $counts = @{} + foreach ($line in $summaryLines) { + if ($line -match '^\s*(total|failed|succeeded|skipped):\s*(\d+)\s*$') { $counts[$Matches[1]] = [int]$Matches[2] } + } + if ($counts.Count -ne 4) { throw 'The xUnit test summary counts are incomplete or ambiguous.' } + $failed = $counts.failed + $passed = $counts.succeeded + $skipped = $counts.skipped + $total = $counts.total + if ($total -lt 1 -or $passed -lt 1 -or $failed -ne 0 -or $skipped -ne 0 -or $passed -ne $total) { + throw 'Tests must execute at least once, all pass, and none fail or skip.' + } +} +'@ + +function Normalize([string] $Text) { $Text.Replace("`r`n", "`n").TrimEnd("`n", "`r") } +function Quote-Literal([string] $Value) { "'" + $Value.Replace("'", "''") + "'" } + +function Sort-ManifestValue($Value) { + if ($Value -is [System.Collections.IDictionary]) { + $ordered = [ordered]@{} + [string[]] $keys = @($Value.Keys) + [Array]::Sort($keys, [StringComparer]::Ordinal) + foreach ($key in $keys) { $ordered[$key] = Sort-ManifestValue $Value[$key] } + return $ordered + } + if ($Value -is [array]) { return ,@($Value | ForEach-Object { Sort-ManifestValue $_ }) } + return $Value +} + +function New-StandalonePair { + param( + [Parameter(Mandatory)][hashtable] $Manifest, + [Parameter(Mandatory)][string] $Image + ) + $ordered = Sort-ManifestValue $Manifest + $manifestJson = ConvertTo-Json -InputObject $ordered -Depth 100 + $verifyTests = $ordered.mode -eq 'test' + $prefix = "#requires -Version 7.0`n`$ErrorActionPreference = 'Stop'`n`$PSNativeCommandUseErrorActionPreference = `$false`n`$manifest = @'`n" + $manifestJson + "`n'@`n" + $suffix = @' +if ($process.ExitCode -ne 0) { throw "csrun execution failed with exit code $($process.ExitCode). $diagnostics" } +if ($verifyTests) { Assert-CsrunTestOutput $output } +'@ + $engineSetup = @' +# Downloads and executes the latest stable csrun release with your permissions. +# Source and release history: https://github.com/codebeltnet/csrun +$engineDirectory = Join-Path ([IO.Path]::GetTempPath()) ('csrun-' + [guid]::NewGuid().ToString('N')) +$null = New-Item -ItemType Directory -Path $engineDirectory +$enginePath = Join-Path $engineDirectory 'csrun.ps1' +$process = $null +try { + $release = Invoke-RestMethod 'https://api.github.com/repos/codebeltnet/csrun/releases/latest' + $assets = @($release.assets | Where-Object name -CEQ 'csrun.ps1') + if ($assets.Count -ne 1 -or $assets[0].digest -notmatch '^sha256:[0-9a-f]{64}$') { + throw "csrun release $($release.tag_name) must publish one csrun.ps1 asset with a SHA-256 digest." + } + $asset = $assets[0] + Invoke-WebRequest $asset.browser_download_url -OutFile $enginePath + $actualHash = (Get-FileHash -LiteralPath $enginePath -Algorithm SHA256).Hash + if ("sha256:$actualHash" -ne $asset.digest) { throw "csrun asset checksum mismatch: $actualHash" } +'@ + $nativeInvoke = @' +$startInfo = [Diagnostics.ProcessStartInfo]::new('pwsh') +foreach ($argument in @('-NoProfile','-NonInteractive','-File')) { $startInfo.ArgumentList.Add($argument) } +$startInfo.ArgumentList.Add($enginePath) +$startInfo.ArgumentList.Add('-ManifestJson') +$startInfo.ArgumentList.Add($manifest) +$startInfo.RedirectStandardOutput = $true +$startInfo.RedirectStandardError = $true +$startInfo.UseShellExecute = $false +$process = [Diagnostics.Process]::new() +$process.StartInfo = $startInfo +if (-not $process.Start()) { throw 'Could not start csrun.' } +$stdoutTask = $process.StandardOutput.ReadToEndAsync() +$stderrTask = $process.StandardError.ReadToEndAsync() +$process.WaitForExit() +$output = $stdoutTask.GetAwaiter().GetResult() +$diagnostics = $stderrTask.GetAwaiter().GetResult() +Write-Output $output +if ($diagnostics) { [Console]::Error.Write($diagnostics) } +'@ + $dockerInvoke = (@' +$enginePayload = [Convert]::ToBase64String([IO.File]::ReadAllBytes($enginePath)) +$containerInput = $enginePayload + "`n" + $manifest +$command = ' +$ErrorActionPreference = "Stop" +$enginePath = Join-Path ([IO.Path]::GetTempPath()) ("csrun-release-" + [guid]::NewGuid().ToString("N") + ".ps1") +$engineBytes = [Convert]::FromBase64String([Console]::In.ReadLine()) +[IO.File]::WriteAllBytes($enginePath, $engineBytes) +$manifest = [Console]::In.ReadToEnd() +& $enginePath -ManifestJson $manifest +exit $LASTEXITCODE +' +$output = (@($containerInput | & docker run --rm -i --entrypoint pwsh __IMAGE__ -NoProfile -NonInteractive -Command $command) -join [Environment]::NewLine) +$process = [pscustomobject]@{ ExitCode = $LASTEXITCODE } +$diagnostics = '' +Write-Output $output +'@).Replace('__IMAGE__', (Quote-Literal $Image)) + $engineCleanup = @' +} catch { + [Console]::Error.WriteLine("csrun diagnostics retained in: $engineDirectory") + throw +} finally { + $resolvedTemp = [IO.Path]::TrimEndingDirectorySeparator([IO.Path]::GetFullPath([IO.Path]::GetTempPath())) + $resolvedEngineDirectory = [IO.Path]::GetFullPath($engineDirectory) + if ([IO.Path]::GetDirectoryName($resolvedEngineDirectory) -ne $resolvedTemp -or + [IO.Path]::GetFileName($resolvedEngineDirectory) -cnotmatch '^csrun-[a-f0-9]{32}$') { throw 'Unsafe cleanup path.' } + if ($process -and $process.ExitCode -eq 0) { Remove-Item -LiteralPath $resolvedEngineDirectory -Recurse -Force } +} +'@ + $encoding = '$OutputEncoding = [Text.UTF8Encoding]::new($false)' + "`n" + '[Console]::OutputEncoding = $OutputEncoding' + "`n" + $native = "& {`n" + ($prefix + $encoding + '$verifyTests = $' + $verifyTests.ToString().ToLowerInvariant() + "`n" + $CsrunTestVerificationTemplate + "`n" + $engineSetup + "`n" + $nativeInvoke + "`n" + $engineCleanup + "`n" + $suffix).TrimEnd() + "`n}`n" + $docker = "& {`n" + ($prefix + $encoding + '$verifyTests = $' + $verifyTests.ToString().ToLowerInvariant() + "`n" + $CsrunTestVerificationTemplate + "`n" + $engineSetup + "`n" + $dockerInvoke + "`n" + $engineCleanup + "`n" + $suffix).TrimEnd() + "`n}`n" + return @{ native = $native; docker = $docker } +} + +function New-RepositoryPair { + param( + [Parameter(Mandatory)][string] $Repository, + [Parameter(Mandatory)][string] $Commit, + [Parameter(Mandatory)][string] $Project, + [Parameter(Mandatory)][string] $Test, + [Parameter(Mandatory)][string] $Framework, + [Parameter(Mandatory)][string] $Image + ) + if ($Repository -notmatch '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$' -or $Commit -notmatch '^[a-fA-F0-9]{40}$' -or + $Project -notmatch '^[A-Za-z0-9_./-]+\.csproj$' -or $Project.Split('/') -contains '..' -or $Project.StartsWith('/') -or + $Test -notmatch '^[A-Za-z0-9_.+]+$' -or $Framework -notmatch '^net\d+\.\d+$' -or + $Image -notmatch '^mcr\.microsoft\.com/dotnet/sdk:[A-Za-z0-9_.-]+$') { + throw 'Expected a pinned GitHub repository, relative project, exact xUnit method, TFM and official SDK image.' + } + $template = @' +& { +#requires -Version 7.0 + $ErrorActionPreference = 'Stop' + $PSNativeCommandUseErrorActionPreference = $false + # Executes trusted repository build tasks and NuGet packages with your permissions. + # Review the pinned source before running; a container is not a security sandbox. + __PREREQUISITE__ + $work = Join-Path ([IO.Path]::GetTempPath()) ('dx-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) + $null = New-Item -ItemType Directory -Path $work + try { + $commit = '__COMMIT__' + Invoke-WebRequest "https://codeload.github.com/__REPOSITORY__/zip/$commit" -OutFile "$work/source.zip" + Expand-Archive -LiteralPath "$work/source.zip" -DestinationPath "$work/extracted" + Move-Item -LiteralPath "$work/extracted/__ARCHIVE__-$commit" -Destination "$work/repo" + $project = '__PROJECT__' + $test = '__TEST__' + __EXECUTE__ + $code = $LASTEXITCODE + if ($code -ne 0) { throw "Repository test failed with exit code $code. See $work/run.log" } + # Require exactly the original test, executed and passing, with no runner errors. + [xml] $report = Get-Content -LiteralPath "$work/results/result.xml" -Raw + $tests = @($report.SelectNodes('/assemblies/assembly/collection/test')) + $assemblies = @($report.SelectNodes('/assemblies/assembly')) + if ($assemblies.Count -ne 1 -or $assemblies[0].total -ne '1' -or $assemblies[0].passed -ne '1' -or + $assemblies[0].errors -ne '0' -or $tests.Count -ne 1 -or $tests[0].name -cne $test -or $tests[0].result -cne 'Pass') { + throw "Expected exactly one passing $test; inspect $work/results/result.xml" + } + Write-Host "Verified: $test (1 executed, 1 passed)." + } + catch { + # Preserve diagnostics outside the repository even though downloaded source is cleaned. + $diagnostics = "$work-diagnostics" + $null = New-Item -ItemType Directory -Path $diagnostics -Force + foreach ($name in @('run.log', 'results')) { + if (Test-Path -LiteralPath "$work/$name") { Copy-Item -LiteralPath "$work/$name" -Destination $diagnostics -Recurse } + } + Write-Warning "Execution not verified. Diagnostics: $diagnostics" + throw + } + finally { + $resolved = [IO.Path]::GetFullPath($work) + $temp = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('/','\') + [IO.Path]::DirectorySeparatorChar + if (-not $resolved.StartsWith($temp, [StringComparison]::OrdinalIgnoreCase)) { throw 'Unsafe cleanup path.' } + Remove-Item -LiteralPath $resolved -Recurse -Force + } +} +'@ + $native = (@' +Push-Location "$work/repo" + try { + dotnet run --project $project --framework __FRAMEWORK__ -p:SkipSignAssembly=true -- --filter-method $test --report-xunit-xml --report-xunit-xml-filename result.xml --results-directory "$work/results" 2>&1 | Tee-Object -FilePath "$work/run.log" + } + finally { Pop-Location } +'@).Replace('__FRAMEWORK__', $Framework) + $docker = (@' +$dockerUser = @() + if ($IsLinux) { + # Keep bind-mounted build output removable by the host user. + $hostUid = id -u + if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve host UID.' } + $hostGid = id -g + if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve host GID.' } + $dockerUser = @('--user', "${hostUid}:${hostGid}") + } + # Let Docker's init reap orphaned build processes and keep build servers disposable. + docker run --rm --init @dockerUser --env HOME=/tmp --env DOTNET_CLI_HOME=/tmp --env MSBUILDDISABLENODEREUSE=1 --mount "type=bind,source=$work,target=/work" --workdir /work/repo __IMAGE__ dotnet run --disable-build-servers --project $project --framework __FRAMEWORK__ -p:SkipSignAssembly=true -- --filter-method $test --report-xunit-xml --report-xunit-xml-filename result.xml --results-directory /work/results 2>&1 | Tee-Object -FilePath "$work/run.log" +'@).Replace('__FRAMEWORK__', $Framework).Replace('__IMAGE__', $Image) + $template = $template.Replace('__COMMIT__', $Commit).Replace('__REPOSITORY__', $Repository).Replace('__ARCHIVE__', $Repository.Split('/')[1]).Replace('__PROJECT__', $Project).Replace('__TEST__', $Test) + return @{ + native = $template.Replace('__PREREQUISITE__', "`$null = Get-Command dotnet -ErrorAction Stop").Replace('__EXECUTE__', $native) + docker = $template.Replace('__PREREQUISITE__', "`$null = Get-Command docker -ErrorAction Stop`n docker info *> `$null`n if (`$LASTEXITCODE -ne 0) { throw 'Docker daemon unavailable.' }").Replace('__EXECUTE__', $docker) + } +} + +$doc = Get-Content -LiteralPath $ManifestPath -Raw | ConvertFrom-Json -AsHashtable +if ($doc.schemaVersion -ne 1) { throw "Unsupported run-actions manifest schemaVersion: $($doc.schemaVersion)" } +$examples = @($doc.examples) +$utf8NoBom = [Text.UTF8Encoding]::new($false) +$expectedScripts = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) +$written = 0 + +foreach ($example in $examples) { + $id = [string] $example.id + if ($id -cnotmatch '^[a-f0-9]{24}$') { throw "Invalid run-action id: $id" } + $pair = if ($example.strategy -ceq 'repository') { + New-RepositoryPair -Repository $example.repository -Commit $example.commit -Project $example.project -Test $example.test -Framework $example.framework -Image $example.image + } elseif ($example.strategy -ceq 'standalone') { + New-StandalonePair -Manifest $example.manifest -Image $example.image + } else { + throw "Unsupported run-action strategy '$($example.strategy)' for $id" + } + $dir = Join-Path $OutputRoot $id + foreach ($transport in @($example.transports)) { + if ($transport -notin @('native', 'docker')) { throw "Unsupported transport '$transport' for $id" } + $scriptText = Normalize $pair[$transport] + $tokens = $null; $errors = $null + $null = [Management.Automation.Language.Parser]::ParseInput($scriptText, [ref]$tokens, [ref]$errors) + if ($errors.Count) { throw "Materialized $transport script for $id has syntax errors: $errors" } + $path = Join-Path $dir "$transport.ps1" + if (-not (Test-Path -LiteralPath $path) -or [IO.File]::ReadAllText($path) -cne $scriptText) { + $null = [IO.Directory]::CreateDirectory($dir) + [IO.File]::WriteAllText($path, $scriptText, $utf8NoBom) + } + $null = $expectedScripts.Add("$id/$transport.ps1") + $written++ + } +} + +if (Test-Path -LiteralPath $OutputRoot -PathType Container) { + foreach ($exampleDir in @(Get-ChildItem -LiteralPath $OutputRoot -Directory)) { + if ($exampleDir.Name -cnotmatch '^[a-f0-9]{24}$' -or + ($exampleDir.Attributes -band [IO.FileAttributes]::ReparsePoint)) { continue } + foreach ($name in @('native.ps1', 'docker.ps1')) { + if ($expectedScripts.Contains("$($exampleDir.Name)/$name")) { continue } + $stalePath = Join-Path $exampleDir.FullName $name + if (Test-Path -LiteralPath $stalePath -PathType Leaf) { + Remove-Item -LiteralPath $stalePath -Force + } + } + if (-not @(Get-ChildItem -LiteralPath $exampleDir.FullName -Force).Count) { + Remove-Item -LiteralPath $exampleDir.FullName + } + } +} + +Write-Host "Materialized $written run-action script(s) for $($examples.Count) example(s) into $OutputRoot." diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationFixtureExtensions.md index 4fcbc29..f6ffe8a 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IApplicationFixture` has b ```csharp using Codebelt.Extensions.Xunit.Hosting; +using Xunit; namespace HostFixtureTests; @@ -18,4 +19,18 @@ public class HostStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedApplicationFixture(); + Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationHostFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationHostFactory.md index afe7e9f..702cf87 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationHostFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationHostFactory.md @@ -4,9 +4,10 @@ example: - *content --- -The test project references a worker application's entry-point assembly. `ApplicationHostFactory.Create` preserves the compatibility path, including direct use of an application's `CreateHostBuilder` when it is available. `ApplicationTestFactory.Create` uses `ManagedApplicationFixture` by default when the application entry point should own startup; pass an explicit fixture when a shared test context needs to customize its lifecycle. Because this lower-level factory returns the host directly, the caller still owns disposal. +Use `ApplicationHostFactory.Create` when you need a built `IHost` and will own its disposal. This standalone console example uses its own executable as the entry-point assembly to demonstrate the compatibility path. The factory calls `CreateHostBuilder` directly, applies the service registration supplied by the caller, and builds the host. `Main` resolves and prints the configured worker identity. In a test of an existing worker, reference the application project and use its entry-point type as `TEntryPoint`. Use `ApplicationTestFactory.Create` when the application entry point should own startup. ```csharp +using System; using Codebelt.Extensions.Xunit.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -39,8 +40,17 @@ public sealed class WorkerProgram public static void Main(string[] args) { - using var host = CreateHostBuilder(args).Build(); - host.Run(); + var identity = new ApplicationHostFactoryExample().GetTestIdentity(); + if (identity != "Test inventory worker") + { + throw new InvalidOperationException(identity); + } + + Console.WriteLine(identity); } } ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactory.md index 641c4d0..db7fd1b 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactory.md @@ -4,41 +4,28 @@ example: - *content --- -The test project references a worker application whose entry point registers `WorkerIdentity`. `ApplicationTestFactory` uses `ManagedApplicationFixture` by default, runs that application's real host setup, and exposes its services and environment through an owned test context so the test can verify application behavior without recreating `Program` configuration. Pass an explicit `IApplicationFixture` when the test needs a different lifecycle. +Use `ApplicationTestFactory.Create` to test an existing worker application in an owned test context. The default `ManagedApplicationFixture` lets the worker entry point own host startup. The excerpt below belongs to an xUnit test project that references the separate `BootstrapperMinimalWorker` application. It verifies the marker registered by the application, the Development environment, and the availability of `IHostApplicationLifetime`. Pass an explicit `IApplicationFixture` when the test needs a different lifecycle. ```csharp -using Codebelt.Extensions.Xunit.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Xunit; - -namespace WorkerApp.Tests; - -public sealed class ApplicationTestFactoryExample -{ +// docfx-context: test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj +// docfx-source: test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/ApplicationTestFactoryTest.cs [Fact] - public void Create_BootstrapsWorkerApplicationServices() + public void Create_ShouldBootstrapApplication_WhenEntryPointUsesBootstrapperMinimalWorkerProgram() { - using var application = ApplicationTestFactory.Create(); + using var application = ApplicationTestFactory.Create(); - var identity = application.Host.Services.GetRequiredService(); + var marker = application.Host.Services.GetRequiredService(); - Assert.Equal("Inventory worker", identity.Name); - Assert.Equal(Environments.Development, application.Environment.EnvironmentName); + Assert.Equal("Bootstrapper Minimal Worker", marker.Value); + Assert.Equal("Development", application.Environment.EnvironmentName); + Assert.NotNull(application.Host.Services.GetRequiredService()); } -} +``` -public sealed record WorkerIdentity(string Name); + +
View Native Script · View Docker Script

Runs the pinned repository test Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactoryTest.Create_ShouldBootstrapApplication_WhenEntryPointUsesBootstrapperMinimalWorkerProgram.

The scripts run the maintained worker integration test and verify its registered marker and Development environment.

+ -public sealed class WorkerProgram -{ - public static void Main(string[] args) - { - var builder = Host.CreateApplicationBuilder(args); - builder.Services.AddSingleton(new WorkerIdentity("Inventory worker")); +The [maintained worker test](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/ApplicationTestFactoryTest.cs) checks the same service resolution and environment against a worker in its own application project. - using var host = builder.Build(); - host.Run(); - } -} -``` +The [application entry point](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/app/Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorker.App/Program.cs) defines the behavior the test exercises. The [functional test project](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj) references that executable project. diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.BlockingManagedWebHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.BlockingManagedWebHostFixture.md index 42b28db..6f7ade3 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.BlockingManagedWebHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.BlockingManagedWebHostFixture.md @@ -4,28 +4,33 @@ example: - *content --- -The following example uses `BlockingManagedWebHostFixture` as a fixture for xUnit tests that need a synchronously started web host. The fixture manages the full web host lifecycle and blocks until the host is started before returning control to the test. +The following example passes a `BlockingManagedWebHostFixture` to `WebHostTestFactory.Create` when a test needs a synchronously started web host. The factory configures the host and returns control after startup, so the test can check `ApplicationStarted` immediately. ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Xunit; namespace WebFixtureTests; -public class WebHostIntegrationTest : IClassFixture +public class WebHostIntegrationTest { - private readonly BlockingManagedWebHostFixture _fixture; - - public WebHostIntegrationTest(BlockingManagedWebHostFixture fixture) - { - _fixture = fixture; - } - [Fact] public void HostShouldBeStarted() { - Assert.True(_fixture.HasValidState()); + using var fixture = new BlockingManagedWebHostFixture(); + using var app = WebHostTestFactory.Create(hostFixture: fixture); + + Assert.True(fixture.HasValidState()); + var lifetime = app.Host.Services.GetRequiredService(); + Assert.True(lifetime.ApplicationStarted.IsCancellationRequested); } } ``` + + + + + +The [maintained fixture test](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Tests/BlockingManagedWebHostFixtureTest.cs) shows the basic factory setup in the repository’s test suite. diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HostBuilderApplicationExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HostBuilderApplicationExtensions.md index d439206..b030c3a 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HostBuilderApplicationExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HostBuilderApplicationExtensions.md @@ -8,7 +8,9 @@ The following example converts an `IHostApplicationBuilder` to an `IHostBuilder` ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; +using Xunit; namespace WebFixtureTests; @@ -19,4 +21,18 @@ public class BuilderConverter return builder.ToHostBuilder(); } } + +public sealed class RunExample +{ + [Fact] + public void ReturnsTheWebHostBuilder() + { + var builder = WebApplication.CreateBuilder(); + Assert.Same(builder.Host, new BuilderConverter().Convert(builder)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.FakeHttpContextAccessor.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.FakeHttpContextAccessor.md index 597e628..8f80a5b 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.FakeHttpContextAccessor.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.FakeHttpContextAccessor.md @@ -20,4 +20,16 @@ public class HttpContextExample Console.WriteLine(accessor.HttpContext.Request.Method); } } + +internal static class RunExample +{ + static void Main() + { + new HttpContextExample().Demonstrate(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpRequestFeature.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpRequestFeature.md index 258eb86..a668c93 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpRequestFeature.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpRequestFeature.md @@ -20,4 +20,16 @@ public class RequestFeatureExample Console.WriteLine(request.Method); } } + +internal static class RunExample +{ + static void Main() + { + new RequestFeatureExample().Demonstrate(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpResponseFeature.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpResponseFeature.md index adbebfa..29db8f6 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpResponseFeature.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpResponseFeature.md @@ -20,4 +20,16 @@ public class ResponseFeatureExample Console.WriteLine(response.StatusCode); } } + +internal static class RunExample +{ + static void Main() + { + new ResponseFeatureExample().Demonstrate(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HttpClientExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HttpClientExtensions.md index 566e5df..82bc8cd 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HttpClientExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.HttpClientExtensions.md @@ -11,6 +11,8 @@ using System; using System.Net.Http; using System.Threading.Tasks; using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.TestHost; namespace WebFixtureTests; @@ -22,4 +24,22 @@ public class HttpClientExample Console.WriteLine(response.StatusCode); } } + +internal static class RunExample +{ + static async Task Main() + { + using var app = WebHostTestFactory.Create(pipelineSetup: app => app.Run(context => + { + context.Response.StatusCode = 202; + return Task.CompletedTask; + })); + using var client = app.Host.GetTestClient(); + await new HttpClientExample().DemonstrateAsync(client); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebApplicationFixture%601.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebApplicationFixture%601.md index 4926258..5dca623 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebApplicationFixture%601.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebApplicationFixture%601.md @@ -4,47 +4,48 @@ example: - *content --- -Use `ManagedWebApplicationFixture` when an xUnit class fixture should exercise an ASP.NET Core application's real entry point and let that entry point start the in-memory server. Derive the test from `WebApplicationTest` and pass the fixture to its base constructor so the base class initializes the fixture through `ConfigureHost` before the test reads `Server`. Fixture setup remains lazy; consuming the test host starts the deferred host, after which the test can create a client from the exposed `TestServer` and verify the application's endpoint behavior. `WebApplicationTestFactory` uses this fixture by default. +Use `ManagedWebApplicationFixture` with `WebApplicationTest` when an xUnit test class needs the real ASP.NET Core entry point and an in-memory `TestServer`. In this excerpt, xUnit supplies the fixture to the constructor, and the base class configures it before the test accesses `Host`. The test project references the separate `Program.App` executable. A request to `/` verifies that the application resolves its registered marker and reports the Development environment. ```csharp +// docfx-context: test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj +// docfx-source: test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/WebApplicationTestTest.cs +using System; +using System.Collections.Generic; using System.Threading.Tasks; -using Codebelt.Extensions.Xunit.Hosting.AspNetCore; -using Microsoft.AspNetCore.Builder; +using Codebelt.Extensions.Xunit.Hosting.Program.App; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Xunit; +using ModernProgram = Codebelt.Extensions.Xunit.Hosting.Program.App.Program; -namespace CatalogApi.Tests; +namespace Codebelt.Extensions.Xunit.Hosting.AspNetCore; -public sealed class CatalogApiTest : WebApplicationTest> +public class WebApplicationTestTest : WebApplicationTest> { - public CatalogApiTest(ManagedWebApplicationFixture fixture, ITestOutputHelper output) - : base(fixture, output) + public WebApplicationTestTest(ManagedWebApplicationFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output) { } [Fact] - public async Task HealthEndpoint_ReturnsApplicationState() + public async Task ShouldBootstrapApplication_WhenEntryPointUsesModernProgramPattern() { - using var client = Server.CreateClient(); + using var client = Host.GetTestClient(); - var body = await client.GetStringAsync("/health").ConfigureAwait(false); + var response = await client.GetAsync("/").ConfigureAwait(false); + var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false); - Assert.Equal("ready", body); + Assert.True(response.IsSuccessStatusCode); + Assert.Equal("Modern Program|Development", body); } } +``` -public sealed record CatalogStatus(string Value); + +
View Native Script · View Docker Script

Runs the pinned repository test Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestTest.ShouldBootstrapApplication_WhenEntryPointUsesModernProgramPattern.

The scripts start the maintained ASP.NET Core application through the same fixture and verify its HTTP response.

+ -public sealed class CatalogProgram -{ - public static void Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); - builder.Services.AddSingleton(new CatalogStatus("ready")); +The [maintained web application test](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/WebApplicationTestTest.cs) uses the managed fixture with a separate ASP.NET Core entry-point assembly. - var app = builder.Build(); - app.MapGet("/health", (CatalogStatus status) => status.Value); - app.Run(); - } -} -``` +The [application entry point](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/app/Codebelt.Extensions.Xunit.Hosting.Program.App/Program.cs) defines the behavior the test exercises. The [functional test project](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj) references that executable project. diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebHostFixture.md index 36bddc9..2fc39ed 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebHostFixture.md @@ -42,12 +42,16 @@ public class MiddlewareTest : WebHostTest } } -public class TestMiddleware +public class TestMiddleware(RequestDelegate next) { - public async Task InvokeAsync(HttpContext context, RequestDelegate next) + public async Task InvokeAsync(HttpContext context) { context.Response.Headers["X-Test"] = "true"; await next(context); } } ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebMinimalHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebMinimalHostFixture.md index 860ad0a..e6926f7 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebMinimalHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebMinimalHostFixture.md @@ -34,11 +34,31 @@ public class MinimalApiTest : MinimalWebHostTest } } -internal class TestMiddleware +public class TestMiddleware(RequestDelegate next) { - public async Task InvokeAsync(HttpContext context, RequestDelegate next) + public async Task InvokeAsync(HttpContext context) { + context.Response.Headers["X-Test"] = "true"; await next(context); } } + +public sealed class RunExample(ManagedWebMinimalHostFixture fixture, ITestOutputHelper output) : MinimalApiTest(fixture, output) +{ + [Fact] + public async Task BuildsAndInvokesTheConfiguredPipeline() + { + var context = new DefaultHttpContext + { + RequestServices = Application.ApplicationServices + }; + await Application.Build()(context); + Assert.Equal("true", context.Response.Headers["X-Test"].ToString()); + Assert.NotNull(context.RequestServices.GetRequiredService()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.MinimalWebHostTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.MinimalWebHostTestFactory.md index 6ba6a8d..cdec5e8 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.MinimalWebHostTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.MinimalWebHostTestFactory.md @@ -12,6 +12,7 @@ using Codebelt.Extensions.Xunit.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Xunit; namespace HealthEndpoint.Tests; @@ -32,4 +33,17 @@ public sealed class MinimalWebHostTestFactoryExample } public sealed record HealthState(string Value); + +public sealed class RunExample +{ + [Fact] + public async Task ExercisesExample() + { + Assert.Equal("healthy", await new MinimalWebHostTestFactoryExample().ReadHealthStateAsync()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebHostFixture.md index a0bbfed..df3397e 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebHostFixture.md @@ -7,6 +7,9 @@ example: Use `SelfManagedWebHostFixture` when a conventional test pipeline must exist before the server starts. The example builds middleware, explicitly starts the host, and then sends a request through `TestServer`, making the startup boundary and resulting response visible. ```csharp +// Program.cs +using System; +using System.Net.Http; using System.Threading.Tasks; using Codebelt.Extensions.Xunit.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; @@ -14,11 +17,11 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Hosting; -namespace DeferredPipeline.Tests; +namespace Codebelt.Extensions.Xunit.Hosting.AspNetCore; -public sealed class SelfManagedWebHostFixtureExample +public class Program { - public async Task StartPipelineWhenReadyAsync() + public static async Task Main(string[] args) { using var host = WebHostTestFactory.Create( pipelineSetup: app => app.Run(context => @@ -28,7 +31,11 @@ public sealed class SelfManagedWebHostFixtureExample await host.Host.StartAsync().ConfigureAwait(false); using var client = host.Host.GetTestClient(); - return await client.GetStringAsync("/").ConfigureAwait(false); + Console.WriteLine(await client.GetStringAsync("/").ConfigureAwait(false)); } } ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebMinimalHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebMinimalHostFixture.md index 633fd47..20f0256 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebMinimalHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebMinimalHostFixture.md @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Xunit; namespace DeferredHealthEndpoint.Tests; @@ -38,4 +39,17 @@ public sealed class SelfManagedWebMinimalHostFixtureExample } public sealed record HealthState(string Value); + +public sealed class RunExample +{ + [Fact] + public async Task ExercisesExample() + { + Assert.Equal("healthy", await new SelfManagedWebMinimalHostFixtureExample().StartHealthEndpointWhenReadyAsync()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ServiceCollectionExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ServiceCollectionExtensions.md index 1095e01..6021637 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ServiceCollectionExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.ServiceCollectionExtensions.md @@ -8,7 +8,9 @@ The following example registers a fake `IHttpContextAccessor` on an `IServiceCol ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Xunit; namespace WebFixtureTests; @@ -19,4 +21,19 @@ public class ExampleFixture return services.AddFakeHttpContextAccessor(ServiceLifetime.Scoped); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var provider = new ExampleFixture().ConfigureServices(new ServiceCollection()).BuildServiceProvider(); + using var scope = provider.CreateScope(); + Assert.IsType(scope.ServiceProvider.GetRequiredService()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationFixtureExtensions.md index 9ddc25f..8bf9b74 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IWebApplicationFixture` ha ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Xunit; namespace WebFixtureTests; @@ -18,4 +19,18 @@ public class WebAppStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedWebApplicationFixture(); + Assert.False(new WebAppStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactory.md index 0d93104..2cb4ded 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactory.md @@ -4,49 +4,47 @@ example: - *content --- -The test project references a minimal ASP.NET Core application with a `/health` endpoint. `WebApplicationTestFactory` uses `ManagedWebApplicationFixture` by default, runs that real entry point on `TestServer`, applies a test-only service override through `IWebHostBuilder`, and gives the test an owned host from which it creates an HTTP client. Pass an explicit `IWebApplicationFixture` when the test needs a different lifecycle. +Use `WebApplicationTestFactory.Create` to exercise an existing ASP.NET Core application through `TestServer`. The default `ManagedWebApplicationFixture` runs the entry point from the separate `Program.App` project. In this excerpt from the functional test, the web-host setup supplies configuration and registers a service. Requests to `/configuration` and `/custom-service` verify that the application endpoints see both changes. The test disposes the client and the factory context. ```csharp -using System.Threading.Tasks; -using Codebelt.Extensions.Xunit.Hosting.AspNetCore; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Xunit; - -namespace CatalogApi.Tests; - -public sealed class WebApplicationTestFactoryExample -{ +// docfx-context: test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj +// docfx-source: test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/WebApplicationTestFactoryTest.cs [Fact] - public async Task Create_UsesTheApplicationPipelineAndTestOverrides() + public async Task Create_ShouldApplyWebHostConfiguration_WhenWebHostSetupIsProvided() { - using var application = WebApplicationTestFactory.Create(builder => + using var application = WebApplicationTestFactory.Create(builder => { + builder.ConfigureAppConfiguration((_, configuration) => + { + configuration.AddInMemoryCollection(new Dictionary + { + ["ProgramLane:Message"] = "Configured from WebApplicationTestFactory" + }); + }); + builder.ConfigureServices(services => - services.AddSingleton(new CatalogStatus("test-ready"))); + { + services.AddSingleton(new ProgramCustomization("Custom service from WebApplicationTestFactory")); + }); }); using var client = application.Host.GetTestClient(); - var body = await client.GetStringAsync("/health").ConfigureAwait(false); + var configurationResponse = await client.GetAsync("/configuration").ConfigureAwait(false); + var configurationBody = await configurationResponse.Content.ReadAsStringAsync().ConfigureAwait(false); + var serviceResponse = await client.GetAsync("/custom-service").ConfigureAwait(false); + var serviceBody = await serviceResponse.Content.ReadAsStringAsync().ConfigureAwait(false); - Assert.Equal("test-ready", body); + Assert.True(configurationResponse.IsSuccessStatusCode); + Assert.Equal("Configured from WebApplicationTestFactory", configurationBody); + Assert.True(serviceResponse.IsSuccessStatusCode); + Assert.Equal("Custom service from WebApplicationTestFactory", serviceBody); } -} +``` -public sealed record CatalogStatus(string Value); + +
View Native Script · View Docker Script

Runs the pinned repository test Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactoryTest.Create_ShouldApplyWebHostConfiguration_WhenWebHostSetupIsProvided.

The scripts run the maintained integration test, which overrides services and configuration and verifies the results through HTTP endpoints.

+ -public sealed class CatalogProgram -{ - public static void Main(string[] args) - { - var builder = WebApplication.CreateBuilder(args); - builder.Services.AddSingleton(new CatalogStatus("ready")); +The [maintained factory test](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/WebApplicationTestFactoryTest.cs) shows how service and configuration overrides reach the application endpoints. - var app = builder.Build(); - app.MapGet("/health", (CatalogStatus status) => status.Value); - app.Run(); - } -} -``` +The [application entry point](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/app/Codebelt.Extensions.Xunit.Hosting.Program.App/Program.cs) defines the behavior the test exercises. The [functional test project](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj) references that executable project. diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostFixtureExtensions.md index e835847..0923559 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IWebHostFixture` has a valid initialize ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Xunit; namespace WebFixtureTests; @@ -18,4 +19,20 @@ public class WebHostStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedWebHostFixture(); + Assert.False(new WebHostStateGuard().EnsureFixtureIsReady(fixture)); + using var app = WebHostTestFactory.Create(hostFixture: fixture); + Assert.True(new WebHostStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostTestFactory.md index 0f08606..b1967fa 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostTestFactory.md @@ -12,6 +12,7 @@ using Codebelt.Extensions.Xunit.Hosting.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Xunit; namespace RequestPipeline.Tests; @@ -32,4 +33,17 @@ public sealed class WebHostTestFactoryExample } public sealed record PipelineStatus(string Value); + +public sealed class RunExample +{ + [Fact] + public async Task ExercisesExample() + { + Assert.Equal("ready", await new WebHostTestFactoryExample().InvokeStatusMiddlewareAsync()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebMinimalHostFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebMinimalHostFixtureExtensions.md index 43a1464..fb95f15 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebMinimalHostFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebMinimalHostFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IWebMinimalHostFixture` has a valid ini ```csharp using Codebelt.Extensions.Xunit.Hosting.AspNetCore; +using Xunit; namespace WebFixtureTests; @@ -18,4 +19,20 @@ public class WebMinimalHostStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedWebMinimalHostFixture(); + Assert.False(new WebMinimalHostStateGuard().EnsureFixtureIsReady(fixture)); + using var app = MinimalWebHostTestFactory.Create(hostFixture: fixture); + Assert.True(new WebMinimalHostStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.GenericHostFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.GenericHostFixtureExtensions.md index dac9d14..f70c725 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.GenericHostFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.GenericHostFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IGenericHostFixture` has been fully con ```csharp using Codebelt.Extensions.Xunit.Hosting; +using Xunit; namespace HostFixtureTests; @@ -18,4 +19,20 @@ public class HostStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedHostFixture(); + Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture)); + using var app = HostTestFactory.Create(hostFixture: fixture); + Assert.True(new HostStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.HostTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.HostTestFactory.md index 49e4c6a..4d40eab 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.HostTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.HostTestFactory.md @@ -9,6 +9,7 @@ Use `HostTestFactory` when the test owns the Generic Host setup instead of loadi ```csharp using Codebelt.Extensions.Xunit.Hosting; using Microsoft.Extensions.DependencyInjection; +using Xunit; namespace WorkerServices.Tests; @@ -25,4 +26,17 @@ public sealed class HostTestFactoryExample } public sealed record WorkerStatus(string Value); + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + Assert.Equal("ready", new HostTestFactoryExample().ResolveWorkerStatus()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.LoggerExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.LoggerExtensions.md index 3a60966..99cdd1e 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.LoggerExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.LoggerExtensions.md @@ -9,7 +9,9 @@ The following example retrieves the captured log entries from an `ILogger` af ```csharp using Codebelt.Extensions.Xunit; using Codebelt.Extensions.Xunit.Hosting; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Xunit; namespace HostFixtureTests; @@ -25,4 +27,24 @@ public class LogInspector return logger.GetTestStore(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + var services = new ServiceCollection(); + services.AddXunitTestLogging(); + using var provider = services.BuildServiceProvider(); + var logger = provider.GetRequiredService>(); + logger.LogWarning("queue ready"); + var inspector = new LogInspector(); + Assert.Contains(inspector.GetEntries((ILogger)logger).Query(), entry => entry.Severity == LogLevel.Warning && entry.Message == "Warning: queue ready"); + Assert.Contains(inspector.GetEntries(logger).Query(), entry => entry.Severity == LogLevel.Warning && entry.Message == "Warning: queue ready"); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedApplicationFixture%601.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedApplicationFixture%601.md index 65cde41..4ec356e 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedApplicationFixture%601.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedApplicationFixture%601.md @@ -4,43 +4,166 @@ example: - *content --- -Use `ManagedApplicationFixture` when an xUnit class fixture should exercise the application's real entry point and let that entry point start the host. Derive the test from `ApplicationTest` and pass the fixture to its base constructor so the base class initializes the fixture through `ConfigureHost` before the test reads `Host`. Fixture setup remains lazy; accessing the test host starts the deferred host and surfaces startup failures at the point the test consumes it. `ApplicationTestFactory` uses this fixture by default. +Use `ManagedApplicationFixture` when an xUnit test should run the application's real entry point and inspect services registered by that application. `TEntryPoint` identifies the executable application assembly; keep its `Program` and startup registrations in the application project, separate from the xUnit runner assembly. Derive the test from `ApplicationTest` and inject the fixture so the base class initializes it before the test accesses `Host`. + +The maintained worker test below resolves a marker registered by the worker's real `Program` and checks the marker value, Development environment, and host lifetime service. Its test project references the worker application as a separate executable project, preserving the assembly identity required by `ManagedApplicationFixture`. ```csharp -using Codebelt.Extensions.Xunit.Hosting; +// docfx-context: test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj +// docfx-source: test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/BootstrapperMinimalWorkerApplicationTestTest.cs using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Xunit; +using BootstrapperMinimalWorkerMarker = Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorker.App.BootstrapperMinimalWorkerMarker; +using BootstrapperMinimalWorkerProgram = Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorker.App.Program; -namespace InventoryWorker.Tests; +namespace Codebelt.Extensions.Xunit.Hosting; -public sealed class InventoryWorkerTest : ApplicationTest> +public class BootstrapperMinimalWorkerApplicationTestTest : ApplicationTest> { - public InventoryWorkerTest(ManagedApplicationFixture fixture, ITestOutputHelper output) - : base(fixture, output) + public BootstrapperMinimalWorkerApplicationTestTest(ManagedApplicationFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output) { } [Fact] - public void Host_ContainsApplicationService() + public void ShouldBootstrapMinimalWorkerProgram() { - var identity = Host.Services.GetRequiredService(); + var marker = Host.Services.GetRequiredService(); - Assert.Equal("Inventory worker", identity.Name); + Assert.Equal("Bootstrapper Minimal Worker", marker.Value); + Assert.Equal("Development", Environment.EnvironmentName); + Assert.NotNull(Host.Services.GetRequiredService()); } } +``` -public sealed record WorkerIdentity(string Name); + +
View Native Script · View Docker Script

Runs the pinned repository test Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorkerApplicationTestTest.ShouldBootstrapMinimalWorkerProgram.

The scripts run this test in its original application and test projects.

+ -public sealed class WorkerProgram -{ - public static void Main(string[] args) - { - var builder = Host.CreateApplicationBuilder(args); - builder.Services.AddSingleton(new WorkerIdentity("Inventory worker")); +To reproduce this exact test without assembling its multi-project context, run either complete PowerShell 7 option below. Each script downloads the same pinned repository revision and runs the maintained test without creating a substitute application or changing its assertions; the test verifies one passed result and checks the runner report for the exact test name. + +## Native: PowerShell 7 and .NET 11 SDK + +```powershell +#requires -Version 7.0 +& { + $ErrorActionPreference = 'Stop' + $PSNativeCommandUseErrorActionPreference = $false + # Executes trusted repository build tasks and NuGet packages with your permissions. + # Review the pinned source before running; a container is not a security sandbox. + $null = Get-Command dotnet -ErrorAction Stop + $work = Join-Path ([IO.Path]::GetTempPath()) ('dx-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) + $null = New-Item -ItemType Directory -Path $work + try { + $commit = '84b13767cb9484f8f3a36a71875662edfdb3e511' + Invoke-WebRequest "https://codeload.github.com/codebeltnet/xunit/zip/$commit" -OutFile "$work/source.zip" + Expand-Archive -LiteralPath "$work/source.zip" -DestinationPath "$work/extracted" + Move-Item -LiteralPath "$work/extracted/xunit-$commit" -Destination "$work/repo" + $project = 'test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj' + $test = 'Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorkerApplicationTestTest.ShouldBootstrapMinimalWorkerProgram' + Push-Location "$work/repo" + try { + dotnet run --project $project --framework net11.0 -p:SkipSignAssembly=true -- --filter-method $test --report-xunit-xml --report-xunit-xml-filename result.xml --results-directory "$work/results" 2>&1 | Tee-Object -FilePath "$work/run.log" + } + finally { Pop-Location } + $code = $LASTEXITCODE + if ($code -ne 0) { throw "Repository test failed with exit code $code. See $work/run.log" } + # Require exactly the original test, executed and passing, with no runner errors. + [xml] $report = Get-Content -LiteralPath "$work/results/result.xml" -Raw + $tests = @($report.SelectNodes('/assemblies/assembly/collection/test')) + $assemblies = @($report.SelectNodes('/assemblies/assembly')) + if ($assemblies.Count -ne 1 -or $assemblies[0].total -ne '1' -or $assemblies[0].passed -ne '1' -or + $assemblies[0].errors -ne '0' -or $tests.Count -ne 1 -or $tests[0].name -cne $test -or $tests[0].result -cne 'Pass') { + throw "Expected exactly one passing $test; inspect $work/results/result.xml" + } + Write-Host "Verified: $test (1 executed, 1 passed)." + } + catch { + # Preserve diagnostics outside the repository even though downloaded source is cleaned. + $diagnostics = "$work-diagnostics" + $null = New-Item -ItemType Directory -Path $diagnostics -Force + foreach ($name in @('run.log', 'results')) { + if (Test-Path -LiteralPath "$work/$name") { Copy-Item -LiteralPath "$work/$name" -Destination $diagnostics -Recurse } + } + Write-Warning "Execution not verified. Diagnostics: $diagnostics" + throw + } + finally { + $resolved = [IO.Path]::GetFullPath($work) + $temp = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('/','\') + [IO.Path]::DirectorySeparatorChar + if (-not $resolved.StartsWith($temp, [StringComparison]::OrdinalIgnoreCase)) { throw 'Unsafe cleanup path.' } + Remove-Item -LiteralPath $resolved -Recurse -Force + } +} +``` + +## Docker: PowerShell 7 and Docker with Linux containers - using var host = builder.Build(); - host.Run(); +No host .NET SDK is required. The official SDK image supplies it; first use pulls the image. The `11.0` image tag can move as Microsoft publishes SDK updates. On Linux, the container runs with the host UID and GID so build and test outputs remain removable during cleanup. Its home and .NET CLI state use container-local `/tmp`, which is writable by that identity. + +```powershell +#requires -Version 7.0 +& { + $ErrorActionPreference = 'Stop' + $PSNativeCommandUseErrorActionPreference = $false + # Executes trusted repository build tasks and NuGet packages with your permissions. + # Review the pinned source before running; a container is not a security sandbox. + $null = Get-Command docker -ErrorAction Stop + docker info *> $null + if ($LASTEXITCODE -ne 0) { throw 'Docker daemon unavailable.' } + $work = Join-Path ([IO.Path]::GetTempPath()) ('dx-' + [guid]::NewGuid().ToString('N').Substring(0, 8)) + $null = New-Item -ItemType Directory -Path $work + try { + $commit = '84b13767cb9484f8f3a36a71875662edfdb3e511' + Invoke-WebRequest "https://codeload.github.com/codebeltnet/xunit/zip/$commit" -OutFile "$work/source.zip" + Expand-Archive -LiteralPath "$work/source.zip" -DestinationPath "$work/extracted" + Move-Item -LiteralPath "$work/extracted/xunit-$commit" -Destination "$work/repo" + $project = 'test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj' + $test = 'Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorkerApplicationTestTest.ShouldBootstrapMinimalWorkerProgram' + $dockerUser = @() + if ($IsLinux) { + # Keep bind-mounted build output removable by the host user. + $hostUid = id -u + if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve host UID.' } + $hostGid = id -g + if ($LASTEXITCODE -ne 0) { throw 'Cannot resolve host GID.' } + $dockerUser = @('--user', "${hostUid}:${hostGid}") + } + docker run --rm @dockerUser --env HOME=/tmp --env DOTNET_CLI_HOME=/tmp --mount "type=bind,source=$work,target=/work" --workdir /work/repo mcr.microsoft.com/dotnet/sdk:11.0 dotnet run --project $project --framework net11.0 -p:SkipSignAssembly=true -- --filter-method $test --report-xunit-xml --report-xunit-xml-filename result.xml --results-directory /work/results 2>&1 | Tee-Object -FilePath "$work/run.log" + $code = $LASTEXITCODE + if ($code -ne 0) { throw "Repository test failed with exit code $code. See $work/run.log" } + # Require exactly the original test, executed and passing, with no runner errors. + [xml] $report = Get-Content -LiteralPath "$work/results/result.xml" -Raw + $tests = @($report.SelectNodes('/assemblies/assembly/collection/test')) + $assemblies = @($report.SelectNodes('/assemblies/assembly')) + if ($assemblies.Count -ne 1 -or $assemblies[0].total -ne '1' -or $assemblies[0].passed -ne '1' -or + $assemblies[0].errors -ne '0' -or $tests.Count -ne 1 -or $tests[0].name -cne $test -or $tests[0].result -cne 'Pass') { + throw "Expected exactly one passing $test; inspect $work/results/result.xml" + } + Write-Host "Verified: $test (1 executed, 1 passed)." + } + catch { + # Preserve diagnostics outside the repository even though downloaded source is cleaned. + $diagnostics = "$work-diagnostics" + $null = New-Item -ItemType Directory -Path $diagnostics -Force + foreach ($name in @('run.log', 'results')) { + if (Test-Path -LiteralPath "$work/$name") { Copy-Item -LiteralPath "$work/$name" -Destination $diagnostics -Recurse } + } + Write-Warning "Execution not verified. Diagnostics: $diagnostics" + throw + } + finally { + $resolved = [IO.Path]::GetFullPath($work) + $temp = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('/','\') + [IO.Path]::DirectorySeparatorChar + if (-not $resolved.StartsWith($temp, [StringComparison]::OrdinalIgnoreCase)) { throw 'Unsafe cleanup path.' } + Remove-Item -LiteralPath $resolved -Recurse -Force } } ``` + +## Further exploration + +The [pinned worker entry point](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/app/Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorker.App/Program.cs) constructs the host, registers the marker and hosted service, and runs the application. The [functional test source](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/BootstrapperMinimalWorkerApplicationTestTest.cs) shows the same fixture usage in its maintained class, while the [test project](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj) records its separate application and library references and target frameworks. The [fixture implementation](https://github.com/codebeltnet/xunit/blob/84b13767cb9484f8f3a36a71875662edfdb3e511/src/Codebelt.Extensions.Xunit.Hosting/ManagedApplicationFixture.cs) shows how it selects the entry-point assembly and connects deferred host startup. + +The Native execution block was verified on Windows x64 with .NET SDK 11.0.100 and runtime 11.0.0; it reported the named test passing. The Docker block's most recent end-to-end attempt observed the test pass but the container exited with code 137, so Docker execution remains unverified. diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedHostFixture.md index 4514482..76e8910 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedHostFixture.md @@ -46,3 +46,7 @@ public class TestWorker : BackgroundService } } ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedMinimalHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedMinimalHostFixture.md index 30d5973..9f487f6 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedMinimalHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ManagedMinimalHostFixture.md @@ -35,3 +35,7 @@ public class MinimalWorkerTest : MinimalHostTest public class MetricsTracker; ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostFixtureExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostFixtureExtensions.md index 08d69f2..35c967a 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostFixtureExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostFixtureExtensions.md @@ -8,6 +8,7 @@ The following example validates that an `IMinimalHostFixture` has been fully ini ```csharp using Codebelt.Extensions.Xunit.Hosting; +using Xunit; namespace HostFixtureTests; @@ -18,4 +19,20 @@ public class HostStateGuard return fixture.HasValidState(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var fixture = new ManagedMinimalHostFixture(); + Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture)); + using var app = MinimalHostTestFactory.Create(hostFixture: fixture); + Assert.True(new HostStateGuard().EnsureFixtureIsReady(fixture)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostTestFactory.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostTestFactory.md index f4c5342..adef8ca 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostTestFactory.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.MinimalHostTestFactory.md @@ -23,4 +23,16 @@ public class MinimalHostFactoryExample Console.WriteLine(version); } } + +internal static class RunExample +{ + static void Main() + { + new MinimalHostFactoryExample().Demonstrate(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedHostFixture.md index 40197bf..95f3947 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedHostFixture.md @@ -31,4 +31,17 @@ public sealed class SelfManagedHostFixtureExample Assert.True(started); } } + +public sealed class RunExample +{ + [Fact] + public async Task ExercisesExample() + { + await new SelfManagedHostFixtureExample().StartAfterAttachingObserverAsync(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedMinimalHostFixture.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedMinimalHostFixture.md index 322d457..e61a42d 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedMinimalHostFixture.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.SelfManagedMinimalHostFixture.md @@ -33,4 +33,17 @@ public sealed class SelfManagedMinimalHostFixtureExample } public sealed record StartupState(string Value); + +public sealed class RunExample +{ + [Fact] + public async Task ExercisesExample() + { + await new SelfManagedMinimalHostFixtureExample().ConfigureBeforeStartingAsync(); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceCollectionExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceCollectionExtensions.md index 1709956..85382c4 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceCollectionExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceCollectionExtensions.md @@ -10,6 +10,7 @@ The following example registers xUnit test logging and output helper services on using Codebelt.Extensions.Xunit.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Xunit; namespace HostFixtureTests; @@ -22,4 +23,21 @@ public class ExampleFixture return services; } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + using var provider = new ExampleFixture().ConfigureServices(new ServiceCollection()).BuildServiceProvider(); + Assert.IsType(provider.GetRequiredService()); + var logger = provider.GetRequiredService>(); + logger.LogInformation("storage ready"); + Assert.Contains(logger.GetTestStore().Query(), entry => entry.Severity == LogLevel.Information && entry.Message == "Information: storage ready"); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceProviderExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceProviderExtensions.md index cc71f59..f2bd847 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceProviderExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.ServiceProviderExtensions.md @@ -10,6 +10,7 @@ The following example retrieves a scoped service of type `T` from an `IServicePr using System; using Codebelt.Extensions.Xunit.Hosting; using Microsoft.Extensions.DependencyInjection; +using Xunit; namespace HostFixtureTests; @@ -20,4 +21,23 @@ public class ServiceResolver return provider.GetRequiredScopedService(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + var services = new ServiceCollection(); + services.AddScoped(_ => new object()); + using var provider = services.BuildServiceProvider(new ServiceProviderOptions + { + ValidateScopes = true + }); + Assert.NotSame(new ServiceResolver().Resolve(provider), new ServiceResolver().Resolve(provider)); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.XunitTestLoggerEntry.md b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.XunitTestLoggerEntry.md index c9ed9d9..9e1721b 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.XunitTestLoggerEntry.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.Hosting.XunitTestLoggerEntry.md @@ -9,6 +9,7 @@ The following example creates an `XunitTestLoggerEntry` record and formats its m ```csharp using Codebelt.Extensions.Xunit.Hosting; using Microsoft.Extensions.Logging; +using Xunit; namespace HostFixtureTests; @@ -20,4 +21,17 @@ public class LogEntryExample return entry.ToString(); } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + Assert.Equal("Something unexpected happened.", new LogEntryExample().FormatEntry()); + } +} ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.InMemoryTestStore%601.md b/.docfx/api/types/Codebelt.Extensions.Xunit.InMemoryTestStore%601.md index 0f0a81d..d9459b4 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.InMemoryTestStore%601.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.InMemoryTestStore%601.md @@ -9,6 +9,7 @@ Use the store to retain test data and query the matching items without a databas ```csharp using System.Linq; using Codebelt.Extensions.Xunit; +using Xunit; namespace Example.Tests; @@ -22,6 +23,17 @@ public class StoreExample return store.Count == 2 && store.Query(value => value == "cached").Single() == "cached"; } } + +public sealed class RunExample +{ + [Fact] + public void ExercisesExample() + { + Assert.True(new StoreExample().HasMatchingItem()); + } +} ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityAttribute.md b/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityAttribute.md index 80c30a3..1f29891 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityAttribute.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityAttribute.md @@ -35,4 +35,6 @@ public class InitializationTest : Test } ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityTestMethodOrderer.md b/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityTestMethodOrderer.md index 126ec45..ff42450 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityTestMethodOrderer.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.PriorityTestMethodOrderer.md @@ -37,4 +37,6 @@ public class CacheLifecycleTest : Test } ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperAccessor.md b/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperAccessor.md index 9c9bd7b..72aabcb 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperAccessor.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperAccessor.md @@ -25,4 +25,6 @@ public class OutputAccessorTest : Test } ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperExtensions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperExtensions.md index 6f51f22..c77d208 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperExtensions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.TestOutputHelperExtensions.md @@ -25,7 +25,9 @@ public class OutputLinesTest : Test } ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + --- uid: Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines(Xunit.ITestOutputHelper,System.Object[]) @@ -54,6 +56,10 @@ public class MixedOutputTest : Test } ``` + + + + --- uid: Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines``1(Xunit.ITestOutputHelper,``0[]) example: @@ -81,6 +87,10 @@ public class ArrayOutputTest : Test } ``` + + + + --- uid: Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines``1(Xunit.ITestOutputHelper,System.Collections.Generic.IEnumerable{``0}) example: @@ -109,3 +119,7 @@ public class EnumerableOutputTest : Test } } ``` + + + + diff --git a/.docfx/api/types/Codebelt.Extensions.Xunit.WildcardOptions.md b/.docfx/api/types/Codebelt.Extensions.Xunit.WildcardOptions.md index 13d15f5..4449660 100644 --- a/.docfx/api/types/Codebelt.Extensions.Xunit.WildcardOptions.md +++ b/.docfx/api/types/Codebelt.Extensions.Xunit.WildcardOptions.md @@ -25,4 +25,6 @@ public class WildcardExampleTest : Test } ``` -[!INCLUDE [availability-default](../../includes/availability-default.md)] + + + diff --git a/.docfx/docfx.json b/.docfx/docfx.json index 6164845..275a30c 100644 --- a/.docfx/docfx.json +++ b/.docfx/docfx.json @@ -45,6 +45,11 @@ "files": [ "images/**" ] + }, + { + "files": [ + "run-actions/**" + ] } ], "globalMetadata": { diff --git a/.docfx/run-actions.manifest.json b/.docfx/run-actions.manifest.json new file mode 100644 index 0000000..d92d62d --- /dev/null +++ b/.docfx/run-actions.manifest.json @@ -0,0 +1,876 @@ +{ + "schemaVersion": 1, + "examples": [ + { + "id": "00acdae546dce87b654496e1", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class MinimalApiTest : MinimalWebHostTest\n{\n public MinimalApiTest(ManagedWebMinimalHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)\n {\n }\n\n protected override void ConfigureHost(IHostApplicationBuilder hb)\n {\n hb.Services.AddFakeHttpContextAccessor();\n }\n\n public override void ConfigureApplication(IApplicationBuilder app)\n {\n app.UseMiddleware();\n }\n}\n\npublic class TestMiddleware(RequestDelegate next)\n{\n public async Task InvokeAsync(HttpContext context)\n {\n context.Response.Headers[\"X-Test\"] = \"true\";\n await next(context);\n }\n}\n\npublic sealed class RunExample(ManagedWebMinimalHostFixture fixture, ITestOutputHelper output) : MinimalApiTest(fixture, output)\n{\n [Fact]\n public async Task BuildsAndInvokesTheConfiguredPipeline()\n {\n var context = new DefaultHttpContext\n {\n RequestServices = Application.ApplicationServices\n };\n await Application.Build()(context);\n Assert.Equal(\"true\", context.Response.Headers[\"X-Test\"].ToString());\n Assert.NotNull(context.RequestServices.GetRequiredService());\n }\n}" + } + }, + { + "id": "0308118a47b5c02daa7b32be", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using System.Collections.Generic;\nusing Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class EnumerableOutputTest : Test\n{\n public EnumerableOutputTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldWriteSequenceItems()\n {\n IEnumerable values = new List { 1, 2, 3 };\n TestOutput.WriteLines(values);\n Assert.True(HasTestOutput);\n }\n}" + } + }, + { + "id": "038a1c806225b412a6f986c1", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class WildcardExampleTest : Test\n{\n public WildcardExampleTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldMatchConfiguredPattern()\n {\n var options = new WildcardOptions { ThrowOnNoMatch = true };\n Assert.True(Match(\"cache*\", \"cached\", setup => setup.ThrowOnNoMatch = options.ThrowOnNoMatch));\n }\n}" + } + }, + { + "id": "08b911ef79f0b743282e37c9", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web", + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features;\n\nnamespace WebFixtureTests;\n\npublic class ResponseFeatureExample\n{\n public void Demonstrate()\n {\n var response = new FakeHttpResponseFeature();\n Console.WriteLine(response.StatusCode);\n }\n}\n\ninternal static class RunExample\n{\n static void Main()\n {\n new ResponseFeatureExample().Demonstrate();\n }\n}" + } + }, + { + "id": "10457ac34cce1cbadb26aee1", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class ArrayOutputTest : Test\n{\n public ArrayOutputTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldWriteArrayItems()\n {\n TestOutput.WriteLines(new int[] { 1, 2, 3 });\n Assert.True(HasTestOutput);\n }\n}" + } + }, + { + "id": "1130af506703020850fdadea", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class HostStateGuard\n{\n public bool EnsureFixtureIsReady(IGenericHostFixture fixture)\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedHostFixture();\n Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture));\n using var app = HostTestFactory.Create(hostFixture: fixture);\n Assert.True(new HostStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "18b0746bf3da1d84f81b5274", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Logging;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class ExampleFixture\n{\n public IServiceCollection ConfigureServices(IServiceCollection services)\n {\n services.AddXunitTestLogging(LogLevel.Information);\n services.AddXunitTestLoggingOutputHelperAccessor();\n return services;\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var provider = new ExampleFixture().ConfigureServices(new ServiceCollection()).BuildServiceProvider();\n Assert.IsType(provider.GetRequiredService());\n var logger = provider.GetRequiredService>();\n logger.LogInformation(\"storage ready\");\n Assert.Contains(logger.GetTestStore().Query(), entry => entry.Severity == LogLevel.Information && entry.Message == \"Information: storage ready\");\n }\n}" + } + }, + { + "id": "1e869fe39c4833386733c21f", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace HealthEndpoint.Tests;\n\npublic sealed class MinimalWebHostTestFactoryExample\n{\n public async Task ReadHealthStateAsync()\n {\n using var response = await MinimalWebHostTestFactory.RunAsync(\n services => services.AddSingleton(new HealthState(\"healthy\")),\n app => app.Run(context =>\n {\n var health = context.RequestServices.GetRequiredService();\n return context.Response.WriteAsync(health.Value);\n })).ConfigureAwait(false);\n\n return await response.Content.ReadAsStringAsync().ConfigureAwait(false);\n }\n}\n\npublic sealed record HealthState(string Value);\n\npublic sealed class RunExample\n{\n [Fact]\n public async Task ExercisesExample()\n {\n Assert.Equal(\"healthy\", await new MinimalWebHostTestFactoryExample().ReadHealthStateAsync());\n }\n}" + } + }, + { + "id": "1ec9196292addaca42a7eef1", + "strategy": "repository", + "transports": [ + "native", + "docker" + ], + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorkerApplicationTestTest.ShouldBootstrapMinimalWorkerProgram", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0" + }, + { + "id": "21b422ce67f920d801901db0", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class WebHostIntegrationTest\n{\n [Fact]\n public void HostShouldBeStarted()\n {\n using var fixture = new BlockingManagedWebHostFixture();\n using var app = WebHostTestFactory.Create(hostFixture: fixture);\n\n Assert.True(fixture.HasValidState());\n var lifetime = app.Host.Services.GetRequiredService();\n Assert.True(lifetime.ApplicationStarted.IsCancellationRequested);\n }\n}" + } + }, + { + "id": "38b60f4b4c1a588bbefe92f1", + "strategy": "repository", + "transports": [ + "native", + "docker" + ], + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactoryTest.Create_ShouldApplyWebHostConfiguration_WhenWebHostSetupIsProvided", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0" + }, + { + "id": "3a1dbfc0e010519636b7091e", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web", + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http;\n\nnamespace WebFixtureTests;\n\npublic class HttpContextExample\n{\n public void Demonstrate()\n {\n var accessor = new FakeHttpContextAccessor();\n Console.WriteLine(accessor.HttpContext.Request.Method);\n }\n}\n\ninternal static class RunExample\n{\n static void Main()\n {\n new HttpContextExample().Demonstrate();\n }\n}" + } + }, + { + "id": "3c3b98167b30d6985017ec27", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "Microsoft.AspNetCore.TestHost@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.AspNetCore.TestHost;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace DeferredHealthEndpoint.Tests;\n\npublic sealed class SelfManagedWebMinimalHostFixtureExample\n{\n public async Task StartHealthEndpointWhenReadyAsync()\n {\n using var host = MinimalWebHostTestFactory.Create(\n services => services.AddSingleton(new HealthState(\"healthy\")),\n pipelineSetup: app => app.Run(context =>\n {\n var health = context.RequestServices.GetRequiredService();\n return context.Response.WriteAsync(health.Value);\n }),\n hostFixture: new SelfManagedWebMinimalHostFixture());\n\n await host.Host.StartAsync().ConfigureAwait(false);\n using var client = host.Host.GetTestClient();\n\n return await client.GetStringAsync(\"/\").ConfigureAwait(false);\n }\n}\n\npublic sealed record HealthState(string Value);\n\npublic sealed class RunExample\n{\n [Fact]\n public async Task ExercisesExample()\n {\n Assert.Equal(\"healthy\", await new SelfManagedWebMinimalHostFixtureExample().StartHealthEndpointWhenReadyAsync());\n }\n}" + } + }, + { + "id": "45fcccef5fc861315b50c55e", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class OutputLinesTest : Test\n{\n public OutputLinesTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldWriteValuesOnSeparateLines()\n {\n TestOutput.WriteLines(\"started\", 2, \"finished\");\n Assert.True(HasTestOutput);\n }\n}" + } + }, + { + "id": "4c5e94adccd20cab4da52078", + "strategy": "repository", + "transports": [ + "native", + "docker" + ], + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestTest.ShouldBootstrapApplication_WhenEntryPointUsesModernProgramPattern", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0" + }, + { + "id": "513a785b0e0abbe2284270b9", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Logging;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class LogInspector\n{\n public ITestStore GetEntries(ILogger logger)\n {\n return logger.GetTestStore();\n }\n\n public ITestStore GetEntries(ILogger logger)\n {\n return logger.GetTestStore();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n var services = new ServiceCollection();\n services.AddXunitTestLogging();\n using var provider = services.BuildServiceProvider();\n var logger = provider.GetRequiredService>();\n logger.LogWarning(\"queue ready\");\n var inspector = new LogInspector();\n Assert.Contains(inspector.GetEntries((ILogger)logger).Query(), entry => entry.Severity == LogLevel.Warning && entry.Message == \"Warning: queue ready\");\n Assert.Contains(inspector.GetEntries(logger).Query(), entry => entry.Severity == LogLevel.Warning && entry.Message == \"Warning: queue ready\");\n }\n}" + } + }, + { + "id": "515575be5bb7683cac9903a5", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace WorkerLifecycle.Tests;\n\npublic sealed class SelfManagedHostFixtureExample\n{\n public async Task StartAfterAttachingObserverAsync()\n {\n using var host = HostTestFactory.Create(\n hostFixture: new SelfManagedHostFixture());\n\n var started = false;\n var lifetime = host.Host.Services.GetRequiredService();\n using var registration = lifetime.ApplicationStarted.Register(() => started = true);\n\n Assert.False(started);\n await host.Host.StartAsync().ConfigureAwait(false);\n Assert.True(started);\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public async Task ExercisesExample()\n {\n await new SelfManagedHostFixtureExample().StartAfterAttachingObserverAsync();\n }\n}" + } + }, + { + "id": "545543e49c6bf054a9e06186", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class OutputAccessorTest : Test\n{\n public OutputAccessorTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldExposeCurrentOutput()\n {\n var accessor = new TestOutputHelperAccessor(TestOutput);\n Assert.Same(TestOutput, accessor.TestOutput);\n }\n}" + } + }, + { + "id": "549c3e82bd0bcb99e9f05bfa", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class WebAppStateGuard\n{\n public bool EnsureFixtureIsReady(IWebApplicationFixture fixture) where TEntryPoint : class\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedWebApplicationFixture();\n Assert.False(new WebAppStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "578d467fd203f66cc41b0364", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class MixedOutputTest : Test\n{\n public MixedOutputTest(ITestOutputHelper output) : base(output) { }\n\n [Fact]\n public void ShouldWriteMixedValues()\n {\n TestOutput.WriteLines((object)\"cache\", 3);\n Assert.True(HasTestOutput);\n }\n}" + } + }, + { + "id": "5e35a33e56470f93afbedf19", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class ServiceResolver\n{\n public T Resolve(IServiceProvider provider) where T : notnull\n {\n return provider.GetRequiredScopedService();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n var services = new ServiceCollection();\n services.AddScoped(_ => new object());\n using var provider = services.BuildServiceProvider(new ServiceProviderOptions\n {\n ValidateScopes = true\n });\n Assert.NotSame(new ServiceResolver().Resolve(provider), new ServiceResolver().Resolve(provider));\n }\n}" + } + }, + { + "id": "6a59b7744a7d9994ffc04782", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class MinimalWorkerTest : MinimalHostTest\n{\n public MinimalWorkerTest(ManagedMinimalHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)\n {\n }\n\n protected override void ConfigureHost(IHostApplicationBuilder hb)\n {\n hb.Services.AddSingleton();\n hb.Services.AddXunitTestLogging();\n }\n\n [Fact]\n public void Host_ShouldNotBeNull()\n {\n Assert.NotNull(Host);\n }\n}\n\npublic class MetricsTracker;" + } + }, + { + "id": "782f24d34260070258f6d164", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using System;\nusing Codebelt.Extensions.Xunit;\nusing Xunit;\nusing Xunit.Sdk;\n\nnamespace Example.Tests;\n\n[TestMethodOrderer(typeof(PriorityTestMethodOrderer))]\npublic class CacheLifecycleTest : Test\n{\n private static bool _initialized;\n\n public CacheLifecycleTest(ITestOutputHelper output) : base(output) { }\n\n [Fact, Priority(-1)]\n public void ShouldInitializeCache()\n {\n var orderer = new PriorityTestMethodOrderer();\n Assert.Empty(orderer.OrderTestMethods(Array.Empty()));\n _initialized = true;\n }\n\n [Fact, Priority(0)]\n public void ShouldUseInitializedCache()\n {\n Assert.True(_initialized);\n }\n}" + } + }, + { + "id": "812efaa205554c7bdcd80831", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\n[TestMethodOrderer(typeof(PriorityTestMethodOrderer))]\npublic class InitializationTest : Test\n{\n private static string _value;\n\n public InitializationTest(ITestOutputHelper output) : base(output) { }\n\n [Fact, Priority(0)]\n public void ShouldInitializeFirst()\n {\n var priority = new PriorityAttribute(0);\n Assert.Equal(0, priority.Priority);\n _value = \"ready\";\n }\n\n [Fact, Priority(1)]\n public void ShouldReadInitializedValue()\n {\n Assert.Equal(\"ready\", _value);\n }\n}" + } + }, + { + "id": "90a8cd444bd08a0115613e58", + "strategy": "repository", + "transports": [ + "native", + "docker" + ], + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactoryTest.Create_ShouldBootstrapApplication_WhenEntryPointUsesBootstrapperMinimalWorkerProgram", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0" + }, + { + "id": "927ca9f6a3bf893bc52887f4", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class MiddlewareTest : WebHostTest\n{\n public MiddlewareTest(ManagedWebHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)\n {\n }\n\n public override void ConfigureServices(IServiceCollection services)\n {\n services.AddFakeHttpContextAccessor();\n }\n\n public override void ConfigureApplication(IApplicationBuilder app)\n {\n app.UseMiddleware();\n }\n\n [Fact]\n public async Task Middleware_ShouldAddHeader()\n {\n var pipeline = Application.Build();\n var context = new DefaultHttpContext();\n await pipeline(context);\n Assert.True(context.Response.Headers.ContainsKey(\"X-Test\"));\n }\n}\n\npublic class TestMiddleware(RequestDelegate next)\n{\n public async Task InvokeAsync(HttpContext context)\n {\n context.Response.Headers[\"X-Test\"] = \"true\";\n await next(context);\n }\n}" + } + }, + { + "id": "947406357e3e26b26a71a538", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "Microsoft.AspNetCore.TestHost@10.0.15" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web", + "source": "using System;\nusing System.Net.Http;\nusing System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.TestHost;\n\nnamespace WebFixtureTests;\n\npublic class HttpClientExample\n{\n public async Task DemonstrateAsync(HttpClient client)\n {\n var response = await client.ToHttpResponseMessageAsync().ConfigureAwait(false);\n Console.WriteLine(response.StatusCode);\n }\n}\n\ninternal static class RunExample\n{\n static async Task Main()\n {\n using var app = WebHostTestFactory.Create(pipelineSetup: app => app.Run(context =>\n {\n context.Response.StatusCode = 202;\n return Task.CompletedTask;\n }));\n using var client = app.Host.GetTestClient();\n await new HttpClientExample().DemonstrateAsync(client);\n }\n}" + } + }, + { + "id": "9a558a9a581c6b11ccb28057", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.Logging;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class LogEntryExample\n{\n public string FormatEntry()\n {\n var entry = new XunitTestLoggerEntry(LogLevel.Warning, new EventId(1001, \"MyEvent\"), \"Something unexpected happened.\");\n return entry.ToString();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n Assert.Equal(\"Something unexpected happened.\", new LogEntryExample().FormatEntry());\n }\n}" + } + }, + { + "id": "9cdeb08f8ba8f3b361a98c58", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace WorkerServices.Tests;\n\npublic sealed class HostTestFactoryExample\n{\n public string ResolveWorkerStatus()\n {\n using var host = HostTestFactory.Create(\n services => services.AddSingleton(new WorkerStatus(\"ready\")));\n\n var status = host.Host.Services.GetRequiredService();\n return status.Value;\n }\n}\n\npublic sealed record WorkerStatus(string Value);\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n Assert.Equal(\"ready\", new HostTestFactoryExample().ResolveWorkerStatus());\n }\n}" + } + }, + { + "id": "a31971b360a8c557b87f6684", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ], + "source": "using System.Linq;\nusing Codebelt.Extensions.Xunit;\nusing Xunit;\n\nnamespace Example.Tests;\n\npublic class StoreExample\n{\n public bool HasMatchingItem()\n {\n var store = new InMemoryTestStore();\n store.Add(\"cached\");\n store.Add(\"other\");\n return store.Count == 2 && store.Query(value => value == \"cached\").Single() == \"cached\";\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n Assert.True(new StoreExample().HasMatchingItem());\n }\n}" + } + }, + { + "id": "b4149382f121a5ffc3c057df", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace MinimalWorkerLifecycle.Tests;\n\npublic sealed class SelfManagedMinimalHostFixtureExample\n{\n public async Task ConfigureBeforeStartingAsync()\n {\n using var host = MinimalHostTestFactory.Create(\n services => services.AddSingleton(new StartupState(\"configured\")),\n hostFixture: new SelfManagedMinimalHostFixture());\n\n var beforeStart = host.Host.Services.GetRequiredService();\n Assert.Equal(\"configured\", beforeStart.Value);\n\n await host.Host.StartAsync().ConfigureAwait(false);\n\n var afterStart = host.Host.Services.GetRequiredService();\n Assert.Same(beforeStart, afterStart);\n }\n}\n\npublic sealed record StartupState(string Value);\n\npublic sealed class RunExample\n{\n [Fact]\n public async Task ExercisesExample()\n {\n await new SelfManagedMinimalHostFixtureExample().ConfigureBeforeStartingAsync();\n }\n}" + } + }, + { + "id": "becb2fe7446fc1571dc86953", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class HostStateGuard\n{\n public bool EnsureFixtureIsReady(IMinimalHostFixture fixture)\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedMinimalHostFixture();\n Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture));\n using var app = MinimalHostTestFactory.Create(hostFixture: fixture);\n Assert.True(new HostStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "d565f9c40d015b247963fdee", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class BuilderConverter\n{\n public IHostBuilder Convert(IHostApplicationBuilder builder)\n {\n return builder.ToHostBuilder();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ReturnsTheWebHostBuilder()\n {\n var builder = WebApplication.CreateBuilder();\n Assert.Same(builder.Host, new BuilderConverter().Convert(builder));\n }\n}" + } + }, + { + "id": "d71e8ed85f1221cb41308b31", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace RequestPipeline.Tests;\n\npublic sealed class WebHostTestFactoryExample\n{\n public async Task InvokeStatusMiddlewareAsync()\n {\n using var response = await WebHostTestFactory.RunAsync(\n services => services.AddSingleton(new PipelineStatus(\"ready\")),\n app => app.Run(context =>\n {\n var status = context.RequestServices.GetRequiredService();\n return context.Response.WriteAsync(status.Value);\n })).ConfigureAwait(false);\n\n return await response.Content.ReadAsStringAsync().ConfigureAwait(false);\n }\n}\n\npublic sealed record PipelineStatus(string Value);\n\npublic sealed class RunExample\n{\n [Fact]\n public async Task ExercisesExample()\n {\n Assert.Equal(\"ready\", await new WebHostTestFactoryExample().InvokeStatusMiddlewareAsync());\n }\n}" + } + }, + { + "id": "dd2fa1a038dbc1220b366a53", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class WebMinimalHostStateGuard\n{\n public bool EnsureFixtureIsReady(IWebMinimalHostFixture fixture)\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedWebMinimalHostFixture();\n Assert.False(new WebMinimalHostStateGuard().EnsureFixtureIsReady(fixture));\n using var app = MinimalWebHostTestFactory.Create(hostFixture: fixture);\n Assert.True(new WebMinimalHostStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "dfdd064179bf4643e1a0b2bf", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class WebHostStateGuard\n{\n public bool EnsureFixtureIsReady(IWebHostFixture fixture)\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedWebHostFixture();\n Assert.False(new WebHostStateGuard().EnsureFixtureIsReady(fixture));\n using var app = WebHostTestFactory.Create(hostFixture: fixture);\n Assert.True(new WebHostStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "e3f79d1c0f2fa85276cee2fb", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15" + ], + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\n\nnamespace HostFixtureTests;\n\npublic class MinimalHostFactoryExample\n{\n public void Demonstrate()\n {\n using var host = MinimalHostTestFactory.Create(\n services => services.AddSingleton(new Version(1, 0, 0)));\n var version = host.Host.Services.GetRequiredService();\n Console.WriteLine(version);\n }\n}\n\ninternal static class RunExample\n{\n static void Main()\n {\n new MinimalHostFactoryExample().Demonstrate();\n }\n}" + } + }, + { + "id": "e7dbb5ba733b205469239b03", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class HostStateGuard\n{\n public bool EnsureFixtureIsReady(IApplicationFixture fixture) where TEntryPoint : class\n {\n return fixture.HasValidState();\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var fixture = new ManagedApplicationFixture();\n Assert.False(new HostStateGuard().EnsureFixtureIsReady(fixture));\n }\n}" + } + }, + { + "id": "f27f77d838407171b56f9073", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.AspNetCore.TestHost@10.0.15" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web", + "source": "// Program.cs\nusing System;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.AspNetCore.TestHost;\nusing Microsoft.Extensions.Hosting;\n\nusing var host = WebHostTestFactory.Create(\n pipelineSetup: app => app.Run(context =>\n context.Response.WriteAsync(\"started on demand\")),\n hostFixture: new SelfManagedWebHostFixture());\n\nawait host.Host.StartAsync().ConfigureAwait(false);\nusing var client = host.Host.GetTestClient();\n\nConsole.WriteLine(await client.GetStringAsync(\"/\").ConfigureAwait(false));" + } + }, + { + "id": "f3c0856195727da12ff2925f", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "source": "using Codebelt.Extensions.Xunit.Hosting.AspNetCore;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace WebFixtureTests;\n\npublic class ExampleFixture\n{\n public IServiceCollection ConfigureServices(IServiceCollection services)\n {\n return services.AddFakeHttpContextAccessor(ServiceLifetime.Scoped);\n }\n}\n\npublic sealed class RunExample\n{\n [Fact]\n public void ExercisesExample()\n {\n using var provider = new ExampleFixture().ConfigureServices(new ServiceCollection()).BuildServiceProvider();\n using var scope = provider.CreateScope();\n Assert.IsType(scope.ServiceProvider.GetRequiredService());\n }\n}" + } + }, + { + "id": "f5ed7c321a52580d7ce11408", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web", + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features;\n\nnamespace WebFixtureTests;\n\npublic class RequestFeatureExample\n{\n public void Demonstrate()\n {\n var request = new FakeHttpRequestFeature();\n Console.WriteLine(request.Method);\n }\n}\n\ninternal static class RunExample\n{\n static void Main()\n {\n new RequestFeatureExample().Demonstrate();\n }\n}" + } + }, + { + "id": "ff2e361441bdc3028ab188a9", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15" + ], + "source": "using System;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\n\nnamespace WorkerApp.Tests;\n\npublic sealed class ApplicationHostFactoryExample\n{\n public string GetTestIdentity()\n {\n using IHost host = ApplicationHostFactory.Create(builder =>\n {\n builder.ConfigureServices(services =>\n services.AddSingleton(new WorkerIdentity(\"Test inventory worker\")));\n });\n\n var identity = host.Services.GetRequiredService();\n return identity.Name;\n }\n}\n\npublic sealed record WorkerIdentity(string Name);\n\npublic sealed class WorkerProgram\n{\n public static IHostBuilder CreateHostBuilder(string[] args)\n {\n return Host.CreateDefaultBuilder(args);\n }\n\n public static void Main(string[] args)\n {\n var identity = new ApplicationHostFactoryExample().GetTestIdentity();\n if (identity != \"Test inventory worker\")\n {\n throw new InvalidOperationException(identity);\n }\n\n Console.WriteLine(identity);\n }\n}" + } + }, + { + "id": "aa478d74f298d8c98e6cd1bf", + "strategy": "standalone", + "transports": [ + "native", + "docker" + ], + "image": "codebeltnet/csrun:10", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "source": "using System.Threading;\nusing System.Threading.Tasks;\nusing Codebelt.Extensions.Xunit.Hosting;\nusing Microsoft.Extensions.DependencyInjection;\nusing Microsoft.Extensions.Hosting;\nusing Xunit;\n\nnamespace HostFixtureTests;\n\npublic class BackgroundServiceTest : HostTest\n{\n public BackgroundServiceTest(ManagedHostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output)\n {\n }\n\n public override void ConfigureServices(IServiceCollection services)\n {\n services.AddHostedService();\n services.AddXunitTestLogging();\n }\n\n [Fact]\n public void Host_ShouldBeRunning()\n {\n Assert.NotNull(Host);\n }\n}\n\npublic class TestWorker : BackgroundService\n{\n protected override async Task ExecuteAsync(CancellationToken stoppingToken)\n {\n while (!stoppingToken.IsCancellationRequested)\n {\n await Task.Delay(100, stoppingToken);\n }\n }\n}" + } + } + ] +} diff --git a/.docfx/run-actions.settings.json b/.docfx/run-actions.settings.json new file mode 100644 index 0000000..7309321 --- /dev/null +++ b/.docfx/run-actions.settings.json @@ -0,0 +1,629 @@ +{ + "examples": [ + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ApplicationFixtureExtensions", + "sourceSha256": "90B08550FC34DE0144BF28F6ADB2577A59AEC596EB8B6060D545A9B56CD34377", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ApplicationHostFactory", + "sourceSha256": "42FEDED83B95259C5771DBE3B83C0323599941985C3D71B510F80C1448BB3771", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactory", + "sourceSha256": "7473E8AE20820AD58942D6212B5A7DCD428922FD0EEF1985E7D05F9CAC6E8D23", + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.ApplicationTestFactoryTest.Create_ShouldBootstrapApplication_WhenEntryPointUsesBootstrapperMinimalWorkerProgram", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0", + "explanation": "The scripts run the maintained worker integration test and verify its registered marker and Development environment." + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.BlockingManagedWebHostFixture", + "sourceSha256": "CD729B010424B55A26B7607AC78059BC5F610C522C2DCF312E7AD6A8A602E7FC", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.HostBuilderApplicationExtensions", + "sourceSha256": "340FBC3BD83E80B5B8AD6FAA66020C285458A08A608961D7D33BFA1B841FEFF4", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.FakeHttpContextAccessor", + "sourceSha256": "DCFB8604280E9AC15FFABA700B4055745F26AB9AD9E2F25C3A455EB50AEE7376", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web" + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpRequestFeature", + "sourceSha256": "A68A4CA3ACD2C8F668D4D343A9B36AB6E84D6CC1B506473700E973B97D053B94", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web" + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http.Features.FakeHttpResponseFeature", + "sourceSha256": "7549EF36EB77D3203099D1DFEF5584A8AAEBD3ED8E537D6BF752D3231191C33D", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web" + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.HttpClientExtensions", + "sourceSha256": "FABF1EB669FF7CC6B2BDB803E7CC6120EF9FE117823C720690A57522435C1468", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "Microsoft.AspNetCore.TestHost@10.0.15" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web" + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebApplicationFixture`1", + "sourceSha256": "8A75CECB985C8FCE6F9C0C1211311D40867D82B83ED060008D75E7A3F963EFE3", + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestTest.ShouldBootstrapApplication_WhenEntryPointUsesModernProgramPattern", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0", + "explanation": "The scripts start the maintained ASP.NET Core application through the same fixture and verify its HTTP response." + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebHostFixture", + "sourceSha256": "2CC0B80DE03471AD6DD8210B4FDF2FA037751EF8B38AD43B1C611FC553EDA979", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.ManagedWebMinimalHostFixture", + "sourceSha256": "9D12413E06F45213763C5BAD14B3B2796097B1F773D18BDA1F8CBF90F7CF1268", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.MinimalWebHostTestFactory", + "sourceSha256": "869F4EDAF75D120A8A7F73B37C8E87002B0B006BABF480ECA0BFDCD5939E1F73", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebHostFixture", + "sourceSha256": "8C67EA9DD2F57A0DB37E7EE5E5516CE5655B61EE90C4097CFAE7EC8CD9B9F59D", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.AspNetCore.TestHost@10.0.15" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ], + "sdk": "Microsoft.NET.Sdk.Web" + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.SelfManagedWebMinimalHostFixture", + "sourceSha256": "BD4DED8434BE4E8F5C88402103358DBCC12C4548C89FC48C060587BDB9CE3C5C", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "Microsoft.AspNetCore.TestHost@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.ServiceCollectionExtensions", + "sourceSha256": "FFE4DD6394228DC8E7DF1EF37C5377AF341AD84C0E18D3B83CFE51ED671CC8F0", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationFixtureExtensions", + "sourceSha256": "9C8A41C5E80934D69DF60798533A7E8BE07CA4210608BBDD2230C757179A8EC5", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactory", + "sourceSha256": "1DB1DAAA9965BF42F736A4BC3788B4261DF4EF52799B83E6F733AB1BD53EA7D3", + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.AspNetCore.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebApplicationTestFactoryTest.Create_ShouldApplyWebHostConfiguration_WhenWebHostSetupIsProvided", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0", + "explanation": "The scripts run the maintained integration test, which overrides services and configuration and verifies the results through HTTP endpoints." + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostFixtureExtensions", + "sourceSha256": "CEDFFF39E914FF47421AE5A4F37CA1564DCAC8252903585B3B53DB069663492B", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebHostTestFactory", + "sourceSha256": "F2DCAE2A6B67B77ADED3A2B726B4ABA20276D3C0FBDFB57F153447D8312005EE", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.AspNetCore.WebMinimalHostFixtureExtensions", + "sourceSha256": "F30F392FC9E68CBA4BCCB949F0CF36307DCC6A0FFF2DEA05F4641ACB4EA13900", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting.AspNetCore@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ], + "frameworkReferences": [ + "Microsoft.AspNetCore.App" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.GenericHostFixtureExtensions", + "sourceSha256": "6DA99A91947A5C64953DDD8F7B42EC74AE39C3EDFBF9F2DB69A31B9B2D0B90AC", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.HostTestFactory", + "sourceSha256": "DBB1A94CF50D0C71616D4482DFD2FF1A4D5F8EA387340B6D4C98A5A4F84E6652", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.LoggerExtensions", + "sourceSha256": "D2C65C928AF86623AF7F8B754C254F1A64B7FEB61F6168559FD1FC1862A08DEB", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ManagedApplicationFixture`1", + "sourceSha256": "47B0C1FBA94E7B43C8753D0A8242801B328E6B463B6EEDAEB640D4F8A262633E", + "repository": "codebeltnet/xunit", + "commit": "84b13767cb9484f8f3a36a71875662edfdb3e511", + "project": "test/Codebelt.Extensions.Xunit.Hosting.FunctionalTests/Codebelt.Extensions.Xunit.Hosting.FunctionalTests.csproj", + "test": "Codebelt.Extensions.Xunit.Hosting.BootstrapperMinimalWorkerApplicationTestTest.ShouldBootstrapMinimalWorkerProgram", + "framework": "net11.0", + "image": "mcr.microsoft.com/dotnet/sdk:11.0", + "explanation": "The scripts run this test in its original application and test projects." + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ManagedHostFixture", + "sourceSha256": "6F9E6E2F82AB916A7A36CC2259AA97366A800843E8B1913EE7C2D79580861DA8", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ManagedMinimalHostFixture", + "sourceSha256": "D0D64093FAF614E7658650534934F6771BB45486D43E7A241D573347840E6DBE", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.MinimalHostFixtureExtensions", + "sourceSha256": "47A5CB15CC0563C81176ADE58748B75704DA88BCA3549BEF914BD63CED52125C", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.MinimalHostTestFactory", + "sourceSha256": "45A7CCD7F1EF9A48A33565AEAC7B5A005AD4AA11E12ADD506911B10614205E87", + "manifest": { + "schemaVersion": 1, + "mode": "console", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.SelfManagedHostFixture", + "sourceSha256": "7B4FC8E01BFCFACAF488EB329E5F50B3F9EEB7F42BF26D59D54C6F69754FB32B", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.SelfManagedMinimalHostFixture", + "sourceSha256": "E1641265DF178540A21BD769CA1A9CD162901D03813C9D723B18349652B19A6B", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ServiceCollectionExtensions", + "sourceSha256": "96463CFB4DADE2AA027CBD21C1A8E380C83914669832CEE2C447DEDDCCAFC9C6", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.ServiceProviderExtensions", + "sourceSha256": "C9C4438BD3D356FA0C39F5F86FAF6E984D9A1253A0A5D8EAEAD280AAAB31569B", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.Hosting.XunitTestLoggerEntry", + "sourceSha256": "5DBC97E4CD56C7D3072FE73E9BBA6F90326CFE7952A57823024464DA85802D3C", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit.Hosting@13.0.0", + "Microsoft.Extensions.Hosting@10.0.15", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.InMemoryTestStore`1", + "sourceSha256": "71987946D4476C5106392E6DB007FE7B11CFE39D4EAA4CA1B04539D1EC7C7F7C", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.PriorityAttribute", + "sourceSha256": "93FF0CA8DBB21BE3475B9DED2131644055C82C6BF81A6D5F51DE91564C44FD78", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.PriorityTestMethodOrderer", + "sourceSha256": "8A21672EB35CB508A5A70D51D8813A009DE6C9B7099E766FDA6BBF8A6DA360BF", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.TestOutputHelperAccessor", + "sourceSha256": "4C6461C6EBDE9468850148117F4972F3C9C25E6F22138521AAB7852B60162109", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.TestOutputHelperExtensions", + "sourceSha256": "BE11774854DE0AF823285BDCAD5BF6B02FD6CFF9D1673B10C6F0CE3D043E5799", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines(Xunit.ITestOutputHelper,System.Object[])", + "sourceSha256": "985FBA10ABE737D5BEE72A19B028BCA6739A84C7B790695AEEC66BCC73BE7713", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines``1(Xunit.ITestOutputHelper,``0[])", + "sourceSha256": "32E90B18345F4AF2EDBA67EDA4F5D6B231292147F40B9B541243F22A2DE71426", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.TestOutputHelperExtensions.WriteLines``1(Xunit.ITestOutputHelper,System.Collections.Generic.IEnumerable{``0})", + "sourceSha256": "6BF4CBD17324584A087D6EF92F873474DD288AA42EAB5DB33665CADCFEF49734", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + }, + { + "uid": "Codebelt.Extensions.Xunit.WildcardOptions", + "sourceSha256": "9E421444D2AB0A979A150637043D0070DCB60D5517C3E595AB902F7C3A7A17E9", + "manifest": { + "schemaVersion": 1, + "mode": "test", + "framework": "net10.0", + "dependsOn": [ + "Codebelt.Extensions.Xunit@13.0.0", + "xunit.v3@4.0.3" + ] + } + } + ] +} diff --git a/.docfx/templates/modern/public/main.js b/.docfx/templates/modern/public/main.js index 520a512..15800c8 100644 --- a/.docfx/templates/modern/public/main.js +++ b/.docfx/templates/modern/public/main.js @@ -10,3 +10,5 @@ export default { document.body.appendChild(script); } }; + +import './run-actions.js'; diff --git a/.docfx/templates/modern/public/run-actions.js b/.docfx/templates/modern/public/run-actions.js new file mode 100644 index 0000000..6f57db6 --- /dev/null +++ b/.docfx/templates/modern/public/run-actions.js @@ -0,0 +1,270 @@ +// Optional modern-template enhancement. The association remains usable without JavaScript. +const icons = { + native: '' + + '', + docker: '' + + '', +}; +const waitingForCopy = new WeakSet(); +// Generated scripts are one complete `& { ... }` paste unit, so execution and verification run together. +const executionScript = /^& \{\r?\n#requires -Version 7\.0\r?\n[\s\S]*\r?\n\}\r?\n?$/; + +async function fetchScript(link) { + const url = new URL(link.href); + if (url.origin !== location.origin) throw new Error('Script must be hosted on this site.'); + // Asset URLs are stable per example, so always revalidate rather than copy a stale cached script. + const response = await fetch(url, { mode: 'same-origin', cache: 'no-cache' }); + if (!response.ok) throw new Error('Script unavailable.'); + const script = await response.text(); + if (!executionScript.test(script)) throw new Error('Response is not an execution script.'); + return script; +} + +function previewScript(script, label) { + const dialog = document.createElement('dialog'); + dialog.className = 'docfx-run-preview'; + dialog.setAttribute('aria-label', label + ' run script'); + const heading = document.createElement('h2'); + heading.textContent = label + ' run script'; + const source = document.createElement('pre'); + source.tabIndex = 0; + source.textContent = script; + const close = document.createElement('button'); + close.type = 'button'; + close.className = 'btn btn-secondary'; + close.textContent = 'Close'; + close.addEventListener('click', () => dialog.close()); + dialog.addEventListener('close', () => dialog.remove(), { once: true }); + dialog.append(heading, source, close); + document.body.append(dialog); + dialog.showModal(); +} + +function createAction(link, report, onCopyFailure) { + const transport = link.dataset.transport; + const label = transport === 'native' ? 'Native' : 'Docker'; + const name = 'Copy ' + label + ' run script'; + const button = document.createElement('button'); + button.type = 'button'; + button.className = 'btn border-0 docfx-run-copy'; + button.title = name + '\nShift-click or right-click to preview'; + button.setAttribute('aria-label', name); + button.setAttribute('aria-description', 'Press Shift+Enter to preview the PowerShell script.'); + button.innerHTML = ''; + const icon = button.firstElementChild; + const check = document.createElement('i'); + check.className = 'bi bi-check-lg'; + check.setAttribute('aria-hidden', 'true'); + + let pending = false; + let resetIcon; + async function act(preview) { + if (pending) return; + pending = true; + report(''); + try { + const script = fetchScript(link); + if (preview) { + previewScript(await script, label); + } else { + // Start the clipboard write during the user's gesture, including while the fetch is pending. + const clipboard = navigator.clipboard; + if (clipboard?.write && typeof ClipboardItem === 'function') { + const text = script.then(value => new Blob([value], { type: 'text/plain' })); + await Promise.all([text, clipboard.write([new ClipboardItem({ 'text/plain': text })])]); + } else { + const text = await script; + await clipboard.writeText(text); + } + clearTimeout(resetIcon); + // Measure DocFX's success markup in the same code block so template overrides apply. + const reference = document.createElement('a'); + reference.className = 'btn border-0 link-success code-action'; + reference.hidden = true; + reference.setAttribute('aria-hidden', 'true'); + reference.style.transition = 'none'; + const referenceIcon = check.cloneNode(false); + referenceIcon.removeAttribute('style'); + reference.append(referenceIcon); + button.closest('pre').prepend(reference); + const appearance = getComputedStyle(referenceIcon, '::before'); + check.style.color = appearance.color; + check.style.fontSize = appearance.fontSize; + reference.remove(); + button.replaceChildren(check); + resetIcon = setTimeout(() => button.replaceChildren(icon), 1000); + report(label + ' script copied.', true); + } + } catch { + if (!preview) onCopyFailure?.(); + report('Could not ' + (preview ? 'preview ' : 'copy ') + label + ' script.'); + } finally { + pending = false; + } + } + + button.addEventListener('click', event => { void act(event.shiftKey); }); + button.addEventListener('contextmenu', event => { + event.preventDefault(); + void act(true); + }); + button.addEventListener('keydown', event => { + if (event.shiftKey && event.key === 'Enter') { + event.preventDefault(); + void act(true); + } + }); + return button; +} + +export function enhanceRunActions(root = document) { + for (const links of root.querySelectorAll('.docfx-run-actions:not([data-enhanced])')) { + const previous = links.previousElementSibling; + const pre = previous?.matches('pre') ? previous : previous?.querySelector('pre'); + if (!pre?.querySelector(':scope > code:is(.lang-csharp, .language-csharp, .lang-cs, .language-cs)')) continue; + const assets = [...links.querySelectorAll('a[data-transport="native"], a[data-transport="docker"]')]; + if (!assets.length) continue; + + // DocFX imports the custom module before rendering its Lit-managed copy anchor. + if (!pre.querySelector(':scope > a.code-action')) { + if (waitingForCopy.has(pre)) continue; + waitingForCopy.add(pre); + const observer = new MutationObserver(() => { + if (!pre.querySelector(':scope > a.code-action')) return; + observer.disconnect(); + waitingForCopy.delete(pre); + attachToolbar(pre, links, assets); + }); + observer.observe(pre, { childList: true }); + continue; + } + + attachToolbar(pre, links, assets); + } +} + +function attachToolbar(pre, links, assets) { + if ('enhanced' in links.dataset) return; + const toolbar = document.createElement('span'); + toolbar.className = 'docfx-run-toolbar'; + toolbar.setAttribute('role', 'group'); + toolbar.setAttribute('aria-label', 'Run scripts'); + const status = document.createElement('span'); + status.setAttribute('role', 'status'); + status.className = 'docfx-run-status'; + let clearStatus; + function report(message, visuallyHidden = false) { + clearTimeout(clearStatus); + status.classList.toggle('visually-hidden', visuallyHidden); + status.textContent = message; + if (message) clearStatus = setTimeout(() => { status.textContent = ''; }, 3000); + } + toolbar.append(...assets.map(link => createAction(link, report, () => { links.hidden = false; }))); + // Keep our nodes before DocFX's Lit render range, which replaces the original anchor on copy. + pre.prepend(toolbar, status); + pre.classList.add('docfx-runnable'); + links.dataset.enhanced = 'true'; + // Keep the recipe explanation visible when the toolbar replaces the fallback links. + links.after(...links.querySelectorAll(':scope > p')); + links.hidden = true; +} + +if (typeof document !== 'undefined') { + const style = document.createElement('style'); + style.textContent = ` +pre.docfx-runnable { + --run-action-size: 2.25rem; +} +.docfx-run-icon-native { + color: #926bbb; +} +.docfx-run-icon-docker { + color: #4d79d7; +} +.docfx-run-play { + color: #628b2f; +} +pre.docfx-runnable > .code-action, +.docfx-run-toolbar { + display: flex; + position: absolute; + top: .25rem; + opacity: 0; + pointer-events: none; + z-index: 1; +} +pre.docfx-runnable > .code-action, +.docfx-run-copy { + align-items: center; + justify-content: center; + inline-size: var(--run-action-size); + block-size: var(--run-action-size); + padding: 0; + background-color: var(--bs-body-bg); +} +.docfx-run-toolbar { + right: calc(.35rem + var(--run-action-size)); + gap: .15rem; +} +.docfx-run-copy { + display: inline-flex; +} +.docfx-run-copy .bi-check-lg { + pointer-events: none; +} +.docfx-run-copy:hover { + background-color: var(--bs-tertiary-bg); +} +pre.docfx-runnable:hover > :is(.code-action, .docfx-run-toolbar), +pre.docfx-runnable:focus-within > :is(.code-action, .docfx-run-toolbar) { + opacity: 1; + pointer-events: auto; +} +pre.docfx-runnable > .code-action:focus-visible, +.docfx-run-copy:focus-visible { + outline: 2px solid currentColor; + outline-offset: -2px; +} +.docfx-run-status { + position: absolute; + z-index: 1; + top: .25rem; + left: .25rem; + max-inline-size: calc(100% - 3 * var(--run-action-size) - 1rem); + white-space: normal; + pointer-events: none; +} +.docfx-run-status:not(:empty) { + padding: .3rem .5rem; + border-radius: .25rem; + background: var(--bs-body-bg); + color: var(--bs-body-color); +} +.docfx-run-preview { + inline-size: min(52rem, 94vw); + padding: 1rem; + color: var(--bs-body-color); + background: var(--bs-body-bg); + border: 1px solid var(--bs-border-color); + border-radius: .5rem; +} +.docfx-run-preview::backdrop { + background: rgb(0 0 0 / 45%); +} +.docfx-run-preview pre { + max-block-size: 65vh; + padding: .75rem; + background: var(--bs-tertiary-bg); +} +@media (hover: none), (any-pointer: coarse) { + pre.docfx-runnable > :is(.code-action, .docfx-run-toolbar) { + opacity: 1; + pointer-events: auto; + } +} +`; + document.head.append(style); + if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => enhanceRunActions(), { once: true }); + else enhanceRunActions(); +} diff --git a/.gitignore b/.gitignore index 03ef557..79d58eb 100644 --- a/.gitignore +++ b/.gitignore @@ -367,6 +367,7 @@ FodyWeavers.xsd /.docfx/api/**/*.yml /.docfx/**/*.manifest /.docfx/.vscode/docfx-assistant +/.docfx/run-actions/ ### VisualStudioCode ### .vscode/* diff --git a/AGENTS.md b/AGENTS.md index 38aa2d6..d9043a2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -294,7 +294,6 @@ Follow the scoped guidance in this file: - [Writing XML documentation](#writing-xml-documentation) - ## DocFX Documentation Maintenance When changing public .NET APIs, keep the DocFX documentation current in the same change set. @@ -323,7 +322,7 @@ Both namespace overwrite files and type overwrite files are required deliverable `docfx.json` must keep namespace and type overwrite files in separate subdirectories. `build.overwrite` must include both `api/namespaces/**/*.md` (for namespace pages) and `api/types/**/*.md` (for type pages). `build.content` must exclude both `api/namespaces/**` and `api/types/**` to prevent overwrite Markdown from being treated as conceptual content. Do not use `api/**/*.md` under `build.overwrite` or `build.content`. -Availability must be documented by referencing the appropriate include file when one exists, or by adding explicit availability text when no suitable include exists. Availability must reflect the actual target frameworks, conditional compilation, and project configuration. +Availability must be documented on namespace overview pages under `.docfx/api/namespaces/*` by referencing the appropriate `[!INCLUDE ...]` file when one exists, or by adding explicit availability text when no suitable include exists. Under `.docfx/api/`, `[!INCLUDE ...]` directives are only allowed in `.docfx/api/namespaces/*` — never on type pages (`.docfx/api/types/*`), never in other files under `.docfx/api/`, and never after examples. Only modify DocFX Markdown files under `.docfx/api/`; leave Markdown files outside `.docfx/api/` untouched. Availability must reflect the actual target frameworks, conditional compilation, and project configuration. For conditionally compiled APIs, choose the executable test framework from the asset that contains the API. Inspect the preprocessor condition, project TFMs, package `lib/` assets, and resolved consumer asset before changing a sample. For APIs under `NETSTANDARD2_0` or `NETSTANDARD2_0_OR_GREATER`, when modern `lib/netX.0/` assets also exist, use `net48` (or another supported .NET Framework target from `net462` onward) so the consumer selects `lib/netstandard2.0/`. Never use `netstandard*` as an executable target, and never use a modern `netX.0` target when it selects an asset where the API is absent. For other TFM guards, select a runnable consumer TFM that resolves to the containing asset and confirm that selection from restore or build evidence. @@ -343,9 +342,7 @@ Before completing documentation work, run the relevant verification commands, no ```bash dotnet build - dotnet test - dotnet run --file /scripts/docfx.cs -- --repo-root . --build-api-model --validate-samples --verify-docfx-build ``` @@ -354,7 +351,6 @@ Codebelt repositories are normally strong-name signed with a `.snk` file in the The final DocFX verification must run outside the working tree when possible. The `--verify-docfx-build` option copies the repository to a temp workspace, runs DocFX against the resolved `docfx.json` there, and removes the temp workspace afterward so generated API YAML, manifest files, and site output do not flood git status. Do not call the work complete until the final JSON reports `summary.fullVerificationRan: true`, `summary.canClaimCompletion: true`, `summary.remainingWorkItems: 0`, an empty `summary.remainingGates`, an empty `summary.remainingDiagnosticsByCode`, `summary.newlyIntroducedSkipMarkers: 0`, and `summary.interimArtifacts: 0`. If a command cannot be run, report the exact limitation or failure instead of claiming the documentation was verified. - ## Writing Unit Tests