AgentTestHost Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A thin test harness that configures an agent using the same DI extension-method style
as production Program.cs, then produces ready-to-use TestFlow instances.
public sealed class AgentTestHost : IAsyncDisposable, IDisposable
type AgentTestHost = class
interface IDisposable
interface IAsyncDisposable
Public NotInheritable Class AgentTestHost
Implements IAsyncDisposable, IDisposable
- Inheritance
-
AgentTestHost
- Implements
Remarks
Pre-registers TestAdapter as IChannelAdapter singleton.
Use await using var host = AgentTestHost.Create(...); in async tests (preferred), or using var host = AgentTestHost.Create(...); in sync contexts.
Register your agent directly as IAgent — do not use AddAgent<T>(), which also registers CloudAdapter and conflicts with the pre-registered TestAdapter.
Properties
| Name | Description |
|---|---|
| Adapter |
Gets the pre-configured TestAdapter shared by all test flows created from this host. |
Methods
| Name | Description |
|---|---|
| Create(Action<IHostApplicationBuilder>) |
Creates and starts a new AgentTestHost. |
| CreateTestFlow() |
Creates a TestFlow wired to the IAgent resolved from DI. Because IAgent is registered as transient, each call produces a new agent instance. All flows share the same Adapter and its ActiveQueue. |
| Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
| DisposeAsync() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. |