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 ); } }
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 ) ); }
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 ) ); } }
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 ) ); }