public void ShouldReturnNullForNonExistingProperty() { var entity = new NotifyingTarget(); var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(entity, "NonExistingProperty"); Assert.IsNull(adapter); }
public void ReturnedAdapterShouldSetValueOfCompatibleTypeGivenTargetWithNameOfDependencyProperty() { var target = new DependencyObjectTarget(); var adapter = ValueAdapterFactory.CreateAdapter(target, "Value"); adapter.SetValue(4.5d); Assert.AreEqual(4, target.Value); }
public void ReturnedAdapterShouldSetValueOfCompatibleTypeGivenTargetWithPropertyInfo() { var target = new Target(); var propertyInfo = target.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public); var adapter = ValueAdapterFactory.CreateAdapter(target, propertyInfo); adapter.SetValue(4.5d); Assert.AreEqual(4, target.Value); }
public void ReturnedAdapterShouldSetValueOfCompatibleTypeGivenTargetWithPropertyDescriptor() { var target = new Target(); var propertyDescriptor = TypeDescriptor.GetProperties(target)["Value"]; var adapter = ValueAdapterFactory.CreateAdapter(target, propertyDescriptor); adapter.SetValue(4.5d); Assert.AreEqual(4, target.Value); }
public SelectorItemsSourceViewAdapter(Selector source) { if (source == null) { throw new ArgumentNullException("source"); } _valueChangedCallback = _ => { }; _sourceItemsSourceAdapter = ValueAdapterFactory.CreateAdapterForDependencyProperty(source, ItemsControl.ItemsSourceProperty); _sourceItemsSourceAdapter.ValueChangedCallback = OnSourceValueChanged; }
private IValueAdapter CreateValueAdapter() { var dataContext = _dataContextAdapter.GetValue(); if (dataContext == null) { return(null); } var valueAdapter = ValueAdapterFactory.CreateAdapter(dataContext, _propertyInDataContext); if (valueAdapter != null) { valueAdapter.ValueChangedCallback = _valueChangedCallback; } return(valueAdapter); }
public DataContextPropertyAdapter(FrameworkElement target, string propertyInDataContext) { if (target == null) { throw new ArgumentNullException("target"); } if (propertyInDataContext == null) { throw new ArgumentNullException("propertyInDataContext"); } _propertyInDataContext = propertyInDataContext; _dataContextAdapter = ValueAdapterFactory.CreateAdapterForDependencyProperty(target, FrameworkElement.DataContextProperty); _dataContextAdapter.ValueChangedCallback = OnDataContextChanged; _valueChangedCallback = newValue => { }; _valueAdapter = CreateValueAdapter(); }
public void ShouldThrowGivenNullTargetWhenCreatingFromPropertyName() { var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(null, "Value"); }
public void ShouldThrowGivenNullPropertyName() { var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(new NotifyingTarget(), null); }
public void ReturnedAdapterShouldNotLeakTargetGivenTargetWithDependencyPropertyInheritedFromBaseClass() { AssertLifetime.UnreachableInstanceIsNotLeaked( () => new Control(), target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "DataContext")); }
public void ReturnedAdapterShouldNotLeakTargetGivenTargetWithDependencyProperty() { AssertLifetime.UnreachableInstanceIsNotLeaked( () => new DependencyObjectTarget(), target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "Value")); }
public void ReturnedAdapterShouldNotLeakTargetGivenPropertyOfNotifyingTarget() { AssertLifetime.UnreachableInstanceIsNotLeaked( () => new NotifyingTarget(), target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "Value")); }