public void When_Path_Invalid() { var SUT = new MyObject(); var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B")); Assert.AreEqual(0, sub.MyProperty); Assert.AreEqual(0, sub.MyPropertyCounter); SUT.SubObject = sub; Assert.AreEqual(0, sub.MyProperty); Assert.AreEqual(0, sub.MyPropertyCounter); SUT.DataContext = 42; Assert.AreEqual(0, sub.MyProperty); Assert.AreEqual(0, sub.MyPropertyCounter); SUT.DataContext = new PropagationContext(); Assert.AreEqual(43, sub.MyProperty); Assert.AreEqual(1, sub.MyPropertyCounter); }
public void When_Path_Invalid_And_NotifyPropertyChanged() { var SUT = new MyObject(); var sub = new SubObject(); sub.SetBinding(SubObject.MyStringPropertyProperty, new Binding("C.D")); Assert.AreEqual("", sub.MyStringProperty); Assert.AreEqual(0, sub.MyStringPropertyCounter); SUT.SubObject = sub; Assert.AreEqual("", sub.MyStringProperty); Assert.AreEqual(0, sub.MyStringPropertyCounter); SUT.DataContext = new PropagationContext2(); Assert.AreEqual("", sub.MyStringProperty); Assert.AreEqual(0, sub.MyStringPropertyCounter); SUT.DataContext = new PropagationContext(); Assert.AreEqual("44", sub.MyStringProperty); // This must be one, even if the original binding was // set to an invalid property path for PropagationContext2. Assert.AreEqual(1, sub.MyStringPropertyCounter); }
public void When_Path_Invalid_And_Fallback_Value_And_Converter() { var SUT = new MyObject(); var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B") { FallbackValue = "21", Converter = new OppositeConverter() }); Assert.AreEqual(21, sub.MyProperty); Assert.AreEqual(1, sub.MyPropertyCounter); SUT.SubObject = sub; // We are testing that the converter isn't called when using FallbackValue Assert.AreEqual(21, sub.MyProperty); Assert.AreEqual(1, sub.MyPropertyCounter); SUT.DataContext = new PropagationContext(); // We are testing that the converter is called when not using FallbackValue Assert.AreEqual(-43, sub.MyProperty); Assert.AreEqual(2, sub.MyPropertyCounter); }
public void When_DataContext_And_SelfReference() { var SUT = new MyObject(); SUT.SelfTest = SUT; var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding()); SUT.SubObject = sub; // This should not fail because of a stack overflow. SUT.DataContext = 42; Assert.AreEqual(42, sub.MyProperty); }
public void When_DataContext_Set_After() { var SUT = new MyObject(); var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding()); Assert.AreEqual(0, sub.MyProperty); SUT.SubObject = sub; Assert.AreEqual(0, sub.MyProperty); SUT.DataContext = 42; Assert.AreEqual(42, sub.MyProperty); }
public void When_DataContext_Set_Before() { var SUT = new MyObject(); SUT.DataContext = 42; var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding()); Assert.AreEqual(0, sub.MyProperty); SUT.SubObject = sub; // The behavior of UWP is undefined. The datacontext is pass through unknown means tp // non-visual elements, to allow binding. But if defined through code, the datacontext // is not flowing. We're reproducing this behavior here. Assert.AreEqual(0, sub.MyProperty); }
public void When_Path_Invalid_And_Fallback_Value() { var SUT = new MyObject(); var sub = new SubObject(); sub.SetBinding(SubObject.MyPropertyProperty, new Binding("B") { FallbackValue = "21" }); Assert.AreEqual(21, sub.MyProperty); Assert.AreEqual(1, sub.MyPropertyCounter); SUT.SubObject = sub; Assert.AreEqual(21, sub.MyProperty); Assert.AreEqual(1, sub.MyPropertyCounter); SUT.DataContext = new PropagationContext(); Assert.AreEqual(43, sub.MyProperty); Assert.AreEqual(2, sub.MyPropertyCounter); }