public void complete_does_not_unsubscribe_from_other_subjects() { var subjectA = new StatsSubject<int>(); var subjectB = new StatsSubject<int>(); var subjectC = new StatsSubject<int>(); var subjectD = new StatsSubject<int>(); var stats = new StatsSubject<string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())), subjectC.And(subjectD).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnCompleted(); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(0, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); }
public void complete_does_not_unsubscribe_from_other_subjects() { var subjectA = new StatsSubject <int>(); var subjectB = new StatsSubject <int>(); var subjectC = new StatsSubject <int>(); var subjectD = new StatsSubject <int>(); var stats = new StatsObserver <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => x.ToString() + "," + y.ToString()), subjectC.And(subjectD).Then((x, y) => x.ToString() + "," + y.ToString()) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnCompleted(); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); }
public void SetUp() { stats = new StatsObserver <string>(); left = new StatsSubject <int>(); right = new StatsSubject <int>(); leftWindows = new List <StatsSubject <Unit> >(); rightWindows = new List <StatsSubject <Unit> >(); leftValueAction = rightValueAction = () => { }; combineAction = (l, r) => String.Format("{0},{1}", l, r); subscription = left.Join(right, leftVal => { leftValueAction(); var leftWindow = new StatsSubject <Unit>(); leftWindows.Add(leftWindow); return(leftWindow); }, rightVal => { rightValueAction(); var rightWindow = new StatsSubject <Unit>(); rightWindows.Add(rightWindow); return(rightWindow); }, (l, r) => combineAction(l, r) ) .Subscribe(stats); }
public void SetUp() { source = new Subject <int>(); windows = new List <StatsSubject <Unit> >(); windowsStats = new List <StatsObserver <int> >(); overallStats = new StatsObserver <int>(); subscription = source.Window(() => { StatsSubject <Unit> window = new StatsSubject <Unit>(); windows.Add(window); return(window); }) .Subscribe(o => { var stats = new StatsObserver <int>(); windowsStats.Add(stats); o.Subscribe(stats); }, overallStats.OnError, overallStats.OnCompleted); }
public void SetUp() { source = new Subject<int>(); windows = new List<StatsSubject<Unit>>(); windowsStats = new List<StatsObserver<int>>(); overallStats = new StatsObserver<int>(); subscription = source.Window(() => { StatsSubject<Unit> window = new StatsSubject<Unit>(); windows.Add(window); return window; }) .Subscribe(o => { var stats = new StatsObserver<int>(); windowsStats.Add(stats); o.Subscribe(stats); }, overallStats.OnError, overallStats.OnCompleted); }
public void errors_cause_all_subscriptions_to_be_removed() { var subjectA = new StatsSubject<int>(); var subjectB = new StatsSubject<int>(); var subjectC = new StatsSubject<int>(); var subjectD = new StatsSubject<int>(); var stats = new StatsSubject<string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())), subjectC.And(subjectD).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnError(new Exception()); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(0, subjectB.SubscriptionCount); Assert.AreEqual(0, subjectC.SubscriptionCount); Assert.AreEqual(0, subjectD.SubscriptionCount); }
public void errors_cause_all_subscriptions_to_be_removed() { var subjectA = new StatsSubject <int>(); var subjectB = new StatsSubject <int>(); var subjectC = new StatsSubject <int>(); var subjectD = new StatsSubject <int>(); var stats = new StatsSubject <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())), subjectC.And(subjectD).Then((x, y) => String.Concat(x.ToString(), ",", y.ToString())) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.AreEqual(1, subjectC.SubscriptionCount); Assert.AreEqual(1, subjectD.SubscriptionCount); subjectA.OnError(new Exception()); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(0, subjectB.SubscriptionCount); Assert.AreEqual(0, subjectC.SubscriptionCount); Assert.AreEqual(0, subjectD.SubscriptionCount); }
public void subscription_is_added_to_source_after_first_subscription() { var subject = new StatsSubject<int>(); var refCount = subject.Publish().RefCount(); Assert.AreEqual(0, subject.SubscriptionCount); refCount.Subscribe(new Subject<int>()); Assert.AreEqual(1, subject.SubscriptionCount); }
public void subscription_is_added_to_source_after_first_subscription() { var subject = new StatsSubject <int>(); var refCount = subject.Publish().RefCount(); Assert.AreEqual(0, subject.SubscriptionCount); refCount.Subscribe(new Subject <int>()); Assert.AreEqual(1, subject.SubscriptionCount); }
public void multiple_subscriptions_do_not_cause_subscriptions_to_the_source() { var subject = new StatsSubject <int>(); var refCount = subject.Publish().RefCount(); refCount.Subscribe(new Subject <int>()); Assert.AreEqual(1, subject.SubscriptionCount); refCount.Subscribe(new Subject <int>()); Assert.AreEqual(1, subject.SubscriptionCount); }
public void multiple_subscriptions_do_not_cause_subscriptions_to_the_source() { var subject = new StatsSubject<int>(); var refCount = subject.Publish().RefCount(); refCount.Subscribe(new Subject<int>()); Assert.AreEqual(1, subject.SubscriptionCount); refCount.Subscribe(new Subject<int>()); Assert.AreEqual(1, subject.SubscriptionCount); }
public void error_is_fired_on_error_from_either_source() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnError(new Exception()); Assert.IsTrue(stats.ErrorCalled); }
public void error_is_fired_on_error_from_either_source() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnError(new Exception()); Assert.IsTrue(stats.ErrorCalled); }
public void subscribes_to_both_sources() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.IsFalse(stats.CompletedCalled); }
public void unsubscribes_from_both_sequences_on_error() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnError(new Exception()); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(0, subjectB.SubscriptionCount); }
public void connecting_multiple_times_does_not_subscribe_to_source_multiple_times() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); connectable.Connect(); connectable.Connect(); Assert.AreEqual(1, source.SubscriptionCount); }
public void scheduler_is_not_used_when_count_great_than_zero() { var scheduler = new ManualScheduler(); var subject = new StatsSubject <int>(); var stats = new StatsObserver <int>(); subject.Take(3, scheduler).Subscribe(stats); subject.OnNext(0); subject.OnNext(1); subject.OnNext(2); Assert.AreEqual(0, scheduler.QueueSize); }
public void subscribes_once_when_subscription_is_repeated_within_join() { var subjectA = new StatsSubject <int>(); var subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => (string)null), subjectB.And(subjectA).Then((x, y) => (string)null) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); }
public void scheduler_is_not_used_when_count_great_than_zero() { var scheduler = new ManualScheduler(); var subject = new StatsSubject<int>(); var stats = new StatsObserver<int>(); subject.Take(3, scheduler).Subscribe(stats); subject.OnNext(0); subject.OnNext(1); subject.OnNext(2); Assert.AreEqual(0, scheduler.QueueSize); }
public void connecting_multiple_times_does_not_subscribe_to_source_multiple_times() { StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> source = new StatsSubject <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); var sub = connectable.Subscribe(stats); connectable.Connect(); connectable.Connect(); Assert.AreEqual(1, source.SubscriptionCount); }
public void emits_combinations_of_the_latest_values() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectB.OnNext(2); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.IsFalse(stats.CompletedCalled); }
public void values_are_received_by_all_subscriptions() { var subject = new StatsSubject <int>(); var statsA = new StatsObserver <int>(); var statsB = new StatsObserver <int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(statsA); var subscriptionB = refCount.Subscribe(statsB); subject.OnNext(0); Assert.AreEqual(1, statsA.NextCount); Assert.AreEqual(1, statsB.NextCount); }
public void connecting_subscribes_to_source() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); Assert.IsFalse(source.HasSubscriptions); connectable.Connect(); Assert.IsTrue(source.HasSubscriptions); }
public void values_are_not_received_by_unsubscribed_observers() { var subject = new StatsSubject<int>(); var statsA = new StatsObserver<int>(); var statsB = new StatsObserver<int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(statsA); refCount.Subscribe(statsB).Dispose(); subject.OnNext(0); Assert.AreEqual(1, statsA.NextCount); Assert.AreEqual(0, statsB.NextCount); }
public void subscriptions_is_disposed_after_last_child_susbcription_is_disposed() { var subject = new StatsSubject <int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(new Subject <int>()); var subscriptionB = refCount.Subscribe(new Subject <int>()); Assert.AreEqual(1, subject.SubscriptionCount); subscriptionA.Dispose(); Assert.AreEqual(1, subject.SubscriptionCount); subscriptionB.Dispose(); Assert.AreEqual(0, subject.SubscriptionCount); }
public void subscriptions_is_disposed_after_last_child_susbcription_is_disposed() { var subject = new StatsSubject<int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(new Subject<int>()); var subscriptionB = refCount.Subscribe(new Subject<int>()); Assert.AreEqual(1, subject.SubscriptionCount); subscriptionA.Dispose(); Assert.AreEqual(1, subject.SubscriptionCount); subscriptionB.Dispose(); Assert.AreEqual(0, subject.SubscriptionCount); }
public void emits_combinations_of_the_latest_values() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectB.OnNext(2); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.IsFalse(stats.CompletedCalled); }
public void disconnecting_subscribes_to_source() { StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> source = new StatsSubject <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); var sub = connectable.Subscribe(stats); Assert.IsFalse(source.HasSubscriptions); connectable.Connect().Dispose(); Assert.IsFalse(source.HasSubscriptions); }
public void SetUp() { groupedValues = new StatsSubject <Tuple <int, IObservable <int> > >(); stats = new StatsObserver <string>(); left = new StatsSubject <int>(); right = new StatsSubject <int>(); leftWindows = new List <StatsSubject <Unit> >(); rightWindows = new List <StatsSubject <Unit> >(); leftValueAction = rightValueAction = () => { }; combineAction = (l, r) => {}; subscription = new CompositeDisposable(); subscription.Add(left.GroupJoin(right, leftVal => { leftValueAction(); var leftWindow = new StatsSubject <Unit>(); leftWindows.Add(leftWindow); return(leftWindow); }, rightVal => { rightValueAction(); var rightWindow = new StatsSubject <Unit>(); rightWindows.Add(rightWindow); return(rightWindow); }, (l, r) => { combineAction(l, r); return(new Tuple <int, IObservable <int> >(l, r)); }) .Subscribe(groupedValues)); subscription.Add(groupedValues .SelectMany(input => input.Item2.Select(r => new Tuple <int, int>(input.Item1, r))) .Select(t => String.Format("{0},{1}", t.Item1, t.Item2)) .Subscribe(stats)); }
public void errors_cause_unsubscription_of_everything() { var subject = new StatsSubject<int>(); var statsA = new StatsObserver<int>(); var statsB = new StatsObserver<int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(statsA); var subscriptionB = refCount.Subscribe(statsB); subject.OnError(new Exception()); Assert.AreEqual(1, statsA.ErrorCount); Assert.AreEqual(1, statsB.ErrorCount); Assert.AreEqual(0, subject.SubscriptionCount); }
public void scheduler_is_used_for_first_subscription() { var sourceA = new StatsSubject <int>(); var sourceB = Observable.Empty <int>(); var scheduler = new ManualScheduler(); var stats = new StatsObserver <int>(); sourceA.Concat(sourceB, scheduler).Subscribe(stats); Assert.AreEqual(0, sourceA.SubscriptionCount); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.AreEqual(1, sourceA.SubscriptionCount); Assert.AreEqual(0, scheduler.QueueSize); }
public void errors_cause_unsubscription_of_everything() { var subject = new StatsSubject <int>(); var statsA = new StatsObserver <int>(); var statsB = new StatsObserver <int>(); var refCount = subject.Publish().RefCount(); var subscriptionA = refCount.Subscribe(statsA); var subscriptionB = refCount.Subscribe(statsB); subject.OnError(new Exception()); Assert.AreEqual(1, statsA.ErrorCount); Assert.AreEqual(1, statsB.ErrorCount); Assert.AreEqual(0, subject.SubscriptionCount); }
public void scheduler_is_used_for_first_subscription() { var sourceA = new StatsSubject<int>(); var sourceB = Observable.Empty<int>(); var scheduler = new ManualScheduler(); var stats = new StatsObserver<int>(); sourceA.Concat(sourceB, scheduler).Subscribe(stats); Assert.AreEqual(0, sourceA.SubscriptionCount); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.AreEqual(1, sourceA.SubscriptionCount); Assert.AreEqual(0, scheduler.QueueSize); }
public void durations_are_unsubscribed_from_onerror() { var groupStats = new StatsObserver <IGroupedObservable <int, int> >(); var durationSubjects = new List <StatsSubject <int> >(); source.ToObservable().Concat(Observable.Throw <GroupableObject>(new Exception())).GroupByUntil(x => x.Key, x => x.Value, g => { var duration = new StatsSubject <int>(); durationSubjects.Add(duration); return(duration); }) .Subscribe(groupStats); Assert.AreEqual( durationSubjects.Select(_ => false).ToArray(), durationSubjects.Select(s => s.HasSubscriptions).ToArray() ); }
public void disconnecting_does_not_remove_subscriptions() { IObservable <int> source = Observable.Empty <int>(); StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); Assert.IsFalse(subject.HasSubscriptions); var sub = connectable.Subscribe(stats); Assert.IsTrue(subject.HasSubscriptions); connectable.Connect().Dispose(); Assert.IsTrue(subject.HasSubscriptions); }
public void disconnecting_does_not_remove_subscriptions() { IObservable<int> source = Observable.Empty<int>(); StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); Assert.IsFalse(subject.HasSubscriptions); var sub = connectable.Subscribe(stats); Assert.IsTrue(subject.HasSubscriptions); connectable.Connect().Dispose(); Assert.IsTrue(subject.HasSubscriptions); }
public void uses_subject_for_subscriptions() { IObservable <int> source = Observable.Empty <int>(); StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); Assert.IsFalse(subject.HasSubscriptions); var sub = connectable.Subscribe(stats); Assert.IsTrue(subject.HasSubscriptions); sub.Dispose(); Assert.IsFalse(subject.HasSubscriptions); }
public void values_send_before_completion_are_ignored() { StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> source = new StatsSubject <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); source.OnCompleted(); source.OnError(new Exception()); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void complete_is_fired_when_both_sequences_complete() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectA.OnCompleted(); subjectB.OnNext(2); subjectB.OnCompleted(); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.IsTrue(stats.CompletedCalled); }
public void complete_is_fired_when_both_sequences_complete() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectA.OnCompleted(); subjectB.OnNext(2); subjectB.OnCompleted(); Assert.AreEqual(1, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.IsTrue(stats.CompletedCalled); }
public void disconnecting_first_of_multiple_connections_subscribes_to_source() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); Assert.IsFalse(source.HasSubscriptions); var connectionA = connectable.Connect(); var connectionB = connectable.Connect(); connectionA.Dispose(); Assert.IsFalse(source.HasSubscriptions); }
public void last_value_is_still_used_after_complete() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectA.OnCompleted(); subjectB.OnNext(2); subjectB.OnNext(3); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.AreEqual("1,3", stats.NextValues[1]); Assert.IsFalse(stats.CompletedCalled); }
public void reuses_values() { StatsSubject <int> subjectA = new StatsSubject <int>(); StatsSubject <int> subjectB = new StatsSubject <int>(); var stats = new StatsObserver <string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectB.OnNext(2); subjectA.OnNext(3); subjectB.OnNext(4); Assert.AreEqual(3, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.AreEqual("3,2", stats.NextValues[1]); Assert.AreEqual("3,4", stats.NextValues[2]); Assert.IsFalse(stats.CompletedCalled); }
public void scheduler_used_to_subscribe_to_each_sequence() { var stats = new StatsObserver<int>(); var scheduler = new ManualScheduler(); var subjectA = new StatsSubject<int>(); var subjectB = new StatsSubject<int>(); var subjectC = new StatsSubject<int>(); Observable.Merge( scheduler, subjectA, subjectB, subjectC ) .Subscribe(stats); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectA.HasSubscriptions); Assert.IsFalse(subjectB.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectB.HasSubscriptions); Assert.IsFalse(subjectC.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectC.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.AreEqual(0, scheduler.QueueSize); }
public void scheduler_used_to_subscribe_to_each_sequence() { var stats = new StatsObserver <int>(); var scheduler = new ManualScheduler(); var subjectA = new StatsSubject <int>(); var subjectB = new StatsSubject <int>(); var subjectC = new StatsSubject <int>(); Observable.Merge( scheduler, subjectA, subjectB, subjectC ) .Subscribe(stats); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectA.HasSubscriptions); Assert.IsFalse(subjectB.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectB.HasSubscriptions); Assert.IsFalse(subjectC.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.IsTrue(subjectC.HasSubscriptions); Assert.AreEqual(1, scheduler.QueueSize); scheduler.RunNext(); Assert.AreEqual(0, scheduler.QueueSize); }
public void operations_are_passed_on_once_connected() { StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> source = new StatsSubject <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); connectable.Connect(); source.OnNext(1); Assert.IsTrue(stats.NextCalled); Assert.AreEqual(1, stats.NextValues[0]); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void operation_order_is_honoured_prior_to_connection() { StatsObserver <int> stats = new StatsObserver <int>(); StatsSubject <int> source = new StatsSubject <int>(); StatsSubject <int> subject = new StatsSubject <int>(); ConnectableObservable <int> connectable = new ConnectableObservable <int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); source.OnCompleted(); connectable.Connect(); source.OnNext(1); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void SetUp() { groupedValues = new StatsSubject<Tuple<int, IObservable<int>>>(); stats = new StatsObserver<string>(); left = new StatsSubject<int>(); right = new StatsSubject<int>(); leftWindows = new List<StatsSubject<Unit>>(); rightWindows = new List<StatsSubject<Unit>>(); leftValueAction = rightValueAction = () => { }; combineAction = (l, r) => {}; subscription = new CompositeDisposable(); subscription.Add(left.GroupJoin(right, leftVal => { leftValueAction(); var leftWindow = new StatsSubject<Unit>(); leftWindows.Add(leftWindow); return leftWindow; }, rightVal => { rightValueAction(); var rightWindow = new StatsSubject<Unit>(); rightWindows.Add(rightWindow); return rightWindow; }, (l, r) => { combineAction(l,r); return new Tuple<int, IObservable<int>>(l, r); }) .Subscribe(groupedValues)); subscription.Add(groupedValues .SelectMany(input => input.Item2.Select(r => new Tuple<int, int>(input.Item1, r))) .Select(t => String.Format("{0},{1}", t.Item1, t.Item2)) .Subscribe(stats)); }
public void reuses_values() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectB.OnNext(2); subjectA.OnNext(3); subjectB.OnNext(4); Assert.AreEqual(3, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.AreEqual("3,2", stats.NextValues[1]); Assert.AreEqual("3,4", stats.NextValues[2]); Assert.IsFalse(stats.CompletedCalled); }
public void subscribes_to_both_sources() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a,b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); Assert.IsFalse(stats.CompletedCalled); }
public void unsubscribes_from_both_sequences_when_complete() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnCompleted(); subjectB.OnCompleted(); Assert.AreEqual(0, subjectA.SubscriptionCount); Assert.AreEqual(0, subjectB.SubscriptionCount); }
public void operations_are_passed_on_once_connected() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); connectable.Connect(); source.OnNext(1); Assert.IsTrue(stats.NextCalled); Assert.AreEqual(1, stats.NextValues[0]); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void operation_order_is_honoured_prior_to_connection() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); source.OnCompleted(); connectable.Connect(); source.OnNext(1); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void uses_subject_for_subscriptions() { IObservable<int> source = Observable.Empty<int>(); StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); Assert.IsFalse(subject.HasSubscriptions); var sub = connectable.Subscribe(stats); Assert.IsTrue(subject.HasSubscriptions); sub.Dispose(); Assert.IsFalse(subject.HasSubscriptions); }
public void values_send_before_completion_are_ignored() { StatsObserver<int> stats = new StatsObserver<int>(); StatsSubject<int> source = new StatsSubject<int>(); StatsSubject<int> subject = new StatsSubject<int>(); ConnectableObservable<int> connectable = new ConnectableObservable<int>(source, subject); var sub = connectable.Subscribe(stats); source.OnNext(0); source.OnCompleted(); source.OnError(new Exception()); Assert.IsFalse(stats.NextCalled); Assert.IsFalse(stats.CompletedCalled); Assert.IsFalse(stats.ErrorCalled); }
public void last_value_is_still_used_after_complete() { StatsSubject<int> subjectA = new StatsSubject<int>(); StatsSubject<int> subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); subjectA.CombineLatest(subjectB, (a, b) => String.Concat(a.ToString(), ",", b.ToString())) .Subscribe(stats); subjectA.OnNext(1); subjectA.OnCompleted(); subjectB.OnNext(2); subjectB.OnNext(3); Assert.AreEqual(2, stats.NextCount); Assert.AreEqual("1,2", stats.NextValues[0]); Assert.AreEqual("1,3", stats.NextValues[1]); Assert.IsFalse(stats.CompletedCalled); }
public void SetUp() { stats = new StatsObserver<string>(); left = new StatsSubject<int>(); right = new StatsSubject<int>(); leftWindows = new List<StatsSubject<Unit>>(); rightWindows = new List<StatsSubject<Unit>>(); leftValueAction = rightValueAction = () => { }; combineAction = (l, r) => String.Format("{0},{1}", l, r); subscription = left.Join(right, leftVal => { leftValueAction(); var leftWindow = new StatsSubject<Unit>(); leftWindows.Add(leftWindow); return leftWindow; }, rightVal => { rightValueAction(); var rightWindow = new StatsSubject<Unit>(); rightWindows.Add(rightWindow); return rightWindow; }, (l, r) => combineAction(l,r) ) .Subscribe(stats); }
public void subscribes_once_when_subscription_is_repeated_within_join() { var subjectA = new StatsSubject<int>(); var subjectB = new StatsSubject<int>(); var stats = new StatsObserver<string>(); Observable.Join( subjectA.And(subjectB).Then((x, y) => (string)null), subjectB.And(subjectA).Then((x, y) => (string)null) ) .Subscribe(stats); Assert.AreEqual(1, subjectA.SubscriptionCount); Assert.AreEqual(1, subjectB.SubscriptionCount); }