Esempio n. 1
0
        public void Should_Set_Simple_Property_Value()
        {
            var data = new Class1 { StringValue = "foo" };
            var target = new BindingExpression(new ExpressionObserver(data, "StringValue"), typeof(string));

            target.OnNext("bar");

            Assert.Equal("bar", data.StringValue);
        }
Esempio n. 2
0
        public void Should_Convert_Set_String_To_Double()
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var data = new Class1 { StringValue = (5.6).ToString() };
            var target = new BindingExpression(new ExpressionObserver(data, "StringValue"), typeof(double));

            target.OnNext(6.7);

            Assert.Equal((6.7).ToString(), data.StringValue);
        }
Esempio n. 3
0
        public void Should_Convert_Set_Double_To_String()
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var data = new Class1 { DoubleValue = 5.6 };
            var target = new BindingExpression(new ExpressionObserver(data, "DoubleValue"), typeof(string));

            target.OnNext("6.7");

            Assert.Equal(6.7, data.DoubleValue);
        }
Esempio n. 4
0
        public void Should_Handle_DataValidation()
        {
            var data = new Class1 { DoubleValue = 5.6 };
            var converter = new Mock<IValueConverter>();
            var target = new BindingExpression(new ExpressionObserver(data, "DoubleValue", true), typeof(string));
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));
            target.OnNext(1.2);
            target.OnNext("3.4");
            target.OnNext("bar");

            Assert.Equal(
                new[]
                {
                    new BindingNotification("5.6"),
                    new BindingNotification("1.2"),
                    new BindingNotification("3.4"),
                    new BindingNotification(
                        new InvalidCastException("'bar' is not a valid number."),
                        BindingErrorType.Error)
                },
                result);
        }
Esempio n. 5
0
        public void Should_Pass_ConverterParameter_To_ConvertBack()
        {
            var data = new Class1 { DoubleValue = 5.6 };
            var converter = new Mock<IValueConverter>();
            var target = new BindingExpression(
                new ExpressionObserver(data, "DoubleValue"), 
                typeof(string),
                converter.Object,
                converterParameter: "foo");

            target.OnNext("bar");

            converter.Verify(x => x.ConvertBack("bar", typeof(double), "foo", CultureInfo.CurrentUICulture));
        }
Esempio n. 6
0
        public void Should_Coerce_Setting_UnsetValue_Double_To_Default_Value()
        {
            var data = new Class1 { DoubleValue = 5.6 };
            var target = new BindingExpression(new ExpressionObserver(data, "DoubleValue"), typeof(string));

            target.OnNext(AvaloniaProperty.UnsetValue);

            Assert.Equal(0, data.DoubleValue);
        }
Esempio n. 7
0
        public void Setting_Invalid_Double_String_Should_Use_FallbackValue()
        {
            var data = new Class1 { DoubleValue = 5.6 };
            var target = new BindingExpression(
                new ExpressionObserver(data, "DoubleValue"),
                typeof(string),
                "9.8",
                DefaultValueConverter.Instance);

            target.OnNext("foo");

            Assert.Equal(9.8, data.DoubleValue);
        }
Esempio n. 8
0
        public void Setting_Invalid_Double_String_Should_Not_Change_Target()
        {
            var data = new Class1 { DoubleValue = 5.6 };
            var target = new BindingExpression(new ExpressionObserver(data, "DoubleValue"), typeof(string));

            target.OnNext("foo");

            Assert.Equal(5.6, data.DoubleValue);
        }