From 49f54b5275a87e6a06b21d214ee02562d5db0c17 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 12 Sep 2019 13:34:43 +0200 Subject: [PATCH] Added failing test for #2912. --- .../Data/BindingTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs b/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs index 0ba06980af..1cc007033b 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs @@ -196,6 +196,29 @@ namespace Avalonia.Markup.UnitTests.Data Assert.Equal("baz", target.Text); } + [Fact] + public void OneWayToSource_Binding_Should_Not_StackOverflow_With_Null_Value() + { + var target = new TextBlock { Text = null }; + var binding = new Binding + { + Path = "Foo", + Mode = BindingMode.OneWayToSource, + }; + + target.Bind(TextBox.TextProperty, binding); + + var source = new Source { Foo = "foo" }; + target.DataContext = source; + + Assert.Null(source.Foo); + + // When running tests under NCrunch, NCrunch replaces the standard StackOverflowException + // with its own, which will be caught by our code. Detect the stackoverflow anyway, by + // making sure the target property was only set once. + Assert.Equal(1, source.FooSetCount); + } + [Fact] public void Default_BindingMode_Should_Be_Used() { @@ -630,10 +653,13 @@ namespace Avalonia.Markup.UnitTests.Data set { _foo = value; + ++FooSetCount; RaisePropertyChanged(); } } + public int FooSetCount { get; private set; } + public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged([CallerMemberName] string prop = "")