Skip to content
Tracon

NonTokenUsageContract

Namespace Tracon.Testing.Contracts.Storage · Assembly Tracon.Testing.Contracts.Xunit.dll

Behavior tests for the IRunStore non-token usage contract: the items a workflow function node reports.

public abstract class NonTokenUsageContract : TenantIsolationContract<IRunStore>, IAsyncLifetime, IAsyncDisposable
Inheritance
object ← StoreCancellationContract<IRunStore> ← TenantIsolationContract<IRunStore> ← NonTokenUsageContract
Implements
IAsyncLifetime, IAsyncDisposable
Inherited Members
TenantIsolationContract<IRunStore>.TenantA, TenantIsolationContract<IRunStore>.TenantB, TenantIsolationContract<IRunStore>.UseAmbientTenant(MutableTenantContext), TenantIsolationContract<IRunStore>.SeedAsync(string, string, CancellationToken), TenantIsolationContract<IRunStore>.ExistsAsync(string, object), TenantIsolationContract<IRunStore>.CountAsync(string, CancellationToken), TenantIsolationContract<IRunStore>.TryDeleteAsync(string, object), TenantIsolationContract<IRunStore>.TryOverwriteAsync(string, string), TenantIsolationContract<IRunStore>.CancellableReadAsync(CancellationToken), TenantIsolationContract<IRunStore>.CancellableWriteAsync(CancellationToken), TenantIsolationContract<IRunStore>.WroteAnythingAsync(), TenantIsolationContract<IRunStore>.Tenant_cannot_read_another_tenants_record(), TenantIsolationContract<IRunStore>.Tenant_reads_its_own_record(), TenantIsolationContract<IRunStore>.Tenant_does_not_see_another_tenants_record_in_the_list(), TenantIsolationContract<IRunStore>.Tenant_cannot_delete_another_tenants_record(), TenantIsolationContract<IRunStore>.Same_name_lives_independently_across_two_tenants(), TenantIsolationContract<IRunStore>.AmbientTenant, StoreCancellationContract<IRunStore>.CreateStoreAsync(), StoreCancellationContract<IRunStore>.InitializeAsync(), StoreCancellationContract<IRunStore>.DisposeAsync(), StoreCancellationContract<IRunStore>.OnDisposeAsync(), StoreCancellationContract<IRunStore>.CancellableReadAsync(CancellationToken), StoreCancellationContract<IRunStore>.CancellableWriteAsync(CancellationToken), StoreCancellationContract<IRunStore>.WroteAnythingAsync(), StoreCancellationContract<IRunStore>.Canceled_token_throws_on_read(), StoreCancellationContract<IRunStore>.The_write_this_contract_checks_can_be_read_back(), StoreCancellationContract<IRunStore>.Canceled_token_throws_on_write_and_leaves_no_trace(), StoreCancellationContract<IRunStore>.Store, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Every implementation must pass the same scenarios. The items hang off a run, so isolation is established through the run’s tenant, the same way a tool invocation’s is.

The run’s total (RunRecord.NonTokenCost) is a different surface: it is a snapshot written with IRunStore.CompleteRunAsync and RunStoreContract covers it.

protected NonTokenUsageContract()

A_run_lists_its_own_items_and_not_its_childrens()

Section titled “ A_run_lists_its_own_items_and_not_its_childrens()”
[Fact]
public Task A_run_lists_its_own_items_and_not_its_childrens()

Task

A_run_that_reported_nothing_or_does_not_exist_lists_nothing()

Section titled “ A_run_that_reported_nothing_or_does_not_exist_lists_nothing()”
[Fact]
public Task A_run_that_reported_nothing_or_does_not_exist_lists_nothing()

Task

An_item_for_a_run_that_was_never_opened_leaves_nothing()

Section titled “ An_item_for_a_run_that_was_never_opened_leaves_nothing()”
[Fact]
public Task An_item_for_a_run_that_was_never_opened_leaves_nothing()

Task

An_item_stamped_with_another_tenant_is_refused_and_leaves_nothing()

Section titled “ An_item_stamped_with_another_tenant_is_refused_and_leaves_nothing()”
[Fact]
public Task An_item_stamped_with_another_tenant_is_refused_and_leaves_nothing()

Task

An_item_with_no_amount_comes_back_with_no_amount_not_zero()

Section titled “ An_item_with_no_amount_comes_back_with_no_amount_not_zero()”
[Fact]
public Task An_item_with_no_amount_comes_back_with_no_amount_not_zero()

Task

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

protected override ValueTask CancellableReadAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The token the store must observe.

ValueTask

The completion task; any result is discarded.

The listing hook is the read: it needs no key, so it can be called on an untouched store. A contract whose store has no listing endpoint – and whose TenantIsolationContract.CountAsync therefore makes no store call at all on an empty store – overrides this with its own read.

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

protected override ValueTask CancellableWriteAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The token the store must observe.

ValueTask

The completion task.

The write must be one StoreCancellationContract.WroteAnythingAsync 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 runs the same pair with a live token and requires the read to find it.

Reports how many records the given tenant sees through the listing endpoint.

protected override ValueTask<int> CountAsync(string tenantId, CancellationToken cancellationToken)

tenantId string

The reading tenant.

cancellationToken CancellationToken

The token every store call inside the hook must be handed; see TenantIsolationContract.SeedAsync.

ValueTask<int>

The number of records seen.

Reports whether the record is visible from the given tenant’s viewpoint.

protected override ValueTask<bool> ExistsAsync(string tenantId, object key)

tenantId string

The reading tenant.

key object

The key returned by TenantIsolationContract.SeedAsync.

ValueTask<bool>

true if the record is visible.

[Fact]
public Task Item_fields_round_trip()

Task

Items_come_back_in_the_order_they_were_reported()

Section titled “ Items_come_back_in_the_order_they_were_reported()”
[Fact]
public Task Items_come_back_in_the_order_they_were_reported()

Task

SeedAsync(string, string, CancellationToken)

Section titled “ SeedAsync(string, string, CancellationToken)”

Writes a sample record for the given tenant.

protected override ValueTask<object> SeedAsync(string tenantId, string name, CancellationToken cancellationToken)

tenantId string

The tenant that owns the record.

name string

The name distinguishing the record. The same name may be used by two tenants.

cancellationToken CancellationToken

The token every store call inside the hook must be handed. The cancellation contract calls this hook with a token that is already cancelled, so a hook that drops the token reports a store as sound when it is not.

ValueTask<object>

The key to use for reading the record back.

The_largest_quantity_and_amount_a_run_accepts_fit_the_columns()

Section titled “ The_largest_quantity_and_amount_a_run_accepts_fit_the_columns()”
[Fact]
public Task The_largest_quantity_and_amount_a_run_accepts_fit_the_columns()

Task