public void with_both_window_and_buffer_size_values_can_be_ignored_by_window() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(3, TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; // ignored by window subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(8); subject.OnCompleted(); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 })); Assert.IsTrue(stats.CompletedCalled); }
public void window_includes_onerror() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(10); subject.OnError(new Exception()); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(1, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 })); Assert.IsTrue(stats.ErrorCalled); }
public void honours_window_for_replays_with_priority_to_most_recent() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnNext(1); scheduler.Now = start.AddMilliseconds(5); subject.OnNext(2); scheduler.Now = start.AddMilliseconds(10); subject.OnNext(3); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(2, stats.NextCount); Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2, 3 })); Assert.IsFalse(stats.CompletedCalled); }
public void publishing_is_run_through_publishing_scheduler() { ManualScheduler scheduler = new ManualScheduler(); obs = Observable.Empty <int>(scheduler); bool completed = false; var subs = obs.Subscribe(x => { }, () => completed = true); Assert.IsFalse(completed); scheduler.RunAll(); Assert.IsTrue(completed); }
public void catch_with_observer_subscribes_to_first_through_scheduler() { ManualScheduler scheduler = new ManualScheduler(); StatsObserver <IEvent <EventArgs> > observer = new StatsObserver <IEvent <EventArgs> >(); EventOwner owner = new EventOwner(); Observable.FromEvent <EventArgs>(x => owner.Event += x, x => owner.Event -= x) .Catch(Observable.Empty <IEvent <EventArgs> >(), scheduler) .Subscribe(observer); Assert.IsFalse(owner.HasSubscriptions); scheduler.RunAll(); Assert.IsTrue(owner.HasSubscriptions); }
public void scheduler_is_used_to_send_values() { Subject <int> subject = new Subject <int>(); var scheduler = new ManualScheduler(); var stats = new StatsObserver <int>(); var obs = subject.Prune(scheduler); var connection = obs.Connect(); subject.OnNext(1); subject.OnCompleted(); obs.Subscribe(stats); scheduler.RunAll(); Assert.IsTrue(stats.NextCalled); Assert.IsTrue(stats.CompletedCalled); }
public void window_can_pass_error() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnError(new Exception()); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.IsFalse(stats.ErrorCalled); }
public void window_can_pass_complete() { ManualScheduler scheduler = new ManualScheduler(); ReplaySubject <int> subject = new ReplaySubject <int>(TimeSpan.FromMilliseconds(10), scheduler); StatsObserver <int> stats = new StatsObserver <int>(); DateTime start = DateTime.UtcNow; scheduler.Now = start; subject.OnCompleted(); scheduler.Now = start.AddMilliseconds(11); subject.Subscribe(stats); scheduler.RunAll(); Assert.AreEqual(0, stats.NextCount); Assert.IsFalse(stats.CompletedCalled); }