public sealed class RunicTestRowSource<TRow, TKey> : IRunicRowSource<TRow, TKey> where TKey : notnull 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
TRowThe row type.
TKeyThe 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
rowsThe rows, in the source's own order.
fieldsThe fields a page may sort and filter by.
keyThe row key.
timeProviderThe clock latency waits on;
TimeProvider.Systemby 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
queryThe query.
cancellationTokenCancels the count.
Documentation from IRunicRowSource.CountAsync.
FailNext
public void FailNext(Exception failure) Makes the next load throw failure.
Parameters
failureThe 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
queryThe query.
keyThe row's key.
cancellationTokenCancels 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
queryThe query.
rangeThe rows to load. Fewer rows come back at the end of the list.
cancellationTokenCancels 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
rowsThe new rows.
Validate
public void Validate(RunicQuery query) Checks that the source can run query before the collection takes it.
Parameters
queryThe query.
Exceptions
ArgumentExceptionThe 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.