示例#1
0
        public void ShouldReturnNullForNonExistingProperty()
        {
            var entity  = new NotifyingTarget();
            var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(entity, "NonExistingProperty");

            Assert.IsNull(adapter);
        }
示例#2
0
        public void ReturnedAdapterShouldSetValueOfCompatibleTypeGivenTargetWithNameOfDependencyProperty()
        {
            var target  = new DependencyObjectTarget();
            var adapter = ValueAdapterFactory.CreateAdapter(target, "Value");

            adapter.SetValue(4.5d);

            Assert.AreEqual(4, target.Value);
        }
示例#3
0
        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);
        }
示例#4
0
        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();
 }
示例#8
0
 public void ShouldThrowGivenNullTargetWhenCreatingFromPropertyName()
 {
     var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(null, "Value");
 }
示例#9
0
 public void ShouldThrowGivenNullPropertyName()
 {
     var adapter = ValueAdapterFactory.CreateAdapterFromPropertyName(new NotifyingTarget(), null);
 }
示例#10
0
 public void ReturnedAdapterShouldNotLeakTargetGivenTargetWithDependencyPropertyInheritedFromBaseClass()
 {
     AssertLifetime.UnreachableInstanceIsNotLeaked(
         () => new Control(),
         target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "DataContext"));
 }
示例#11
0
 public void ReturnedAdapterShouldNotLeakTargetGivenTargetWithDependencyProperty()
 {
     AssertLifetime.UnreachableInstanceIsNotLeaked(
         () => new DependencyObjectTarget(),
         target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "Value"));
 }
示例#12
0
 public void ReturnedAdapterShouldNotLeakTargetGivenPropertyOfNotifyingTarget()
 {
     AssertLifetime.UnreachableInstanceIsNotLeaked(
         () => new NotifyingTarget(),
         target => ValueAdapterFactory.CreateAdapterFromPropertyName(target, "Value"));
 }