/// <summary> /// Create a value binding. /// </summary> public IValueBinding CreateValueBinding(object parentObject, object value, Type type) { IValueBinding valueBinding; // // Recurse if neccessary and setup bindings for subobjects. // if (RecurseTypeForBindings(type)) { // Get the sub-object from the property. if (type.IsArray) { valueBinding = new ArrayBinding((Array)value, this); } else if (value is IList) { valueBinding = new ListBinding((IList)value, this); } else { valueBinding = new ObjectBinding(value, this); } } else { valueBinding = new PrimitiveBinding(value); } return(valueBinding); }
/// <summary> /// Initializes the test object. /// </summary> private void InitTestObject(TestClass obj) { testObject = new ObjectBinding(obj, mockBindingsFactory.Object); }
public void test_find_property_binding() { var obj = new TestClass() { X = 15 }; var mockObjectPropertyBinding = new Mock<IObjectPropertyBinding>(); var mockBindingsFactory = new Mock<IBindingsFactory>(); mockObjectPropertyBinding .Setup(m => m.PropertyName) .Returns("X"); mockObjectPropertyBinding .Setup(m => m.FindNestedBinding(string.Empty)) .Returns(mockObjectPropertyBinding.Object); mockBindingsFactory .Setup(m => m.CreateObjectBindings(obj)) .Returns(new IObjectPropertyBinding[] { mockObjectPropertyBinding.Object }); var testObject = new ObjectBinding(obj, mockBindingsFactory.Object); Assert.Equal(mockObjectPropertyBinding.Object, testObject.FindNestedBinding("X")); }
public void test_find_nested_property_binding() { var obj = new { X = new ObservableList<int>() }; var mockObjectPropertyBinding = new Mock<IObjectPropertyBinding>(); var mockBindingsFactory = new Mock<IBindingsFactory>(); mockObjectPropertyBinding .Setup(m => m.PropertyName) .Returns("X"); mockObjectPropertyBinding .Setup(m => m.FindNestedBinding("0")) .Returns(mockObjectPropertyBinding.Object); mockBindingsFactory .Setup(m => m.CreateObjectBindings(obj)) .Returns(new IObjectPropertyBinding[] { mockObjectPropertyBinding.Object }); var testObject = new ObjectBinding(obj, mockBindingsFactory.Object); Assert.Equal(mockObjectPropertyBinding.Object, testObject.FindNestedBinding("X.0")); }
public void property_changing_is_propagated_from_child_node_after_reconnect() { var propertyName = "X"; var obj = new TestClass(); var childEventStream = new Subject<BoundPropertyChangingEventArgs>(); InitMocks(); InitTestObjectWithPropertyChangingStream(childEventStream, obj); var testObject = new ObjectBinding(obj, mockBindingsFactory.Object); List<BoundPropertyChangingEventArgs> events = new List<BoundPropertyChangingEventArgs>(); testObject.PropertyChangingEventStream.Subscribe(ev => events.Add(ev)); testObject.Disconnect(); Assert.Empty(events); testObject.Connect(obj); childEventStream.OnNext(new BoundPropertyChangingEventArgs(propertyName, mockObjectPropertyBinding.Object)); Assert.Equal(1, events.Count); Assert.Equal(propertyName, events[0].PropertyName); Assert.Equal(mockObjectPropertyBinding.Object, events[0].Binding); }
/// <summary> /// Create a value binding. /// </summary> public IValueBinding CreateValueBinding(object parentObject, object value, Type type) { IValueBinding valueBinding; // // Recurse if neccessary and setup bindings for subobjects. // if (RecurseTypeForBindings(type)) { // Get the sub-object from the property. if (type.IsArray) { valueBinding = new ArrayBinding((Array)value, this); } else if (value is IList) { valueBinding = new ListBinding((IList)value, this); } else { valueBinding = new ObjectBinding(value, this); } } else { valueBinding = new PrimitiveBinding(value); } return valueBinding; }