Microsoft.DurableTask.InProcessTestHost 0.2.0-preview.1

Prefix Reserved
This is a prerelease version of Microsoft.DurableTask.InProcessTestHost.
dotnet add package Microsoft.DurableTask.InProcessTestHost --version 0.2.0-preview.1
                    
NuGet\Install-Package Microsoft.DurableTask.InProcessTestHost -Version 0.2.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Microsoft.DurableTask.InProcessTestHost --version 0.2.0-preview.1
                    
#r "nuget: Microsoft.DurableTask.InProcessTestHost, 0.2.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Microsoft.DurableTask.InProcessTestHost@0.2.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.0-preview.1&prerelease
                    
Install as a Cake Tool

DurableTaskTestHost - Testing Durable Orchestrations In-Process

DurableTaskTestHost is a simple API for testing your durable task orchestrations and activities in-process without requiring any external backend.

Supports both class-based and function-based syntax.

Quick Start

1. Configure options (optional)

var options = new DurableTaskTestHostOptions
{
    Port = 31000,                  // Optional: specific port (random by default)
    LoggerFactory = myLoggerFactory // Optional: pass logger factory for logging
};

2. Register test orchestrations and activities

await using var testHost = await DurableTaskTestHost.StartAsync(registry =>
{
    // Class-based
    registry.AddOrchestrator<MyOrchestrator>();
    registry.AddActivity<MyActivity>();
    
    // Function-based
    registry.AddOrchestratorFunc("MyFunc", (ctx, input) => Task.FromResult("done"));
    registry.AddActivityFunc("MyActivity", (ctx, input) => Task.FromResult("result"));
});

3. Test

string instanceId = await testHost.Client.ScheduleNewOrchestrationInstanceAsync("MyOrchestrator");
var result = await testHost.Client.WaitForInstanceCompletionAsync(instanceId);

Dependency Injection

When your activities depend on services, there are two approaches:

Approach When to Use
Option 1: ConfigureServices Simple tests where you register a few services directly
Option 2: AddInMemoryDurableTask When you have an existing host (e.g., WebApplicationFactory) with complex DI setup

Option 1: ConfigureServices

Use this when you want the test host to manage everything. Register services directly in the test host options.

await using var host = await DurableTaskTestHost.StartAsync(
    tasks =>
    {
        tasks.AddOrchestrator<MyOrchestrator>();
        tasks.AddActivity<MyActivity>();
    },
    new DurableTaskTestHostOptions
    {
        ConfigureServices = services =>
        {
            // Register services required by your orchestrator or activity function
            services.AddSingleton<IMyService, MyService>();
            services.AddSingleton<IUserRepository, InMemoryUserRepository>();
            services.AddLogging();
        }
    });

var instanceId = await host.Client.ScheduleNewOrchestrationInstanceAsync(nameof(MyOrchestrator), "input");
var result = await host.Client.WaitForInstanceCompletionAsync(instanceId, getInputsAndOutputs: true);

Access registered services via host.Services:

var myService = host.Services.GetRequiredService<IMyService>();

Option 2: AddInMemoryDurableTask

Use this when you already have a host with complex DI setup (database, auth, external APIs, etc.) and want to add durable task testing to it.

public class MyIntegrationTests : IAsyncLifetime
{
    IHost host = null!;
    DurableTaskClient client = null!;

    public async Task InitializeAsync()
    {
        this.host = Host.CreateDefaultBuilder()
            .ConfigureServices(services =>
            {
                // Your existing services (from Program.cs, Startup.cs, etc.)
                services.AddSingleton<IUserRepository, InMemoryUserRepository>();
                services.AddScoped<IOrderService, OrderService>();
                services.AddDbContext<MyDbContext>();

                // Add in-memory durable task support
                services.AddInMemoryDurableTask(tasks =>
                {
                    tasks.AddOrchestrator<MyOrchestrator>();
                    tasks.AddActivity<MyActivity>();
                });
            })
            .Build();

        await this.host.StartAsync();
        this.client = this.host.Services.GetRequiredService<DurableTaskClient>();
    }
}

Access the in-memory orchestration service:

var orchestrationService = host.Services.GetInMemoryOrchestrationService();

API Reference

DurableTaskTestHostOptions

Property Type Description
Port int? Specific port for gRPC sidecar. Random 30000-40000 if not set.
LoggerFactory ILoggerFactory? Logger factory for capturing logs during tests.
ConfigureServices Action<IServiceCollection>? Callback to register services for DI.

DurableTaskTestHost

Property Type Description
Client DurableTaskClient Client for scheduling and managing orchestrations.
Services IServiceProvider Service provider with registered services.

Extension Methods

Method Description
services.AddInMemoryDurableTask(configureTasks) Adds in-memory durable task support to an existing IServiceCollection.
services.GetInMemoryOrchestrationService() Gets the InMemoryOrchestrationService from the service provider.

More Samples

See BasicOrchestrationTests.cs, DependencyInjectionTests.cs, and WebApplicationFactoryIntegrationTests.cs for complete samples.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0-preview.1 0 1/20/2026
0.1.0-preview.1 149 10/27/2025