![]() |
VOOZH | about |
dotnet add package Microsoft.DurableTask.InProcessTestHost --version 0.2.3-preview.1
NuGet\Install-Package Microsoft.DurableTask.InProcessTestHost -Version 0.2.3-preview.1
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.3-preview.1" />
<PackageVersion Include="Microsoft.DurableTask.InProcessTestHost" Version="0.2.3-preview.1" />Directory.Packages.props
<PackageReference Include="Microsoft.DurableTask.InProcessTestHost" />Project file
paket add Microsoft.DurableTask.InProcessTestHost --version 0.2.3-preview.1
#r "nuget: Microsoft.DurableTask.InProcessTestHost, 0.2.3-preview.1"
#:package Microsoft.DurableTask.InProcessTestHost@0.2.3-preview.1
#addin nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.3-preview.1&prereleaseInstall as a Cake Addin
#tool nuget:?package=Microsoft.DurableTask.InProcessTestHost&version=0.2.3-preview.1&prereleaseInstall as a Cake Tool
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.
var options = new DurableTaskTestHostOptions
{
Port = 31000, // Optional: specific port (random by default)
LoggerFactory = myLoggerFactory // Optional: pass logger factory for logging
};
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"));
});
string instanceId = await testHost.Client.ScheduleNewOrchestrationInstanceAsync("MyOrchestrator");
var result = await testHost.Client.WaitForInstanceCompletionAsync(instanceId);
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 |
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>();
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();
| 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. |
| Property | Type | Description |
|---|---|---|
Client |
DurableTaskClient |
Client for scheduling and managing orchestrations. |
Services |
IServiceProvider |
Service provider with registered services. |
| Method | Description |
|---|---|
services.AddInMemoryDurableTask(configureTasks) |
Adds in-memory durable task support to an existing IServiceCollection. |
services.GetInMemoryOrchestrationService() |
Gets the InMemoryOrchestrationService from the service provider. |
See , , and for complete samples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.3-preview.1 | 1,422 | 4/22/2026 |
| 0.2.2-preview.1 | 1,362 | 4/15/2026 |
| 0.2.1-preview.1 | 530 | 3/18/2026 |
| 0.2.0-preview.1 | 303 | 1/20/2026 |
| 0.1.0-preview.1 | 185 | 10/27/2025 |