# StoreCancellationContract<TStore\>

> 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.storage.storecancellationcontract-1/
> Summary: StoreCancellationContract<TStore\>: The promise every store makes about a token that is already cancelled, plus the lifecycle plumbing every store contract shares.

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

The promise every store makes about a token that is **already
cancelled**, plus the lifecycle plumbing every store contract shares.

```csharp
public abstract class StoreCancellationContract<TStore> : IAsyncLifetime, IAsyncDisposable
```

<dl class="api-relations"><dt>Type Parameters</dt><dd><code>TStore</code> The store type under test.</dd><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.testing.contracts.storage.storecancellationcontract-1/">StoreCancellationContract&lt;TStore&gt;</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>

## Remarks

A store handed a token that is already cancelled throws
[OperationCanceledException](https://learn.microsoft.com/dotnet/api/system.operationcanceledexception) and leaves no trace. The write
side is the half that matters: throwing on its own proves nothing, because
a check placed *after* the work throws too. The contract therefore
reads the store back and requires it to be untouched.

Cancellation *during* a call is deliberately outside this contract.
It races, so no deterministic case can assert where the work stopped. Only
a token that was already cancelled when the call started is covered.

[Storage.TenantIsolationContract](/api/tracon.testing.contracts.storage/) derives from this class and
wires the three hooks to its own seed and count hooks, so a tenant-aware
store contract implements nothing extra. The four store contracts that
carry no tenant dimension derive from this class directly.

## Constructors

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1__ctor"></a> StoreCancellationContract\(\)

```csharp
protected StoreCancellationContract()
```

## Properties

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Store"></a> Store

The store under test.

```csharp
protected TStore Store { get; }
```

#### Property Value

 TStore

## Methods

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Canceled_token_throws_on_read"></a> Canceled\_token\_throws\_on\_read\(\)

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

 [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task)

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_Canceled_token_throws_on_write_and_leaves_no_trace"></a> Canceled\_token\_throws\_on\_write\_and\_leaves\_no\_trace\(\)

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

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

Calls one **read** method of the store with the given
token.

```csharp
protected abstract ValueTask CancellableReadAsync(CancellationToken cancellationToken)
```

#### Parameters

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The token the store must observe.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task; any result is discarded.

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_CancellableWriteAsync_System_Threading_CancellationToken_"></a> CancellableWriteAsync\(CancellationToken\)

Calls one **write** method of the store with the given
token.

```csharp
protected abstract ValueTask CancellableWriteAsync(CancellationToken cancellationToken)
```

#### Parameters

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The token the store must observe.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task.

#### Remarks

The write must be one [StoreCancellationContract.WroteAnythingAsync](/api/tracon.testing.contracts.storage/) can see. A write
this contract cannot read back proves nothing about side effects, which
is why [StoreCancellationContract.The_write_this_contract_checks_can_be_read_back](/api/tracon.testing.contracts.storage/)
runs the same pair with a live token and requires the read to find it.

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_CreateStoreAsync"></a> CreateStoreAsync\(\)

Produces an empty store for the test.

```csharp
protected abstract ValueTask<TStore> CreateStoreAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<TStore\>

A store ready for use.

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

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

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_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_Storage_StoreCancellationContract_1_OnDisposeAsync"></a> OnDisposeAsync\(\)

Hook for a derived class to release its own resources.

```csharp
protected virtual ValueTask OnDisposeAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

A completed task.

### <a id="Tracon_Testing_Contracts_Storage_StoreCancellationContract_1_The_write_this_contract_checks_can_be_read_back"></a> The\_write\_this\_contract\_checks\_can\_be\_read\_back\(\)

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

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

Reports whether [StoreCancellationContract.CancellableWriteAsync](/api/tracon.testing.contracts.storage/) left anything
behind.

```csharp
protected abstract ValueTask<bool> WroteAnythingAsync()
```

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the store holds any record the write would have created.
