Ejemplo n.º 1
0
        public void PropertyOwnersMarkedForGC_BindingReleased()
        {
            WeakReference<ViewModel1> wr1 = null;
            WeakReference<ViewModel2> wr2 = null;

            new Action( () =>
            {
                var vm1 = new ViewModel1();
                var vm2 = new ViewModel2();

                wr1 = new WeakReference<ViewModel1>( vm1 );
                wr2 = new WeakReference<ViewModel2>( vm2 );

                PropertyBinding.Bind( () => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay );
            } )();

            EnforceGC();

            {
                ViewModel1 vm1;
                Assert.That( wr1.TryGetTarget( out vm1 ), Is.False );

                ViewModel2 vm2;
                Assert.That( wr2.TryGetTarget( out vm2 ), Is.False );
            }
        }
Ejemplo n.º 2
0
        public void Create_ExpressionWithLocalVariable_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create( () => vm.PrimaryValue );

            Assert.That( prop.Owner, Is.EqualTo( vm ) );
            Assert.That( prop.PropertyName, Is.EqualTo( "PrimaryValue" ) );
        }
Ejemplo n.º 3
0
        public void Create_ExpressionPath_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create( () => vm.Model.ModelValue );

            Assert.That( prop.Owner, Is.EqualTo( vm.Model ) );
            Assert.That( prop.PropertyName, Is.EqualTo( "ModelValue" ) );
        }
Ejemplo n.º 4
0
        public void OneWayToSourceBinding_ChangesOnTargetNotSyncedtoSource()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind( () => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.OneWayToSource );

            vm1.PrimaryValue = 42;
            Assert.That( vm2.SecondaryValue, Is.Not.EqualTo( 42 ) );
        }
Ejemplo n.º 5
0
        public void Create_InstanceAndPropertyName_OwnerAndPropertyCorrectlyDetected()
        {
            var vm = new ViewModel1();

            var prop = BindableProperty.Create( vm, "PrimaryValue" );

            Assert.That( prop.Owner, Is.EqualTo( vm ) );
            Assert.That( prop.PropertyName, Is.EqualTo( "PrimaryValue" ) );
        }
Ejemplo n.º 6
0
        public void PropertyOwnersStillAlive_BindingsSurvivesGC()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind( () => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay );

            EnforceGC();

            {
                // lets see whether binding still works
                vm1.PrimaryValue = 42;
                Assert.That( vm2.SecondaryValue, Is.EqualTo( 42 ) );
            }
        }
Ejemplo n.º 7
0
        public void TwoWayBinding_ChangesOnEitherEndSyncedToTheOtherOne()
        {
            var vm1 = new ViewModel1();
            var vm2 = new ViewModel2();

            PropertyBinding.Bind( () => vm1.PrimaryValue, () => vm2.SecondaryValue, BindingMode.TwoWay );

            vm1.PrimaryValue = 42;
            Assert.That( vm2.SecondaryValue, Is.EqualTo( 42 ) );

            vm2.SecondaryValue = 24;
            Assert.That( vm1.PrimaryValue, Is.EqualTo( 24 ) );
        }