private static IValueAdapter CreateTargetAdapter(DataGridColumn column, DependencyProperty storedProperty) { var propertyType = storedProperty.PropertyType; var propertyAdapter = new DependencyPropertyAdapter(column, storedProperty); return(WrapInTypeConverterIfNecessary(propertyAdapter, propertyType)); }
public void ShouldSetValue() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); adapter.SetValue(5); Assert.AreEqual(5, entity.Sample); }
public void ShouldGiveNewValueToValueChangedCallback() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); object value = null; adapter.ValueChangedCallback = newValue => value = newValue; entity.Sample = 5; Assert.AreEqual(5, value); }
public void ShouldNotifyAboutValueChanges() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); var callbackCallCount = 0; adapter.ValueChangedCallback = newValue => ++ callbackCallCount; entity.Sample = 3; Assert.AreEqual(1, callbackCallCount); }
public void ShouldGetValue() { var entity = new Entity { Sample = 5 }; var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); var value = adapter.GetValue(); Assert.AreEqual(5, value); }
public void ShouldGetValueFromAttachedProperty() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Other.AttachedProperty); Other.SetAttached(entity, 5); var value = adapter.GetValue(); Assert.AreEqual(5, value); }
public void ShouldNotCallNotifyValueChangedCallbackWhenValueChangesAfterBeingDisposed() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); var callbackCallCount = 0; adapter.ValueChangedCallback = newValue => ++ callbackCallCount; adapter.Dispose(); entity.Sample = 3; Assert.AreEqual(0, callbackCallCount); }
public void ShouldNotNotifyOldValueChangedCallbackWhenValueHasChangedAndNewIsSet() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); var callbackCallCount = 0; adapter.ValueChangedCallback = newValue => ++ callbackCallCount; entity.Sample = 3; adapter.ValueChangedCallback = newValue => { }; entity.Sample = 4; Assert.AreEqual(1, callbackCallCount); }
public void ShouldNotCallValueChangedCallbackWhenSettingValue() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); bool callbackCalled = false; adapter.ValueChangedCallback = newValue => { callbackCalled = true; }; adapter.SetValue(5); Assert.IsFalse(callbackCalled); }
public void ShouldNotFailWhenSettingValueAndValueChangedCallbackIsNotSet() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); try { entity.Sample = 2; } catch { Assert.Fail(); } }
public void ShouldDoNothingWhenSettingValueToReadOnlyProperty() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleReadOnlyProperty); try { adapter.SetValue(5); } catch { Assert.Fail(); } }
public void ShouldDoNothingAfterValueChangedCallbackIsSetToNullWhenValueChanges() { var entity = new Entity(); var adapter = new DependencyPropertyAdapter(entity, Entity.SampleProperty); adapter.ValueChangedCallback = newValue => { }; adapter.ValueChangedCallback = null; try { entity.Sample = 3; } catch { Assert.Fail(); } }