public void SetValue_Should_Return_False_For_Missing_Object()
        {
            var data   = new Class1();
            var target = ExpressionObserver.Create(data, o => (o.Next as Class2).Bar);

            using (target.Subscribe(_ => { }))
            {
                Assert.False(target.SetValue("baz"));
            }

            GC.KeepAlive(data);
        }
Ejemplo n.º 2
0
        public async Task Should_Coerce_Get_Null_Double_String_To_UnsetValue()
        {
            var data = new Class1 {
                StringValue = null
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(double));
            var result = await target.Take(1);

            Assert.Equal(AvaloniaProperty.UnsetValue, result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 3
0
        public void Should_Set_Simple_Property_Value()
        {
            var data   = new { Foo = "foo" };
            var target = ExpressionObserver.Create(data, o => o.Foo);

            using (target.Subscribe(_ => { }))
            {
                target.SetValue("bar");
            }

            Assert.Equal("foo", data.Foo);
        }
Ejemplo n.º 4
0
        public async Task Should_Convert_Get_String_To_Double()
        {
            var data = new Class1 {
                StringValue = $"{5.6}"
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(double));
            var result = await target.Take(1);

            Assert.Equal(5.6, result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 5
0
        public async Task Getting_Invalid_Double_String_Should_Return_BindingError()
        {
            var data = new Class1 {
                StringValue = "foo"
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(double));
            var result = await target.Take(1);

            Assert.IsType <BindingNotification>(result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 6
0
        public async Task Should_Convert_Get_Double_To_String()
        {
            var data = new Class1 {
                DoubleValue = 5.6
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.DoubleValue), typeof(string));
            var result = await target.Take(1);

            Assert.Equal($"{5.6}", result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 7
0
        public async Task Should_Get_Simple_Property_Value()
        {
            var data = new Class1 {
                StringValue = "foo"
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(string));
            var result = await target.Take(1);

            Assert.Equal("foo", result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 8
0
        public void Enabled_Indei_Validation_Subscribes()
        {
            var data = new IndeiTest {
                MustBePositive = 5
            };
            var observer = ExpressionObserver.Create(data, o => o.MustBePositive, true);
            var sub      = observer.Subscribe(_ => { });

            Assert.Equal(1, data.ErrorsChangedSubscriptionCount);
            sub.Dispose();
            Assert.Equal(0, data.ErrorsChangedSubscriptionCount);
        }
        public async Task Should_Get_List_Value()
        {
            var data = new { Foo = new List <string> {
                                 "foo", "bar"
                             } };
            var target = ExpressionObserver.Create(data, o => o.Foo[1]);
            var result = await target.Take(1);

            Assert.Equal("bar", result);

            GC.KeepAlive(data);
        }
        public async Task List_Out_Of_Bounds_Should_Return_UnsetValue()
        {
            var data = new { Foo = new List <string> {
                                 "foo", "bar"
                             } };
            var target = ExpressionObserver.Create(data, o => o.Foo[2]);
            var result = await target.Take(1);

            Assert.Equal(AvaloniaProperty.UnsetValue, result);

            GC.KeepAlive(data);
        }
        public async Task Should_Get_Simple_Property_From_Base_Class()
        {
            var data = new Class3 {
                Foo = "foo"
            };
            var target = ExpressionObserver.Create(data, o => o.Foo);
            var result = await target.Take(1);

            Assert.Equal("foo", result);

            GC.KeepAlive(data);
        }
        public async Task Should_Return_BindingNotification_Error_For_Observable_Root_Null()
        {
            var target = ExpressionObserver.Create(Observable.Return(default(Class3)), o => o.Foo);
            var result = await target.Take(1);

            Assert.Equal(
                new BindingNotification(
                    new MarkupBindingChainException("Null value", "o => o.Foo", string.Empty),
                    BindingErrorType.Error,
                    AvaloniaProperty.UnsetValue),
                result);
        }
        public async Task Should_Get_MultiDimensional_Array_Value()
        {
            var data = new { Foo = new[, ] {
                                 { "foo", "bar" }, { "baz", "qux" }
                             } };
            var target = ExpressionObserver.Create(data, o => o.Foo[1, 1]);
            var result = await target.Take(1);

            Assert.Equal("qux", result);

            GC.KeepAlive(data);
        }
        public async Task Should_Get_Value_For_Non_String_Indexer()
        {
            var data = new { Foo = new Dictionary <double, string> {
                                 { 1.0, "bar" }, { 2.0, "qux" }
                             } };
            var target = ExpressionObserver.Create(data, o => o.Foo[1.0]);
            var result = await target.Take(1);

            Assert.Equal("bar", result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 15
0
        public void Indexer_Can_Set_Value()
        {
            var data = new[] { 1, 2, 3, 4 };

            var target = ExpressionObserver.Create(data, o => o[0]);

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue(2));
            }

            GC.KeepAlive(data);
        }
Ejemplo n.º 16
0
        public void Can_SetValue_For_Valid_Value()
        {
            var data = new Test {
                Foo = true
            };
            var target = ExpressionObserver.Create(data, o => !o.Foo);

            target.Subscribe(_ => { });

            Assert.True(target.SetValue(true));

            Assert.False(data.Foo);
        }
Ejemplo n.º 17
0
        public void Should_Set_Simple_Property_Value()
        {
            var data = new Class1 {
                StringValue = "foo"
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(string));

            target.OnNext("bar");

            Assert.Equal("bar", data.StringValue);

            GC.KeepAlive(data);
        }
Ejemplo n.º 18
0
        public void Should_Coerce_Setting_UnsetValue_Double_To_Default_Value()
        {
            var data = new Class1 {
                DoubleValue = 5.6
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.DoubleValue), typeof(string));

            target.OnNext(AvaloniaProperty.UnsetValue);

            Assert.Equal(0, data.DoubleValue);

            GC.KeepAlive(data);
        }
Ejemplo n.º 19
0
        public void Setting_Invalid_Double_String_Should_Not_Change_Target()
        {
            var data = new Class1 {
                DoubleValue = 5.6
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.DoubleValue), typeof(string));

            target.OnNext("foo");

            Assert.Equal(5.6, data.DoubleValue);

            GC.KeepAlive(data);
        }
Ejemplo n.º 20
0
        public void Should_Convert_Set_Double_To_String()
        {
            var data = new Class1 {
                DoubleValue = 5.6
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.DoubleValue), typeof(string));

            target.OnNext($"{6.7}");

            Assert.Equal(6.7, data.DoubleValue);

            GC.KeepAlive(data);
        }
Ejemplo n.º 21
0
        public void Should_Convert_Set_String_To_Double()
        {
            var data = new Class1 {
                StringValue = $"{5.6}"
            };
            var target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(double));

            target.OnNext(6.7);

            Assert.Equal($"{6.7}", data.StringValue);

            GC.KeepAlive(data);
        }
        public void SetValue_Should_Notify_New_Value_Without_Inpc()
        {
            var data   = new Class1();
            var target = ExpressionObserver.Create(data, o => o.Bar);
            var result = new List <object>();

            target.Subscribe(x => result.Add(x));
            target.SetValue("bar");

            Assert.Equal(new[] { null, "bar" }, result);

            GC.KeepAlive(data);
        }
Ejemplo n.º 23
0
        public async Task Indexer_Accessor_Can_Read_Complex_Index()
        {
            var data = new Dictionary <object, object>();

            var key = new object();

            data.Add(key, new object());

            var target = ExpressionObserver.Create(data, o => o[key]);

            Assert.Equal(data[key], await target.Take(1));

            GC.KeepAlive(data);
        }
Ejemplo n.º 24
0
        public void Should_SetArrayIndex()
        {
            var data   = new { Foo = new[] { "foo", "bar" } };
            var target = ExpressionObserver.Create(data, o => o.Foo[1]);

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("baz"));
            }

            Assert.Equal("baz", data.Foo[1]);

            GC.KeepAlive(data);
        }
        public void Should_Get_Completed_Task_Value()
        {
            using (var sync = UnitTestSynchronizationContext.Begin())
            {
                var data   = new { Foo = Task.FromResult("foo") };
                var target = ExpressionObserver.Create(data, o => o.Foo.StreamBinding());
                var result = new List <object>();

                var sub = target.Subscribe(x => result.Add(x));

                Assert.Equal(new[] { "foo" }, result);

                GC.KeepAlive(data);
            }
        }
Ejemplo n.º 26
0
        public void Second_Subscription_Should_Fire_Immediately()
        {
            var data = new Class1 {
                StringValue = "foo"
            };
            var    target = new BindingExpression(ExpressionObserver.Create(data, o => o.StringValue), typeof(string));
            object result = null;

            target.Subscribe();
            target.Subscribe(x => result = x);

            Assert.Equal("foo", result);

            GC.KeepAlive(data);
        }
        public void Should_Not_Keep_Source_Alive_MethodBinding()
        {
            Func <ExpressionObserver> run = () =>
            {
                var source = new { Foo = new MethodBound() };
                var target = ExpressionObserver.Create(source, o => (Action)o.Foo.A);
                target.Subscribe(_ => { });
                return(target);
            };

            var result = run();

            dotMemory.Check(memory =>
                            Assert.Equal(0, memory.GetObjects(where => where.Type.Is <MethodBound>()).ObjectsCount));
        }
        public void Should_Not_Keep_Source_Alive_NonIntegerIndexer()
        {
            Func <ExpressionObserver> run = () =>
            {
                var source = new { Foo = new NonIntegerIndexer() };
                var target = ExpressionObserver.Create(source, o => o.Foo);

                target.Subscribe(_ => { });
                return(target);
            };

            var result = run();

            dotMemory.Check(memory =>
                            Assert.Equal(0, memory.GetObjects(where => where.Type.Is <NonIntegerIndexer>()).ObjectsCount));
        }
        public void Should_Track_Simple_Property_Value()
        {
            var data   = new Class1();
            var target = ExpressionObserver.Create(data, o => o.Foo);
            var result = new List <object>();

            var sub = target.Subscribe(x => result.Add(x));

            data.SetValue(Class1.FooProperty, "bar");

            Assert.Equal(new[] { "foo", "bar" }, result);

            sub.Dispose();

            Assert.Null(((IAvaloniaObjectDebug)data).GetPropertyChangedSubscribers());
        }
        public void SetValue_Should_Set_Simple_Property_Value()
        {
            var data = new Class1 {
                Foo = "foo"
            };
            var target = ExpressionObserver.Create(data, o => o.Foo);

            using (target.Subscribe(_ => { }))
            {
                Assert.True(target.SetValue("bar"));
            }

            Assert.Equal("bar", data.Foo);

            GC.KeepAlive(data);
        }