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 aRecorded<Expected<T>>(res.Messages.AssertEqual(...)). - assert_
subscriptions - Asserts that the subscriptions are the expected ones, in order (
xs.Subscriptions.AssertEqual(...)).
Structs§
- Cold
Observable - 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>). - Mock
Observer - An observer that records what it receives with the virtual time (
MockObserver<T>,ITestableObserver<T>). - Reactive
Test - 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). - Test
Exception - An error made by a test, which compares by identity (
new Exception()of upstream’s tests). - Test
Scheduler - 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, …). - Test
Time - The virtual time of the test scheduler: ticks of 100 nanoseconds, as
TimeSpancounts them.
Enums§
- Expected
- A notification a test expects: one notification, or a notification that satisfies a predicate
(the predicate forms of
ReactiveTest.OnNextandOnError).
Functions§
- assert_
recorded_ eq - Asserts that the recorded notifications are the expected ones, in order (
AssertEqualon the messages of an observer or observable). - assert_
throws - Asserts that
actionpanics (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)).