Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Hosting.Testing;

/// <summary>
/// Unit testing friendly configured host.
/// </summary>
[Experimental(diagnosticId: Experiments.Hosting, UrlFormat = Experiments.UrlFormat)]
public sealed class FakeHost : IHost
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Hosting.Testing;

/// <summary>
/// Options to configure <see cref="FakeHost"/>.
/// </summary>
[Experimental(diagnosticId: Experiments.Hosting, UrlFormat = Experiments.UrlFormat)]
public class FakeHostOptions
{
/// <summary>
Expand Down
53 changes: 52 additions & 1 deletion src/Libraries/Microsoft.Extensions.Hosting.Testing/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
README
# Microsoft.Extensions.Hosting.Testing

Tools for integration test hosting and related test oriented helpers.

## Install the package

From the command-line:

```dotnetcli
dotnet add package Microsoft.Extensions.Hosting.Testing
```

Or directly in the C# project file:

```xml
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Testing" Version="[CURRENTVERSION]" />
</ItemGroup>
```

## Usage Example

### FakeHost

`FakeHost` enables creating an application host pre-configured for a unit test environment.

The host can be created using the following APIs:

```csharp
public static IHostBuilder CreateBuilder()
public static IHostBuilder CreateBuilder(Action<FakeHostOptions> configure)
public static IHostBuilder CreateBuilder(FakeHostOptions options)
```

For example:

```csharp
using var host = await FakeHost.CreateBuilder(options => { });
.ConfigureServices(x =>
{
// ...
})
.StartAsync();
```

### FakeHostingExtensions

`FakeHostingExtensions` is a collection of [`IHost`](https://learn.microsoft.com/dotnet/api/microsoft.extensions.hosting.ihost) and [`IHostBuilder`](https://learn.microsoft.com/dotnet/api/microsoft.extensions.hosting.ihostbuilder) extension methods for use within a unit test environment. These help collect logs as well as augment the host and app configurations.

## Feedback & Contributing

For any feedback or contributions, please visit us in [our GitHub repo](https://github.com/dotnet/extensions).