# TraconTestHost

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.testing.tracontesthost/
> Summary: TraconTestHost: In-memory Tracon host.

<div class="api-provenance">Namespace Tracon.Testing · Assembly <code>Tracon.Testing.dll</code></div>

In-memory Tracon host.

```csharp
public sealed class TraconTestHost : IAsyncDisposable
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.testing.tracontesthost/">TraconTestHost</a></dd><dt>Implements</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.iasyncdisposable">IAsyncDisposable</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

Built on `WebApplication.CreateSlimBuilder` + `UseTestServer`;
`Microsoft.AspNetCore.Mvc.Testing`'s `WebApplicationFactory<T>`
is not used, because it requires an entry-point assembly and locks the
consumer into a hosting model. In-memory stores are a first-class
implementation, so the host needs no database.

`AIFunctionArguments.Services` is empty in the MAF pipeline: a
dependency your own tool needs is **not resolved from DI**. Take
the dependency in the tool's CONSTRUCTOR and register it through a factory
with `services.AddSingleton(provider => new
TraconToolRegistration(new MyTool(provider)) { ... })`.

## Properties

### <a id="Tracon_Testing_TraconTestHost_Client"></a> Client

HTTP client bound to the host.

```csharp
public HttpClient Client { get; }
```

#### Property Value

 [HttpClient](https://learn.microsoft.com/dotnet/api/system.net.http.httpclient)

### <a id="Tracon_Testing_TraconTestHost_Services"></a> Services

The host's service provider.

```csharp
public IServiceProvider Services { get; }
```

#### Property Value

 [IServiceProvider](https://learn.microsoft.com/dotnet/api/system.iserviceprovider)

## Methods

### <a id="Tracon_Testing_TraconTestHost_DisposeAsync"></a> DisposeAsync\(\)

```csharp
public ValueTask DisposeAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

### <a id="Tracon_Testing_TraconTestHost_RunAsync_System_String_System_String_System_Threading_CancellationToken_"></a> RunAsync\(string, string, CancellationToken\)

Runs an agent, drains the stream to completion, and returns its record.

```csharp
public ValueTask<RunAssertions> RunAsync(string agentName, string message, CancellationToken cancellationToken = default)
```

#### Parameters

`agentName` [string](https://learn.microsoft.com/dotnet/api/system.string)

The name of the agent to run.

`message` [string](https://learn.microsoft.com/dotnet/api/system.string)

The user message.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

Cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[RunAssertions](/api/tracon.testing.runassertions/)\>

An object for building assertions on the run.

#### Exceptions

 [TraconAssertionException](/api/tracon.testing.traconassertionexception/)

The run was not accepted, or its record was not found in the store.

### <a id="Tracon_Testing_TraconTestHost_StartAsync_System_Action_Tracon_Testing_TraconTestHostOptions__System_Threading_CancellationToken_"></a> StartAsync\(Action<TraconTestHostOptions\>?, CancellationToken\)

Builds and starts a host.

```csharp
public static ValueTask<TraconTestHost> StartAsync(Action<TraconTestHostOptions>? configure = null, CancellationToken cancellationToken = default)
```

#### Parameters

`configure` [Action](https://learn.microsoft.com/dotnet/api/system.action\-1)<[TraconTestHostOptions](/api/tracon.testing.tracontesthostoptions/)\>?

Changes the host settings.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

Cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[TraconTestHost](/api/tracon.testing.tracontesthost/)\>

The running host.
