Table of Contents

Class TestScheduler

Namespace
RxSharp.Testing
Assembly
RxSharp.dll

A VirtualTimeScheduler that additionally understands rxjs-style ASCII marble diagrams, so time-based operator tests can build deterministic cold/hot sources and assert exactly when values, errors, and completion happen — no real timers, no flakiness. See MarbleParser for the (deliberately simplified) diagram grammar this supports.

public class TestScheduler : VirtualTimeScheduler, IScheduler
Inheritance
System.Object
TestScheduler
Implements
Inherited Members

Methods

CreateColdObservable<T>(string, IReadOnlyDictionary<char, T>?, Exception?)

Builds a "cold" source: each independent subscription replays marbles from its own subscription instant (frame 0 of the diagram = the moment Subscribe is called), same as rxjs's cold(). The diagram cannot contain a subscription marker ^ — a cold source has no fixed subscription point, every subscriber gets its own independent playback.

public Observable<T> CreateColdObservable<T>(string marbles, IReadOnlyDictionary<char, T>? values = null, Exception? error = null)

Parameters

marbles string

The marble diagram (see MarbleParser for the supported grammar).

values IReadOnlyDictionary<char, T>?

Maps marble characters to emitted values; when omitted, the marble character itself is used as the value (requires T to be System.Char).

error Exception?

The error to emit for an # marker, if the diagram contains one; defaults to a generic exception.

Returns

Observable<T>

An observable that replays the diagram independently for each subscriber.

Type Parameters

T

The element type of the observable.

CreateHotObservable<T>(string, IReadOnlyDictionary<char, T>?, Exception?)

Builds a "hot" source: a shared Subject<T> whose messages are scheduled once, at absolute virtual times measured from Clock at the moment this method is called (frame 0 of the diagram = that instant) — same as rxjs's hot(). Call this before advancing the clock unless you deliberately want the diagram's frames offset from the scheduler's current time. Subscribers that attach after a message's due time has already passed simply miss it, same as subscribing to a real Subject<T> late.

public Observable<T> CreateHotObservable<T>(string marbles, IReadOnlyDictionary<char, T>? values = null, Exception? error = null)

Parameters

marbles string

The marble diagram (see MarbleParser for the supported grammar).

values IReadOnlyDictionary<char, T>?

Maps marble characters to emitted values; when omitted, the marble character itself is used as the value (requires T to be System.Char).

error Exception?

The error to emit for an # marker, if the diagram contains one; defaults to a generic exception.

Returns

Observable<T>

An observable shared by every subscriber, driven by a single underlying Subject<T>.

Type Parameters

T

The element type of the observable.

ParseTime(string)

Finds the completion marker | in a plain time diagram (e.g. "---|") and returns its frame as a TimeSpan, for use with AdvanceTo(TimeSpan). Mirrors rxjs's createTime.

public static TimeSpan ParseTime(string marbles)

Parameters

marbles string

A time diagram containing exactly one completion marker |.

Returns

TimeSpan

The virtual time of the completion marker.

Record<T>(Observable<T>)

Subscribes to source immediately and returns a list that fills in with a Recorded<T> (stamped with Clock at the moment each notification arrives) for every next/error/complete the source produces. Advance the scheduler afterward (Start(), AdvanceTo(TimeSpan), or AdvanceBy(TimeSpan)), then assert against the same list reference.

public IReadOnlyList<Recorded<T>> Record<T>(Observable<T> source)

Parameters

source Observable<T>

The observable to subscribe to and record notifications from.

Returns

IReadOnlyList<Recorded<T>>

A live list that fills in with each notification as the scheduler is advanced.

Type Parameters

T

The element type of the observable.