Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .docfx/Dockerfile.docfx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG NGINX_VERSION=1.31-alpine
ARG NGINX_VERSION=1.31-alpine

FROM --platform=$BUILDPLATFORM nginx:${NGINX_VERSION} AS base
RUN rm -rf /usr/share/nginx/html/*

FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2.78.4 AS build
FROM --platform=$BUILDPLATFORM codebeltnet/docfx:2.78.5 AS build

ADD [".", "docfx"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Complements: [ASP.NET Core integration tests](https://learn.microsoft.com/en-us/
|---|---|---|
|Bootstrap an existing ASP.NET Core application for one focused test|`WebApplicationTestFactory.Create<TEntryPoint>`|Returns an owned `IHostTest` whose host exposes the application's `TestServer`, services, configuration, and environment.|
|Send one request to an existing application|`WebApplicationTestFactory.RunAsync<TEntryPoint>`|Combines application startup, `HttpClient` creation, request execution, and cleanup in one call.|
|Share an existing application across an xUnit test class|`WebApplicationTest<TEntryPoint, TFixture>` with `ManagedWebApplicationFixture<TEntryPoint>`|Opt-in entrypoint-owned startup while the fixture exposes `TestServer`.|
|Share an existing application across an xUnit test class|`WebApplicationTest<TEntryPoint, TFixture>` with `ManagedWebApplicationFixture<TEntryPoint>`|Uses entrypoint-owned startup while the fixture exposes `TestServer`.|
|Define services and middleware entirely inside the test|`WebHostTestFactory` or `MinimalWebHostTestFactory`|Builds a purpose-specific in-memory pipeline without loading an application project.|
|Attach observers or change state before startup|A `SelfManaged` web fixture|Builds the host and pipeline but leaves startup to the test.|

Expand All @@ -41,11 +41,10 @@ ASP.NET Core host fixtures follow the same lifecycle naming convention as the ho
|---|---|
|`Managed`|The fixture owns host creation, configuration and disposal while the application entry point owns startup; test-host consumption starts the deferred host when needed.|
|`SelfManaged`|The fixture owns host creation and configuration, but leaves host startup to the test.|
|`BlockingManaged`|The fixture owns the host lifecycle and starts the host synchronously before returning control to the test.|

For the current minor release, the existing `WebApplicationTestFactory` and blocking fixture paths preserve legacy startup behavior. Use `ManagedWebApplicationFixture<TEntryPoint>` explicitly when the real `Main` method should own startup; fixture setup remains lazy and test-host consumption starts the deferred host. `BlockingManagedWebApplicationFixture<TEntryPoint>` remains available as an obsolete compatibility fixture and should be removed or changed in the next major release.

`BlockingManagedWebHostFixture` remains the opt-in blocking variant for the lower-level web host fixture family. The application-entry-point fixture is named `BlockingManagedWebApplicationFixture<TEntryPoint>` directly because this API is blocking by convention from its first release.

`WebApplicationTestFactory` uses `ManagedWebApplicationFixture<TEntryPoint>` by default, so the real application entry point owns startup and fixture setup remains lazy. Use `ManagedWebApplicationFixture<TEntryPoint>` explicitly with `WebApplicationTest<TEntryPoint, TFixture>` when tests share the application context; use a `SelfManaged` fixture when the test must control startup itself.

`BlockingManagedWebHostFixture` remains the opt-in blocking variant for the lower-level web host fixture family. It is separate from the application-entry-point fixture, which uses `ManagedWebApplicationFixture<TEntryPoint>` for entrypoint-owned startup.

### Extension Members

Expand Down
7 changes: 3 additions & 4 deletions .docfx/api/namespaces/Codebelt.Extensions.Xunit.Hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Complements: [xUnit: Shared Context between Tests](https://xunit.net/docs/shared
|When you need to|Start with|Why|
|---|---|---|
|Bootstrap an existing console, worker, or Generic Host application for one test|`ApplicationTestFactory.Create<TEntryPoint>`|Runs the application's entry-point setup and returns an owned `IHostTest` context that the caller disposes.|
|Share an existing application across an xUnit test class|`ApplicationTest<TEntryPoint, TFixture>` with `ManagedApplicationFixture<TEntryPoint>`|Opt-in entrypoint-owned startup through the new managed fixture while retaining configuration and service access.|
|Share an existing application across an xUnit test class|`ApplicationTest<TEntryPoint, TFixture>` with `ManagedApplicationFixture<TEntryPoint>`|Uses entrypoint-owned startup while retaining configuration and service access.|
|Build a conventional Generic Host entirely inside the test|`HostTestFactory`|Configures `IServiceCollection` and `IHostBuilder` directly without requiring an application entry point.|
|Build with the modern `IHostApplicationBuilder` model|`MinimalHostTestFactory`|Keeps minimal-host tests focused on services and application-builder configuration.|
|Configure the host now but decide when it starts|A `SelfManaged` fixture|Leaves startup under test control so observers and pre-start assertions can be attached first.|
Expand All @@ -29,9 +29,8 @@ Host fixtures follow a lifecycle naming convention:
|---|---|
|`Managed`|The fixture owns host creation, configuration and disposal while the application entry point owns startup; test-host consumption starts the deferred host when needed.|
|`SelfManaged`|The fixture owns host creation and configuration, but leaves host startup to the test.|
|`BlockingManaged`|The fixture owns the host lifecycle and starts the host synchronously before returning control to the test.|

For the current minor release, the existing `ApplicationTestFactory` and blocking fixture paths preserve legacy startup behavior. Use `ManagedApplicationFixture<TEntryPoint>` explicitly when the real `Main` method should own startup; fixture setup remains lazy and test-host consumption starts the deferred host. `BlockingManagedApplicationFixture<TEntryPoint>` remains available as an obsolete compatibility fixture and should be removed or changed in the next major release.

`ApplicationTestFactory` uses `ManagedApplicationFixture<TEntryPoint>` by default, so the real application entry point owns startup and fixture setup remains lazy. Use `ManagedApplicationFixture<TEntryPoint>` explicitly with `ApplicationTest<TEntryPoint, TFixture>` when tests share the application context; use a `SelfManaged` fixture when the test must control startup itself.

### Extension Members

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example:
- *content
---

The test project references a worker application's entry-point assembly. `ApplicationHostFactory.Create<TEntryPoint>` preserves the current minor-release compatibility path, including direct use of an application's `CreateHostBuilder` when it is available. When the application entry point should own startup, pass `ManagedApplicationFixture<TEntryPoint>` to `ApplicationTestFactory.Create<TEntryPoint>`; the fixture opts into the deferred path without changing the existing factory method signature. The compatibility path is intentionally retained until it can be removed or changed in the next major release. Because this lower-level factory returns the host directly, the caller still owns disposal.
The test project references a worker application's entry-point assembly. `ApplicationHostFactory.Create<TEntryPoint>` preserves the compatibility path, including direct use of an application's `CreateHostBuilder` when it is available. `ApplicationTestFactory.Create<TEntryPoint>` uses `ManagedApplicationFixture<TEntryPoint>` 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.

```csharp
using Codebelt.Extensions.Xunit.Hosting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example:
- *content
---

The test project references a worker application whose entry point registers `WorkerIdentity`. `ApplicationTestFactory` runs that application's real host setup, then exposes its services and environment through an owned test context so the test can verify application behavior without recreating `Program` configuration.
The test project references a worker application whose entry point registers `WorkerIdentity`. `ApplicationTestFactory` uses `ManagedApplicationFixture<TEntryPoint>` 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<TEntryPoint>` when the test needs a different lifecycle.

```csharp
using Codebelt.Extensions.Xunit.Hosting;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example:
- *content
---

Use `ManagedWebApplicationFixture<TEntryPoint>` 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<TEntryPoint,T>` and pass the fixture to its base constructor so the base class initializes the fixture through `ConfigureHost` before the test reads `Server`. This is an opt-in path for the current minor release. 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. The legacy blocking path is retained for compatibility until it can be removed or changed in the next major release.
Use `ManagedWebApplicationFixture<TEntryPoint>` 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<TEntryPoint,T>` 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.

```csharp
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example:
- *content
---

The test project references a minimal ASP.NET Core application with a `/health` endpoint. `WebApplicationTestFactory` 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.
The test project references a minimal ASP.NET Core application with a `/health` endpoint. `WebApplicationTestFactory` uses `ManagedWebApplicationFixture<TEntryPoint>` 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<TEntryPoint>` when the test needs a different lifecycle.

```csharp
using System.Threading.Tasks;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ example:
- *content
---

Use `ManagedApplicationFixture<TEntryPoint>` 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<TEntryPoint,T>` and pass the fixture to its base constructor so the base class initializes the fixture through `ConfigureHost` before the test reads `Host`. This is an opt-in path for the current minor release. Fixture setup remains lazy; accessing the test host starts the deferred host and surfaces startup failures at the point the test consumes it. The legacy blocking path is retained for compatibility until it can be removed or changed in the next major release.
Use `ManagedApplicationFixture<TEntryPoint>` 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<TEntryPoint,T>` 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.

```csharp
using Codebelt.Extensions.Xunit.Hosting;
Expand Down
13 changes: 1 addition & 12 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ dotnet_diagnostic.IDE0078.severity = none
[*.{cs,vb}]
dotnet_diagnostic.IDE0290.severity = none

# CA1200: Avoid using cref tags with a prefix
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1200
[*.{cs,vb}]
dotnet_diagnostic.CA1200.severity = none

# IDE0305: Use collection expression for fluent
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0305
[*.{cs,vb}]
Expand Down Expand Up @@ -176,12 +171,6 @@ dotnet_diagnostic.IDE0032.severity = none

# Order modifiers
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0036
# Excluded because of inconsistency with other analyzers
# Excluded becuase of inconsistency with other analyzers

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Analyzer comment spelling error

The edited rationale spells “because” as “becuase,” reducing the clarity of the repository-wide analyzer configuration.

Suggested change
# Excluded becuase of inconsistency with other analyzers
# Excluded because of inconsistency with other analyzers
Prompt To Fix With AI
This is a comment left during a code review.
Path: .editorconfig
Line: 174

Comment:
**Analyzer comment spelling error**

The edited rationale spells “because” as “becuase,” reducing the clarity of the repository-wide analyzer configuration.

```suggestion
# Excluded because of inconsistency with other analyzers
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex

[*.{cs,vb}]
dotnet_diagnostic.IDE0036.severity = none

# Use 'System.Threading.Lock'
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0330
# Excluded while TFMs are less than net9.0
[*.{cs,vb}]
dotnet_diagnostic.IDE0330.severity = none
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
Loading
Loading