@ -54,6 +54,36 @@ namespace Avalonia.Base.UnitTests
Assert . False ( target . IsSet ( Class1 . QuxProperty ) ) ;
}
[Fact]
public void OneTime_Binding_Ignores_UnsetValue ( )
{
var target = new Class1 ( ) ;
var source = new Subject < object > ( ) ;
target . Bind ( Class1 . QuxProperty , new TestOneTimeBinding ( source ) ) ;
source . OnNext ( AvaloniaProperty . UnsetValue ) ;
Assert . Equal ( 5.6 , target . GetValue ( Class1 . QuxProperty ) ) ;
source . OnNext ( 6.7 ) ;
Assert . Equal ( 6.7 , target . GetValue ( Class1 . QuxProperty ) ) ;
}
[Fact]
public void OneTime_Binding_Ignores_Binding_Errors ( )
{
var target = new Class1 ( ) ;
var source = new Subject < object > ( ) ;
target . Bind ( Class1 . QuxProperty , new TestOneTimeBinding ( source ) ) ;
source . OnNext ( new BindingNotification ( new Exception ( ) , BindingErrorType . Error ) ) ;
Assert . Equal ( 5.6 , target . GetValue ( Class1 . QuxProperty ) ) ;
source . OnNext ( 6.7 ) ;
Assert . Equal ( 6.7 , target . GetValue ( Class1 . QuxProperty ) ) ;
}
[Fact]
public void Bind_Throws_Exception_For_Unregistered_Property ( )
{
@ -352,5 +382,24 @@ namespace Avalonia.Base.UnitTests
public static readonly StyledProperty < string > BarProperty =
AvaloniaProperty . Register < Class2 , string > ( "Bar" , "bardefault" ) ;
}
private class TestOneTimeBinding : IBinding
{
private IObservable < object > _ source ;
public TestOneTimeBinding ( IObservable < object > source )
{
_ source = source ;
}
public InstancedBinding Initiate (
IAvaloniaObject target ,
AvaloniaProperty targetProperty ,
object anchor = null ,
bool enableDataValidation = false )
{
return new InstancedBinding ( _ source , BindingMode . OneTime ) ;
}
}
}
}