public void all_sources_are_unsubscribed_when_complete_is_received() { var sourceA = new EventOwner(); var sourceC = new EventOwner(); var obs = Observable.Amb( sourceA.GetObservableEvent(), Observable.Empty<IEvent<EventArgs>>(), sourceC.GetObservableEvent() ); var stats = new StatsObserver<IEvent<EventArgs>>(); obs.Subscribe(stats); Assert.IsFalse(sourceA.HasSubscriptions); Assert.IsFalse(sourceC.HasSubscriptions); }
public void all_sources_are_unsubscribed_when_error_is_received() { var sourceA = new EventOwner(); var sourceB = new EventOwner(); var obs = Observable.Amb( sourceA.GetObservableEvent(), sourceB.GetObservableEvent(), Observable.Throw<IEvent<EventArgs>>(new Exception()) ); var stats = new StatsObserver<IEvent<EventArgs>>(); obs.Subscribe(stats); Assert.IsFalse(sourceA.HasSubscriptions); Assert.IsFalse(sourceB.HasSubscriptions); Assert.IsTrue(stats.ErrorCalled); }
public void complete_does_not_equate_to_value() { var eventOwnerA = new EventOwner(); var observableA = Observable.FromEvent<EventArgs>(x => eventOwnerA.Event += x, x => eventOwnerA.Event -= x); var stats = new StatsObserver<IEvent<EventArgs>>(); observableA .SkipUntil(Observable.Empty<int>()) .Subscribe(stats); eventOwnerA.Fire(); eventOwnerA.Fire(); eventOwnerA.Fire(); Assert.AreEqual(0, stats.NextCount); Assert.IsFalse(stats.CompletedCalled); }
public void other_sources_are_unsubscribed_when_value_is_received() { var sourceA = new EventOwner(); var sourceB = new EventOwner(); var sourceC = new EventOwner(); var obs = Observable.Amb( sourceA.GetObservableEvent(), sourceB.GetObservableEvent(), sourceC.GetObservableEvent() ); var stats = new StatsObserver<IEvent<EventArgs>>(); obs.Subscribe(stats); sourceB.Fire(); Assert.IsFalse(sourceA.HasSubscriptions); Assert.IsTrue(sourceB.HasSubscriptions); Assert.IsFalse(sourceC.HasSubscriptions); }
public void returns_values_after_other_emits_value() { var eventOwnerA = new EventOwner(); var eventOwnerB = new EventOwner(); var observableA = Observable.FromEvent<EventArgs>(x => eventOwnerA.Event += x, x => eventOwnerA.Event -= x); var observableB = Observable.FromEvent<EventArgs>(x => eventOwnerB.Event += x, x => eventOwnerB.Event -= x); var stats = new StatsObserver<IEvent<EventArgs>>(); observableA.SkipUntil(observableA) .Subscribe(stats); eventOwnerA.Fire(); eventOwnerA.Fire(); eventOwnerA.Fire(); eventOwnerB.Fire(); eventOwnerA.Fire(); Assert.AreEqual(3, stats.NextCount); }
public void source_is_unscribed_from_on_disconnect() { EventOwner owner = new EventOwner(); var source = owner.GetObservableEvent(); var obs = source.Prune(); var connection = obs.Connect(); Assert.IsTrue(owner.HasSubscriptions); connection.Dispose(); Assert.IsFalse(owner.HasSubscriptions); }
public void source_is_resubscribed_to_if_on_reconnect() { EventOwner owner = new EventOwner(); var source = owner.GetObservableEvent(); var obs = source.Prune(); var connectionA = obs.Connect(); Assert.IsTrue(owner.HasSubscriptions); connectionA.Dispose(); Assert.IsFalse(owner.HasSubscriptions); var connectionB = obs.Connect(); Assert.IsTrue(owner.HasSubscriptions); connectionB.Dispose(); Assert.IsFalse(owner.HasSubscriptions); }
public void source_is_only_subscribed_to_once_for_multiple_connections() { EventOwner owner = new EventOwner(); var source = owner.GetObservableEvent(); var obs = source.Prune(); obs.Connect(); obs.Connect(); Assert.AreEqual(1, owner.SubscriptionCount); }
public void source_is_not_subscribed_to_until_connect() { EventOwner owner = new EventOwner(); var source = owner.GetObservableEvent(); var obs = source.Prune(); Assert.IsFalse(owner.HasSubscriptions); obs.Connect(); Assert.IsTrue(owner.HasSubscriptions); }
public void Setup() { ev = new EventOwner(); obs = Observable.FromEvent<EventArgs>(e => ev.Event += e, e => ev.Event -= e); }