Example #1
0
        public void SubscribeToChanges_OneFirstLevelPropertyChangesWithTwoLevelAccessTree_FiresExpectedChange()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person = new NotifyingPerson();

            person.Brother = new NotifyingPerson();

            int callCount            = 0;
            var callbackSubscription = _target.CreateCallbackSubscription <PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) =>
            {
                Assert.AreEqual(this, me);
                Assert.AreEqual(person, sender);
                callCount++;
            });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            person.Brother = new NotifyingPerson();

            Assert.AreEqual(1, callCount);
        }
Example #2
0
        public void UnsubscribeFromChanges_OneSecondLevelPropertyChanges_DoesNotFireChange()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person = new NotifyingPerson();

            person.Brother = new NotifyingPerson();

            int callCount            = 0;
            var callbackSubscription = _target.CreateCallbackSubscription <PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) =>
            {
                Assert.AreEqual(this, me);
                Assert.AreEqual(person, sender);
                callCount++;
            });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            callbackSubscription.UnsubscribeFromChanges(person, this);

            person.Brother.Age = 1234;

            Assert.AreEqual(0, callCount);
        }
Example #3
0
        public void SubscribeToChanges_TwoLevelAndSecondLevelReferenceDropped_SecondLevelIsGarbageCollected()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person    = new NotifyingPerson();
            WeakReference   personRef = new WeakReference(person);

            NotifyingPerson brother    = new NotifyingPerson();
            WeakReference   brotherRef = new WeakReference(brother);

            person.Brother = brother;

            var callbackSubscription = _target.CreateCallbackSubscription <PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) => {});

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            brother        = null;
            person.Brother = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(brotherRef.IsAlive);
        }
Example #4
0
 public void Setup()
 {
     _target          = new PropertyAccessTree();
     _person          = new NotifyingPerson();
     _ageProperty     = typeof(NotifyingPerson).GetProperty("Age");
     _brotherProperty = typeof(NotifyingPerson).GetProperty("Brother");
 }
 public void Setup()
 {
     _target = new PropertyAccessTree();
     _person = new NotifyingPerson();
     _ageProperty = typeof(NotifyingPerson).GetProperty("Age");
     _brotherProperty = typeof(NotifyingPerson).GetProperty("Brother");
 }
Example #6
0
        public void SubscribeToChanges_AllReferencesToSubjectDropped_SubjectIsGarbageCollected()
        {
            InitializeTargetJustAgeAccess();

            NotifyingPerson person    = new NotifyingPerson();
            WeakReference   personRef = new WeakReference(person);

            var callbackSubscription = _target.CreateCallbackSubscription <PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) => { });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            person = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(personRef.IsAlive);
        }
        public void SubscribeToChanges_AllReferencesToSubjectDropped_SubjectIsGarbageCollected()
        {
            InitializeTargetJustAgeAccess();

            NotifyingPerson person = new NotifyingPerson();
            WeakReference personRef = new WeakReference(person);

            var callbackSubscription = _target.CreateCallbackSubscription<PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) => { });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            person = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(personRef.IsAlive);
        }
        public void SubscribeToChanges_OneFirstLevelPropertyChangesWithTwoLevelAccessTree_FiresExpectedChange()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person = new NotifyingPerson();
            person.Brother = new NotifyingPerson();

            int callCount = 0;
            var callbackSubscription = _target.CreateCallbackSubscription<PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) =>
                {
                    Assert.AreEqual(this, me);
                    Assert.AreEqual(person, sender);
                    callCount++;
                });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            person.Brother = new NotifyingPerson();

            Assert.AreEqual(1, callCount);
        }
        public void UnsubscribeFromChanges_OneSecondLevelPropertyChanges_DoesNotFireChange()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person = new NotifyingPerson();
            person.Brother = new NotifyingPerson();

            int callCount = 0;
            var callbackSubscription = _target.CreateCallbackSubscription<PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) =>
                {
                    Assert.AreEqual(this, me);
                    Assert.AreEqual(person, sender);
                    callCount++;
                });

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            callbackSubscription.UnsubscribeFromChanges(person, this);

            person.Brother.Age = 1234;

            Assert.AreEqual(0, callCount);
        }
        public void SubscribeToChanges_TwoLevelAndSecondLevelReferenceDropped_SecondLevelIsGarbageCollected()
        {
            InitializeTargetBrothersAgeAccess();

            NotifyingPerson person = new NotifyingPerson();
            WeakReference personRef = new WeakReference(person);

            NotifyingPerson brother = new NotifyingPerson();
            WeakReference brotherRef = new WeakReference(brother);

            person.Brother = brother;

            var callbackSubscription = _target.CreateCallbackSubscription<PropertyAccessTreeNotifyingPropertyChangeTest>(
                (me, sender, args) => {});

            callbackSubscription.SubscribeToChanges(
                person,
                this);

            brother = null;
            person.Brother = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            Assert.IsFalse(brotherRef.IsAlive);
        }