Beispiel #1
0
        public void Should_Return_FallbackValue_When_Converter_Returns_UnsetValue()
        {
            var target = new TextBlock();
            var source = new { A = 1, B = 2, C = 3 };
            var binding = new MultiBinding
            {
                Converter = new UnsetValueConverter(),
                Bindings = new[]
                {
                    new Binding { Path = "A" },
                    new Binding { Path = "B" },
                    new Binding { Path = "C" },
                },
                FallbackValue = "fallback",
            };

            target.Bind(TextBlock.TextProperty, binding);

            Assert.Equal("fallback", target.Text);
        }
Beispiel #2
0
        public async void OneWay_Binding_Should_Be_Set_Up()
        {
            var source = new { A = 1, B = 2, C = 3 };
            var binding = new MultiBinding
            {
                Converter = new ConcatConverter(),
                Bindings = new[]
                {
                    new Binding { Path = "A" },
                    new Binding { Path = "B" },
                    new Binding { Path = "C" },
                }
            };

            var target = new Mock<IPerspexObject>();
            target.Setup(x => x.GetValue(Control.DataContextProperty)).Returns(source);

            var subject = binding.CreateSubject(target.Object, null);
            var result = await subject.Take(1);

            Assert.Equal("1,2,3", result);
        }
        public async void OneWay_Binding_Should_Be_Set_Up()
        {
            var source = new { A = 1, B = 2, C = 3 };
            var binding = new MultiBinding
            {
                Converter = new ConcatConverter(),
                Bindings = new[]
                {
                    new Binding { SourcePropertyPath = "A" },
                    new Binding { SourcePropertyPath = "B" },
                    new Binding { SourcePropertyPath = "C" },
                }
            };

            var target = new Mock<IObservablePropertyBag>();
            target.Setup(x => x.GetValue(Control.DataContextProperty)).Returns(source);
            target.Setup(x => x.GetObservable(Control.DataContextProperty)).Returns(
                Observable.Never<object>().StartWith(source));

            var subject = binding.CreateSubject(target.Object, typeof(string));
            var result = await subject.Take(1);

            Assert.Equal("1,2,3", result);
        }