Skip to content

Commit

Permalink
test: Property change propagation and callback order
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jul 21, 2021
1 parent b3f64a6 commit 480b30c
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/Uno.UI.Tests/DependencyProperty/Given_DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,61 @@ public void When_Set_Style_Property_FromCallback_PrecedenceInContext_No_Local()
sut.Tag = style;
}

[TestMethod]
public void When_Callback_And_Changed_With_Binding()
{
var source = new ChangedCallbackOrderElement();
var target = new ChangedCallbackOrderElement();
var binding = new Binding()
{
Source = target,
Path = new PropertyPath("Test"),
Mode = BindingMode.TwoWay
};
source.SetBinding(ChangedCallbackOrderElement.TestProperty, binding);

int order = 0;

void OnSourceChanged(object s, object e)
{
order++;
Assert.AreEqual(true, source.Test);
Assert.AreEqual(false, target.Test);
Assert.AreEqual(1, order);
}

void OnTargetChanged(object s, object e)
{
order++;
Assert.AreEqual(true, source.Test);
Assert.AreEqual(true, target.Test);
Assert.AreEqual(2, order);
}

void OnTargetCallback(object s, object e)
{
order++;
Assert.AreEqual(true, source.Test);
Assert.AreEqual(true, target.Test);
Assert.AreEqual(3, order);
}

void OnSourceCallback(object s, object e)
{
order++;
Assert.AreEqual(true, source.Test);
Assert.AreEqual(true, target.Test);
Assert.AreEqual(4, order);
}

source.TestCallback += OnSourceCallback;
target.TestCallback += OnTargetCallback;
source.TestChanged += OnSourceChanged;
target.TestChanged += OnTargetChanged;

source.Test = true;
}

[TestMethod]
public void When_Set_With_Both_Style_And_LocalValue()
{
Expand Down Expand Up @@ -1829,6 +1884,41 @@ public int MyProperty

}

public class ChangedCallbackOrderElement : FrameworkElement
{
public ChangedCallbackOrderElement()
{
this.RegisterPropertyChangedCallback(TestProperty, OnTestCallback);
}

public event EventHandler TestChanged;
public event EventHandler TestCallback;

public bool Test
{
get => (bool)GetValue(TestProperty);
set => SetValue(TestProperty, value);
}

public static readonly DependencyProperty TestProperty =
DependencyProperty.Register(
nameof(Test),
typeof(bool),
typeof(ChangedCallbackOrderElement),
new PropertyMetadata(false, OnTestChanged));

private static void OnTestChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var custom = (ChangedCallbackOrderElement)d;
custom.TestChanged?.Invoke(custom, null);
}

private void OnTestCallback(DependencyObject sender, DependencyProperty dp)
{
TestCallback?.Invoke(this, null);
}
}


#endregion
}

0 comments on commit 480b30c

Please sign in to comment.