public void BindingParser_NoParameters()
 {
     var parser = new BindingParser();
     var binding = (BindingMarkup)parser.ParseExpression("Binding");
     Assert.IsInstanceOfType(binding.Path, typeof(BindingGetPropertyExpression));
     Assert.IsTrue(string.IsNullOrEmpty(((BindingGetPropertyExpression)binding.Path).PropertyName));
 }
        public void BindingEvaluateVisitor_PropertyGet()
        {
            var target = CreateTestObject();
            var parser = new BindingParser();
            var eval = new BindingEvaluateVisitor();

            // arrayIndex on array
            var binding = (BindingMarkup)parser.ParseExpression("Child");
            Assert.AreEqual(target.Child, eval.Visit(binding.Path, target));
        }
        public void BindingEvaluateVisitor_IndexerOnly()
        {
            var target = CreateTestObject();
            var parser = new BindingParser();
            var eval = new BindingEvaluateVisitor();

            // arrayIndex on array
            var binding = (BindingMarkup)parser.ParseExpression("[1]");
            Assert.AreEqual(2, eval.Visit(binding.Path, target.Child.ArrayOfIntegers));
        }
        public void BindingEvaluateVisitor_IndexerOnIList()
        {
            var target = CreateTestObject();
            var parser = new BindingParser();
            var eval = new BindingEvaluateVisitor();

            // property.arrayIndex on List
            var binding = (BindingMarkup)parser.ParseExpression("Child.ListOfIntegers[0]");
            Assert.AreEqual(1, eval.Visit(binding.Path, target));
        }
        public void BindingEvaluateVisitor_IndexerOnIEnumerable()
        {
            var target = CreateTestObject();
            var parser = new BindingParser();
            var eval = new BindingEvaluateVisitor();

            // property.arrayIndex on IEnumerable
            var binding = (BindingMarkup)parser.ParseExpression("Child.EnumerableOfValues[1].Value");
            Assert.AreEqual("b", eval.Visit(binding.Path, target));
        }
        public void BindingParser_BindingWithSpecifiedPropertyName()
        {
            var parser = new BindingParser();
            var binding = (BindingMarkup)parser.ParseExpression("Binding Path=Test.Test2");

            dynamic path = binding.Path;

            Assert.IsInstanceOfType(path, typeof(BindingGetPropertyExpression));
            Assert.AreEqual("Test", path.PropertyName);

            Assert.IsInstanceOfType(path.NextExpression, typeof(BindingGetPropertyExpression));
            Assert.AreEqual("Test2", path.NextExpression.PropertyName);
        }
        public void BindingParser_BindingWithDefaultProperty()
        {
            var parser = new BindingParser();
            var binding = (BindingMarkup)parser.ParseExpression("Binding Test.Test2, Mode=TwoWay");

            Assert.AreEqual(BindingMode.TwoWay, binding.Mode);

            dynamic path = binding.Path;

            Assert.IsInstanceOfType(path, typeof(BindingGetPropertyExpression));
            Assert.AreEqual("Test", path.PropertyName);

            Assert.IsInstanceOfType(path.NextExpression, typeof(BindingGetPropertyExpression));
            Assert.AreEqual("Test2", path.NextExpression.PropertyName);
        }