Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer has been updated to the now released version 1.0 of Rx.</p> <p>Official documentation is still scant but <a href="http://msdn.microsoft.com/en-us/library/hh242967%28v=vs.103%29.aspx">Testing and Debugging Observable Sequences</a> on MSDN is a good starting place.</p> <p>The test class should derive from <a href="http://msdn.microsoft.com/en-us/library/microsoft.reactive.testing.reactivetest%28v=VS.103%29.aspx"><code>ReactiveTest</code></a> in the <code>Microsoft.Reactive.Testing</code> namespace. The test is based around a <a href="http://msdn.microsoft.com/en-us/library/microsoft.reactive.testing.testscheduler%28v=VS.103%29.aspx"><code>TestScheduler</code></a> that provides virtual time for the test.</p> <p>The <code>TestScheduler.Schedule</code> method can be used to queue up activities at certain points (ticks) in virtual time. The test is executed by <code>TestScheduler.Start</code>. This will return an <code>ITestableObserver&lt;T&gt;</code> that can be used for asserting for instance by using the <code>ReactiveAssert</code> class.</p> <pre><code>public class Fixture : ReactiveTest { public void SomethingHappenedTest() { // Arrange var scheduler = new TestScheduler(); var classUnderTest = new ClassUnderTest(); // Act scheduler.Schedule(TimeSpan.FromTicks(20), () =&gt; classUnderTest.DoSomething()); var actual = scheduler.Start( () =&gt; classUnderTest.SomethingHappened, created: 0, subscribed: 10, disposed: 100 ); // Assert var expected = new[] { OnNext(20, new Unit()) }; ReactiveAssert.AreElementsEqual(expected, actual.Messages); } } </code></pre> <p><code>TestScheduler.Schedule</code> is used to schedule a call to <code>DoSomething</code> at time 20 (measured in ticks).</p> <p>Then <code>TestScheduler.Start</code> is used to perform the actual test on the observable <code>SomethingHappened</code>. The lifetime of the subscription is controlled by the arguments to the call (again measured in ticks).</p> <p>Finally <code>ReactiveAssert.AreElementsEqual</code> is used to verify that <code>OnNext</code> was called at time 20 as expected.</p> <p>The test verifies that calling <code>DoSomething</code> immediately fires the observable <code>SomethingHappened</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload