mirror of https://github.com/AMT-Cheif/Stylet.git
Finish off (?) the PropertyChangedExtensionsTests
This commit is contained in:
parent
684995eb98
commit
cc8e3343cf
|
@ -31,6 +31,7 @@ namespace Stylet
|
|||
this.binder = new WeakReference(binder);
|
||||
this.inpc = new WeakReference<INotifyPropertyChanged>(inpc);
|
||||
this.propertyName = propertyName;
|
||||
// We need to keep this strongly, in case its target is a compiler-generated class instance
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
|
|
|
@ -169,14 +169,30 @@ namespace StyletUnitTests
|
|||
var weakBinding = new WeakReference<BindingClass>(binding);
|
||||
|
||||
var notifying = new NotifyingClass();
|
||||
// Retain binder, in case that affects anything
|
||||
var binder = binding.BindWeak(notifying);
|
||||
binding.BindWeak(notifying);
|
||||
|
||||
binding = null;
|
||||
GC.Collect();
|
||||
Assert.IsFalse(weakBinding.TryGetTarget(out binding));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeakBindingRetainsClassIfIPropertyChangedBindingRetained()
|
||||
{
|
||||
var binding = new BindingClass();
|
||||
|
||||
// Means of determining whether the class has been disposed
|
||||
var weakBinding = new WeakReference<BindingClass>(binding);
|
||||
|
||||
var notifying = new NotifyingClass();
|
||||
// Retain this
|
||||
var binder = binding.BindWeak(notifying);
|
||||
|
||||
binding = null;
|
||||
GC.Collect();
|
||||
Assert.IsTrue(weakBinding.TryGetTarget(out binding));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeakBindingDoesNotRetainNotifier()
|
||||
{
|
||||
|
@ -191,5 +207,17 @@ namespace StyletUnitTests
|
|||
GC.Collect();
|
||||
Assert.IsFalse(weakNotifying.TryGetTarget(out notifying));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeakBindingUnbinds()
|
||||
{
|
||||
string newVal = null;
|
||||
var c1 = new NotifyingClass();
|
||||
var binding = c1.BindWeak(this, x => x.Bar, x => newVal = x);
|
||||
binding.Unbind();
|
||||
c1.Bar = "bar";
|
||||
|
||||
Assert.AreEqual(null, newVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue