Microsoft.DurableTask.InProcessTestHost
0.2.0-preview.1
Prefix Reserved
dotnet add package Microsoft.DurableTask.InProcessTestHost --version 0.2.0-preview.1
NuGet\Install-Package Microsoft.DurableTask.InProcessTestHost -Version 0.2.0-preview.1
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.0-preview.1" />
<PackageVersion Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.0-preview.1" />
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" />
paket add Microsoft.DurableTask.InProcessTestHost --version 0.2.0-preview.1
#r "nuget: Microsoft.DurableTask.InProcessTestHost, 0.2.0-preview.1"
#:package Microsoft.DurableTask.InProcessTestHost@0.2.0-preview.1
#addin nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.0-preview.1&prerelease
#tool nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.0-preview.1&prerelease
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 | Versions 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. |
-
net10.0
- Google.Protobuf (>= 3.33.2)
- Grpc.AspNetCore.Server (>= 2.71.0)
- Grpc.Net.Client (>= 2.67.0)
- Microsoft.Azure.DurableTask.Core (>= 3.7.0)
- Microsoft.DurableTask.Client.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Worker.Grpc (>= 1.19.1)
-
net6.0
- Google.Protobuf (>= 3.33.2)
- Grpc.AspNetCore.Server (>= 2.71.0)
- Grpc.Net.Client (>= 2.67.0)
- Microsoft.Azure.DurableTask.Core (>= 3.7.0)
- Microsoft.DurableTask.Client.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Worker.Grpc (>= 1.19.1)
-
net8.0
- Google.Protobuf (>= 3.33.2)
- Grpc.AspNetCore.Server (>= 2.71.0)
- Grpc.Net.Client (>= 2.67.0)
- Microsoft.Azure.DurableTask.Core (>= 3.7.0)
- Microsoft.DurableTask.Client.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Grpc (>= 1.19.1)
- Microsoft.DurableTask.Worker.Grpc (>= 1.19.1)
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 |