|
|
|
@ -333,6 +333,50 @@ namespace Perspex.Base.UnitTests |
|
|
|
Assert.Equal("second", target.Foo); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Direct_Property_Does_Not_Get_Collected() |
|
|
|
{ |
|
|
|
var target = new Class2(); |
|
|
|
|
|
|
|
Func<WeakReference> setupBinding = () => |
|
|
|
{ |
|
|
|
var source = new Subject<string>(); |
|
|
|
var sub = target.Bind((PerspexProperty)Class1.FooProperty, source); |
|
|
|
return new WeakReference(source); |
|
|
|
}; |
|
|
|
|
|
|
|
var weakSource = setupBinding(); |
|
|
|
|
|
|
|
GC.Collect(); |
|
|
|
|
|
|
|
Assert.True(weakSource.IsAlive); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_To_Direct_Property_Gets_Collected_When_Completed() |
|
|
|
{ |
|
|
|
var target = new Class2(); |
|
|
|
|
|
|
|
Func<WeakReference> setupBinding = () => |
|
|
|
{ |
|
|
|
var source = new Subject<string>(); |
|
|
|
var sub = target.Bind((PerspexProperty)Class1.FooProperty, source); |
|
|
|
return new WeakReference(source); |
|
|
|
}; |
|
|
|
|
|
|
|
var weakSource = setupBinding(); |
|
|
|
|
|
|
|
Action completeSource = () => |
|
|
|
{ |
|
|
|
((ISubject<string>)weakSource.Target).OnCompleted(); |
|
|
|
}; |
|
|
|
|
|
|
|
completeSource(); |
|
|
|
GC.Collect(); |
|
|
|
|
|
|
|
Assert.False(weakSource.IsAlive); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Property_Notifies_Initialized() |
|
|
|
{ |
|
|
|
|