Skip to main content

Crate ferroui_reactive_testing

Crate ferroui_reactive_testing 

Source
Expand description

ferroui-reactive-testing

A port of Microsoft.Reactive.Testing (https://github.com/dotnet/reactive) for ferroui-reactive: the virtual-time TestScheduler, recorded notifications (Recorded) and subscriptions (Subscription), hot and cold test observables, the observer that records what it receives, the factories of ReactiveTest and the assertions of ReactiveAssert.

A test in the style of upstream:

use ferroui_reactive::ObservableExt;
use ferroui_reactive_testing::{assert_messages, assert_subscriptions, ReactiveTest as RT, TestScheduler};

let scheduler = TestScheduler::new();
let xs = scheduler.create_hot_observable(vec![RT::on_next(150, 1), RT::on_next(210, 2), RT::on_completed(250)]);
let source = xs.as_observable();
let res = scheduler.start(move || source.clone());
assert_messages!(res.messages(), RT::on_next(210, 2), RT::on_completed::<i32>(250));
// A hot observable subscribed directly keeps the subscription until it is disposed.
assert_subscriptions!(xs.subscriptions(), RT::subscribe(200, 1000));

Macros§

assert_messages
Asserts that the recorded notifications are the expected ones; each expected one is a Recorded<Notification<T>> or a Recorded<Expected<T>> (res.Messages.AssertEqual(...)).
assert_subscriptions
Asserts that the subscriptions are the expected ones, in order (xs.Subscriptions.AssertEqual(...)).

Structs§

ColdObservable
A sequence of recorded notifications at times relative to each subscription (ColdObservable<T>, ITestableObservable<T>).
HotObservable
A sequence of recorded notifications at absolute times, shared by its observers (HotObservable<T>, ITestableObservable<T>).
MockObserver
An observer that records what it receives with the virtual time (MockObserver<T>, ITestableObserver<T>).
ReactiveTest
The factories of recorded notifications and subscriptions, and the default times of TestScheduler::start (ReactiveTest).
Recorded
A value with the virtual time it was recorded at (Recorded<T>).
Subscription
A subscription to a test observable: the virtual times it was made and disposed (Subscription).
TestException
An error made by a test, which compares by identity (new Exception() of upstream’s tests).
TestScheduler
A virtual-time scheduler for tests, whose clock counts ticks (TestScheduler). It dereferences to the virtual-time scheduler (clock, start, advance_to, advance_by, sleep, schedule_absolute, …).
TestTime
The virtual time of the test scheduler: ticks of 100 nanoseconds, as TimeSpan counts them.

Enums§

Expected
A notification a test expects: one notification, or a notification that satisfies a predicate (the predicate forms of ReactiveTest.OnNext and OnError).

Functions§

assert_recorded_eq
Asserts that the recorded notifications are the expected ones, in order (AssertEqual on the messages of an observer or observable).
assert_throws
Asserts that action panics (ReactiveAssert.Throws): the form of an exception thrown to the caller in the port.
duration_to_ticks
A duration as ticks of 100 nanoseconds (TimeSpan.Ticks).
new_error
A new error for a test (new Exception(message)).
ticks_to_duration
Ticks of 100 nanoseconds as a duration (TimeSpan.FromTicks).
ticks_to_time
The time of the test scheduler at ticks (new DateTimeOffset(ticks, TimeSpan.Zero)).