RunicTestRowSource<TRow, TKey> class

Namespace Runic.Application.Testing in Runic.Application.Testing 0.23.0

public sealed class RunicTestRowSource<TRow, TKey> : IRunicRowSource<TRow, TKey> where TKey : notnull

Inherits or implements IRunicRowSource.

An in-memory IRunicRowSource for tests of query collections: it serves a list through RunicQueryFields, with optional latency, and records every load, count and search, so a test can assert what a page's scrolling and sorting loaded.

Type parameters

TRow

The row type.

TKey

The row key.

Remarks

Latency waits on TimeProvider: with the test host's FakeTimeProvider, loads complete when the test advances it. RunicTestRowSource.FailNext makes the next load throw, as a database outage does.

Constructors

RunicTestRowSource

public RunicTestRowSource(IEnumerable<TRow> rows, RunicQueryFields<TRow> fields, Expression<Func<TRow, TKey>> key, TimeProvider? timeProvider = null)

Creates a source of rows.

Parameters

rows

The rows, in the source's own order.

fields

The fields a page may sort and filter by.

key

The row key.

timeProvider

The clock latency waits on; TimeProvider.System by default.

Properties

Counts

public int Counts { get; }

The counts taken so far.

Latency

public TimeSpan Latency { get; set; }

How long each load, count and search takes. Zero by default.

Loads

public IReadOnlyList<RunicRowLoad> Loads { get; }

Every load, oldest first: its query and range.

MaximumConcurrency

public int MaximumConcurrency { get; }

The most loads, counts and searches that ran at once.

RowsLoaded

public long RowsLoaded { get; }

The rows loaded so far, summed over RunicTestRowSource.Loads.

Searches

public int Searches { get; }

The key searches (IndexOfAsync) so far.

Methods

CountAsync

public ValueTask<int> CountAsync(RunicQuery query, CancellationToken cancellationToken)

Counts the rows that match query's filters.

Parameters

query

The query.

cancellationToken

Cancels the count.

Documentation from IRunicRowSource.CountAsync.

FailNext

public void FailNext(Exception failure)

Makes the next load throw failure.

Parameters

failure

The exception.

IndexOfAsync

public ValueTask<int> IndexOfAsync(RunicQuery query, TKey key, CancellationToken cancellationToken)

Returns the position of the row with key in query's order, or -1.

Parameters

query

The query.

key

The row's key.

cancellationToken

Cancels the search.

Documentation from IRunicRowSource.IndexOfAsync.

LoadAsync

public ValueTask<RunicRowPage<TRow>> LoadAsync(RunicQuery query, RunicRowRange range, CancellationToken cancellationToken)

Loads the rows of range in query's order.

Parameters

query

The query.

range

The rows to load. Fewer rows come back at the end of the list.

cancellationToken

Cancels the load.

Returns

The rows, and optionally the number of rows that match the query, such as from COUNT(*) OVER ().

Documentation from IRunicRowSource.LoadAsync.

SetRows

public void SetRows(IEnumerable<TRow> rows)

Replaces the rows. Call the collection's Refresh or Invalidate afterwards, as after a database change.

Parameters

rows

The new rows.

Validate

public void Validate(RunicQuery query)

Checks that the source can run query before the collection takes it.

Parameters

query

The query.

Exceptions

ArgumentException

The query names a field or filter the source does not have, or a value it cannot use. The page receives invalid-input, and the collection keeps its query.

Remarks

The query comes from a page and is untrusted: its field names, custom filter names and values are whatever the page sent. Reject every field, operator and value the source does not support by name, rather than passing them to a database. RunicQueryFields.Validate does so for registered fields.

Documentation from IRunicRowSource.Validate.