# JobHandlerContract

> 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.contracts.scheduling.jobhandlercontract/
> Summary: JobHandlerContract: Behavior tests for the IJobHandler at-least-once contract: a handler must not reprocess an item already reported, and must observe cancellation between items.

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

Behavior tests for the [IJobHandler](/api/tracon.ijobhandler/) at-least-once contract:
a handler must not reprocess an item already reported, and must observe
cancellation between items.

```csharp
public abstract class JobHandlerContract : IAsyncLifetime, 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.contracts.scheduling.jobhandlercontract/">JobHandlerContract</a></dd><dt>Implements</dt><dd>IAsyncLifetime, <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.memberwiseclone">object.MemberwiseClone()</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>

## Constructors

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract__ctor"></a> JobHandlerContract\(\)

```csharp
protected JobHandlerContract()
```

## Properties

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_Handler"></a> Handler

The handler under test.

```csharp
protected IJobHandler Handler { get; }
```

#### Property Value

 [IJobHandler](/api/tracon.ijobhandler/)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_HandlerKey"></a> HandlerKey

The handler key the job records this contract builds carry. Override
when the handler under test needs its real key (a built-in one from
[JobHandlerKeys](/api/tracon.jobhandlerkeys/), or the consumer's own); the value never
reaches dispatch here, because the contract calls the handler directly.

```csharp
protected virtual string HandlerKey { get; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_JobId"></a> JobId

The job identifier shared by every [JobContext](/api/tracon.jobcontext/) built
during this instance's tests. A handler that keys other state by job id
(an eval run record, for example) can create that state against this
value inside [JobHandlerContract.CreateHandlerAsync](/api/tracon.testing.contracts.scheduling.jobhandlercontract/#Tracon_Testing_Contracts_Scheduling_JobHandlerContract_CreateHandlerAsync).

```csharp
protected Guid JobId { get; }
```

#### Property Value

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

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_Cancellation_is_observed_between_items"></a> Cancellation\_is\_observed\_between\_items\(\)

```csharp
[Fact]
public Task Cancellation_is_observed_between_items()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_Completed_items_are_not_processed_again"></a> Completed\_items\_are\_not\_processed\_again\(\)

```csharp
[Fact]
public Task Completed_items_are_not_processed_again()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_CreateHandlerAsync"></a> CreateHandlerAsync\(\)

Creates the handler under test, performing whatever async setup it
needs (an eval suite and run record, a workflow registration, and
so on).

```csharp
protected abstract ValueTask<IJobHandler> CreateHandlerAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IJobHandler](/api/tracon.ijobhandler/)\>

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_CreateItem_System_Int32_Tracon_JobItemStatus_"></a> CreateItem\(int, JobItemStatus\)

Creates one job item the handler under test can process.

```csharp
protected abstract JobItemRecord CreateItem(int sequence, JobItemStatus status)
```

#### Parameters

`sequence` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The item's position within the job.

`status` [JobItemStatus](/api/tracon.jobitemstatus/)

The item's starting status.

#### Returns

 [JobItemRecord](/api/tracon.jobitemrecord/)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_CreateJob_System_Collections_Generic_IReadOnlyList_Tracon_JobItemRecord__"></a> CreateJob\(IReadOnlyList<JobItemRecord\>\)

Builds the job record wrapping `items`. Override to
set a specific target name or payload the handler under test needs.

```csharp
protected virtual JobRecord CreateJob(IReadOnlyList<JobItemRecord> items)
```

#### Parameters

`items` [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[JobItemRecord](/api/tracon.jobitemrecord/)\>

#### Returns

 [JobRecord](/api/tracon.jobrecord/)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_DisposeAsync"></a> DisposeAsync\(\)

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

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_InitializeAsync"></a> InitializeAsync\(\)

Called immediately after the class has been created, before it is used.

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

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

### <a id="Tracon_Testing_Contracts_Scheduling_JobHandlerContract_Only_pending_items_are_processed_on_a_retry"></a> Only\_pending\_items\_are\_processed\_on\_a\_retry\(\)

```csharp
[Fact]
public Task Only_pending_items_are_processed_on_a_retry()
```

#### Returns

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)
