public async void Should_Convert_Get_Invalid_Double_String_To_UnsetValue() { var data = new Class1 { StringValue = "foo" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.Equal(PerspexProperty.UnsetValue, result); }
public async void Should_Coerce_Get_Null_String_To_Double_Deafult_Value() { var data = new Class1 { StringValue = null }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.Equal(0.0, result); }
public async void Should_Get_Simple_Property_Value() { var data = new Class1 { StringValue = "foo" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(string)); var result = await target.Take(1); Assert.Equal("foo", result); }
public async void Should_Convert_Get_String_To_Double() { var data = new Class1 { StringValue = "5.6" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.Equal(5.6, result); }
public async void Should_Convert_Get_Double_To_String() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); var result = await target.Take(1); Assert.Equal("5.6", result); }
public async void Getting_Invalid_Double_String_Should_Return_BindingError() { var data = new Class1 { StringValue = "foo" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.IsType<BindingError>(result); }
public void Should_Convert_Set_String_To_Double() { var data = new Class1 { StringValue = "5.6" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); target.OnNext(6.7); Assert.Equal("6.7", data.StringValue); }
public void Should_Set_Simple_Property_Value() { var data = new Class1 { StringValue = "foo" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(string)); target.OnNext("bar"); Assert.Equal("bar", data.StringValue); }
public void Bind(IObservablePropertyBag instance, PerspexProperty property) { var subject = new ExpressionSubject(CreateExpressionObserver(instance, property)); if (subject != null) { Bind(instance, property, subject); } }
public async void Should_Coerce_Get_Null_Double_String_To_UnsetValue() { var data = new Class1 { StringValue = null }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.Equal(AvaloniaProperty.UnsetValue, result); }
public async void Getting_Invalid_Double_String_Should_Return_BindingError() { var data = new Class1 { StringValue = "foo" }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); var result = await target.Take(1); Assert.IsType <BindingError>(result); }
public void Should_Coerce_Set_Invalid_Double_String_To_Default_Value() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext("foo"); Assert.Equal(0, data.DoubleValue); }
public void Calculate_StringExpression_StringResult(string input, string expected) { // Arrange var expression = new ExpressionSubject(input); // Act string result = expression.Calculate(); // Assert Assert.AreEqual(result, expected); }
public void Bind(IObservablePropertyBag instance, PerspexProperty property) { var subject = new ExpressionSubject( CreateExpressionObserver(instance, property), property.PropertyType); if (subject != null) { Bind(instance, property, subject); } }
public void Should_Convert_Set_String_To_Double() { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var data = new Class1 { StringValue = (5.6).ToString() }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); target.OnNext(6.7); Assert.Equal((6.7).ToString(), data.StringValue); }
public void Should_Convert_Set_Double_To_String() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext("6.7"); Assert.Equal(6.7, data.DoubleValue); }
public void Setting_Invalid_Double_String_Should_Not_Change_Target() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext("foo"); Assert.Equal(5.6, data.DoubleValue); }
public void Should_Coerce_Setting_UnsetValue_Double_To_Default_Value() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext(AvaloniaProperty.UnsetValue); Assert.Equal(0, data.DoubleValue); }
public async void Should_Convert_Get_Double_To_String() { CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); var result = await target.Take(1); Assert.Equal((5.6).ToString(), result); }
public void Should_Convert_Set_String_To_Double() { CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; var data = new Class1 { StringValue = (5.6).ToString() }; var target = new ExpressionSubject(new ExpressionObserver(data, "StringValue"), typeof(double)); target.OnNext(6.7); Assert.Equal((6.7).ToString(), data.StringValue); }
public void Should_Convert_Set_Double_To_String() { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext("6.7"); Assert.Equal(6.7, data.DoubleValue); }
/// <inheritdoc/> public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null) { Contract.Requires <ArgumentNullException>(target != null); var pathInfo = ParsePath(Path); ValidateState(pathInfo); ExpressionObserver observer; if (pathInfo.ElementName != null || ElementName != null) { observer = CreateElementObserver( (target as IControl) ?? (anchor as IControl), pathInfo.ElementName ?? ElementName, pathInfo.Path); } else if (Source != null) { observer = CreateSourceObserver(Source, pathInfo.Path); } else if (RelativeSource == null || RelativeSource.Mode == RelativeSourceMode.DataContext) { observer = CreateDataContexObserver( target, pathInfo.Path, targetProperty == Control.DataContextProperty, anchor); } else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent) { observer = CreateTemplatedParentObserver(target, pathInfo.Path); } else { throw new NotSupportedException(); } var subject = new ExpressionSubject( observer, targetProperty?.PropertyType ?? typeof(object), Converter ?? DefaultValueConverter.Instance, ConverterParameter, FallbackValue, Priority); return(new InstancedBinding(subject, Mode, Priority)); }
public IExpressionSubject GetById(Guid id) { var collectioin = db.GetCollection <ExpressionDto>(_table); var filter = Builders <ExpressionDto> .Filter.Eq("Id", id); var expressionDto = collectioin.Find(filter).FirstOrDefault(); var expressionSubject = new ExpressionSubject(expressionDto.Infix) { Result = expressionDto.Result }; return(expressionSubject); }
public void Setting_Invalid_Double_String_Should_Use_FallbackValue() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject( new ExpressionObserver(data, "DoubleValue"), typeof(string), DefaultValueConverter.Instance, fallbackValue: "9.8"); target.OnNext("foo"); Assert.Equal(9.8, data.DoubleValue); }
public void Should_Pass_ConverterParameter_To_ConvertBack() { var data = new Class1 { DoubleValue = 5.6 }; var converter = new Mock <IValueConverter>(); var target = new ExpressionSubject( new ExpressionObserver(data, "DoubleValue"), typeof(string), converter.Object, "foo"); target.OnNext("bar"); converter.Verify(x => x.ConvertBack("bar", typeof(double), "foo", CultureInfo.CurrentUICulture)); }
public List <IExpressionSubject> Get() { var collection = db.GetCollection <ExpressionDto>(_table); var mongoCollection = collection.Find(new BsonDocument()).ToList(); var expressionSubjects = new List <IExpressionSubject>(); foreach (var expressionDto in mongoCollection) { var expressionSubject = new ExpressionSubject(expressionDto.Infix) { Result = expressionDto.Result }; expressionSubjects.Add(expressionSubject); } return(expressionSubjects); }
public void Should_Ignore_Set_Invalid_Double_String() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext("foo"); Assert.Equal(5.6, data.DoubleValue); }
public void Setting_Invalid_Double_String_Should_Use_FallbackValue() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject( new ExpressionObserver(data, "DoubleValue"), typeof(string), "9.8", DefaultValueConverter.Instance); target.OnNext("foo"); Assert.Equal(9.8, data.DoubleValue); }
public async void Should_Convert_Get_Double_To_String() { Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); var result = await target.Take(1); Assert.Equal((5.6).ToString(), result); }
/// <inheritdoc/> public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null) { Contract.Requires <ArgumentNullException>(target != null); var pathInfo = ParsePath(Path); ValidateState(pathInfo); ExpressionObserver observer; if (pathInfo.ElementName != null || ElementName != null) { observer = CreateElementObserver( (target as IControl) ?? (anchor as IControl), pathInfo.ElementName ?? ElementName, pathInfo.Path); } else if (Source != null) { observer = CreateSourceObserver(Source, pathInfo.Path); } else if (RelativeSource == null || RelativeSource.Mode == RelativeSourceMode.DataContext) { observer = CreateDataContexObserver( target, pathInfo.Path, targetProperty == Control.DataContextProperty, anchor); } else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent) { observer = CreateTemplatedParentObserver(target, pathInfo.Path); } else { throw new NotSupportedException(); } var fallback = FallbackValue; // If we're binding to DataContext and our fallback is UnsetValue then override // the fallback value to null, as broken bindings to DataContext must reset the // DataContext in order to not propagate incorrect DataContexts to child controls. // See Avalonia.Markup.Xaml.UnitTests.Data.DataContext_Binding_Should_Produce_Correct_Results. if (targetProperty == Control.DataContextProperty && fallback == AvaloniaProperty.UnsetValue) { fallback = null; } var subject = new ExpressionSubject( observer, targetProperty?.PropertyType ?? typeof(object), fallback, Converter ?? DefaultValueConverter.Instance, ConverterParameter, Priority); return(new InstancedBinding(subject, Mode, Priority)); }
/// <inheritdoc/> public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null) { Contract.Requires<ArgumentNullException>(target != null); var pathInfo = ParsePath(Path); ValidateState(pathInfo); ExpressionObserver observer; if (pathInfo.ElementName != null || ElementName != null) { observer = CreateElementObserver( (target as IControl) ?? (anchor as IControl), pathInfo.ElementName ?? ElementName, pathInfo.Path); } else if (Source != null) { observer = CreateSourceObserver(Source, pathInfo.Path); } else if (RelativeSource == null || RelativeSource.Mode == RelativeSourceMode.DataContext) { observer = CreateDataContexObserver( target, pathInfo.Path, targetProperty == Control.DataContextProperty, anchor); } else if (RelativeSource.Mode == RelativeSourceMode.TemplatedParent) { observer = CreateTemplatedParentObserver(target, pathInfo.Path); } else { throw new NotSupportedException(); } var fallback = FallbackValue; // If we're binding to DataContext and our fallback is UnsetValue then override // the fallback value to null, as broken bindings to DataContext must reset the // DataContext in order to not propagate incorrect DataContexts to child controls. // See Avalonia.Markup.Xaml.UnitTests.Data.DataContext_Binding_Should_Produce_Correct_Results. if (targetProperty == Control.DataContextProperty && fallback == AvaloniaProperty.UnsetValue) { fallback = null; } var subject = new ExpressionSubject( observer, targetProperty?.PropertyType ?? typeof(object), fallback, Converter ?? DefaultValueConverter.Instance, ConverterParameter, Priority); return new InstancedBinding(subject, Mode, Priority); }
public void Should_Pass_ConverterParameter_To_ConvertBack() { var data = new Class1 { DoubleValue = 5.6 }; var converter = new Mock<IValueConverter>(); var target = new ExpressionSubject( new ExpressionObserver(data, "DoubleValue"), typeof(string), converter.Object, "foo"); target.OnNext("bar"); converter.Verify(x => x.ConvertBack("bar", typeof(double), "foo", CultureInfo.CurrentUICulture)); }
public void Should_Coerce_Set_UnsetValue_To_Default_Value() { var data = new Class1 { DoubleValue = 5.6 }; var target = new ExpressionSubject(new ExpressionObserver(data, "DoubleValue"), typeof(string)); target.OnNext(PerspexProperty.UnsetValue); Assert.Equal(0, data.DoubleValue); }