示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
 public void Setup()
 {
     ev = new EventOwner();
     obs = Observable.FromEvent<EventArgs>(e => ev.Event += e, e => ev.Event -= e);
 }