public void SetValueWithSetProperty() { var obj = new MyBindableObject(); obj.As <IAttachedPropertyStore>().SetProperty(MyBindableObject.AttachedDecimalProperty.Identifier, 2m); AssertCustomValue(obj, 2m); }
public void SetValueWithIndexer() { var obj = new MyBindableObject(); obj[MyBindableObject.AttachedDecimalProperty] = 2m; AssertCustomValue(obj, 2m); }
public void SetValue() { var obj = new MyBindableObject(); obj.SetValue(MyBindableObject.AttachedDecimalProperty, 2m); AssertCustomValue(obj, 2m); }
private static void AssertDefaultValue(MyBindableObject obj, decimal expectedValue) { obj.HasValue(MyBindableObject.AttachedDecimalProperty).Should().BeFalse(); obj.GetValue(MyBindableObject.AttachedDecimalProperty).Should().Be(expectedValue); obj[MyBindableObject.AttachedDecimalProperty].Should().Be(expectedValue); obj.As <IAttachedPropertyStore>().PropertyCount.Should().Be(0); obj.As <IAttachedPropertyStore>().TryGetProperty(MyBindableObject.AttachedDecimalProperty.Identifier, out object value); value.Should().Be(expectedValue); }
public void ResetValueWithRemoveProperty() { var obj = new MyBindableObject(); obj.As <IAttachedPropertyStore>().SetProperty(MyBindableObject.AttachedDecimalProperty.Identifier, 2m); obj.As <IAttachedPropertyStore>().RemoveProperty(MyBindableObject.AttachedDecimalProperty.Identifier); AssertDefaultValue(obj, 1m); }
public void ResetValue() { var obj = new MyBindableObject(); obj.SetValue(MyBindableObject.AttachedDecimalProperty, 2m); obj.ResetValue(MyBindableObject.AttachedDecimalProperty); AssertDefaultValue(obj, 1m); }
public void DataContextWithotBind() { var obj = new MyBindableObject(); var data = new Data { StringValue = "str", Int32Value = 42 }; obj.DataContext = data; obj.MyStringValue.Should().Be(default);
public void CloneAttachedProperties() { var obj = new MyBindableObject { [MyBindableObject.AttachedDecimalProperty] = 10m }; var clone = (MyBindableObject)obj.Clone(); obj[MyBindableObject.AttachedDecimalProperty] = 20m; clone[MyBindableObject.AttachedDecimalProperty].Should().Be(10m); }
public void Clone() { var obj = new MyBindableObject { MyStringValue = "str", MyInt32Value = 42 }; var clone = (MyBindableObject)obj.Clone(); clone.Should().NotBeSameAs(obj); clone.MyStringValue.Should().Be(obj.MyStringValue); clone.MyInt32Value.Should().Be(obj.MyInt32Value); }
private static void AssertCustomValue(MyBindableObject obj, decimal expectedValue) { var props = new KeyValuePair <AttachableMemberIdentifier, object> [1]; obj.HasValue(MyBindableObject.AttachedDecimalProperty).Should().BeTrue(); obj.GetValue(MyBindableObject.AttachedDecimalProperty).Should().Be(expectedValue); obj[MyBindableObject.AttachedDecimalProperty].Should().Be(expectedValue); obj.As <IAttachedPropertyStore>().PropertyCount.Should().Be(1); obj.As <IAttachedPropertyStore>().TryGetProperty(MyBindableObject.AttachedDecimalProperty.Identifier, out object value); value.Should().Be(expectedValue); obj.As <IAttachedPropertyStore>().CopyPropertiesTo(props, 0); props[0].Should().Be(new KeyValuePair <AttachableMemberIdentifier, object>(MyBindableObject.AttachedDecimalProperty.Identifier, expectedValue)); }
public void NullArguments() { var obj = new MyBindableObject(); var getter = new GetExpression(); var property = obj.GetType().GetProperty(nameof(MyBindableObject.MyStringValue)); new Action(() => obj.Bind(null, getter)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj.Bind(property, null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(getter)); new Action(() => obj.HasValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj.GetValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj.ResetValue <int>(null)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj.SetValue(null, 1)).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj[null] = 1).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); new Action(() => obj[null].As <int>()).ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be(nameof(property)); }
public void Bind() { var obj = new MyBindableObject(); var data = new Data { StringValue = "str", Int32Value = 42 }; obj.Bind( obj.GetType().GetProperty(nameof(MyBindableObject.MyStringValue)), new GetExpression { Path = nameof(Data.StringValue) }); obj.Bind( obj.GetType().GetProperty(nameof(MyBindableObject.MyInt32Value)), new GetExpression { Path = nameof(Data.Int32Value) }); obj.DataContext = data; obj.MyStringValue.Should().Be(data.StringValue); obj.MyInt32Value.Should().Be(data.Int32Value); }
public void EmptyDataContext() { var obj = new MyBindableObject(); new Action(() => obj.DataContext = null).Should().NotThrow(); }
public void UnsetValue() { var obj = new MyBindableObject(); AssertDefaultValue(obj, 1m); }