Esempio n. 1
0
        public void AddWeakHandler_WhenCrossSubscriptions_NotAlives()
        {
            var handlers = new List <WeakEventHandler <EventArgs> >();

            WeakHelpers.ExecuteAndCollect(() =>
            {
                var pubsub1 = new Subscriber();
                var pubsub2 = new Subscriber();
                handlers.Add(pubsub2.AddWeakHandler <EventArgs>(nameof(Publisher.Event), pubsub1.OnEventRaised));
                handlers.Add(pubsub1.AddWeakHandler <EventArgs>(nameof(Publisher.Event), pubsub2.OnEventRaised));
            });

            Assert.IsTrue(handlers.Any((a) => !a.IsAlive));
        }
Esempio n. 2
0
        public void TwoWayBinding_ReferencesDestroyed_BindingNotAlive()
        {
            IBinding binding = null;

            WeakHelpers.ExecuteAndCollect(() =>
            {
                var source = new Observable <int>();
                var target = new Observable <int>();

                binding = target.Bind(source).Property(s => s.Value, t => t.Value, Transmute.Transmuter.Default.GetConverter <int, int>());
            });

            Assert.IsFalse(binding.IsAlive);
        }
Esempio n. 3
0
        public void AddWeakHandler_WhenSubscriberDestroyed_Unsubscription()
        {
            var publisher = new Publisher();

            WeakHelpers.ExecuteAndCollect(() =>
            {
                var subscriber = new Subscriber();
                publisher.AddWeakHandler <EventArgs>(nameof(publisher.Event), subscriber.OnEventRaised);
            });

            publisher.RaiseEvent();

            Assert.IsFalse(publisher.HasSubscriptions);
        }