예제 #1
0
        public void ParserShouldParseMultiExpressionWithCustomObjectValueDynamic2()
        {
            const string targetPath = "Text";
            const string sourcePath1 = "SourceText1";
            const string sourcePath2 = "SourceText2";
            const string objectName = "TestObject";
            const string binding = "Text SourceText1 + SourceText2 == $TestObject.IntProperty";
            var targetObj = new object();
            var model = new BindingSourceModel { IntProperty = 10 };
            var args = new object[] { 9, 1, model.IntProperty };

            var provider = new BindingProvider();
            var resolver = new BindingResourceResolver();
            BindingServiceProvider.ResourceResolver = resolver;
            resolver.AddObject(objectName, new BindingResourceObject(model), true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: provider);

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, targetObj, null).Single());
            IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
            path.Path.ShouldEqual(targetPath);

            var expression = context.GetData(BindingBuilderConstants.MultiExpression);
            expression(context, args).ShouldEqual(true);

            var sources = context.GetData(BindingBuilderConstants.Sources);
            BindingSourceShouldBeValidDataContext(targetObj, sources[0].Invoke(context), sourcePath1);
            BindingSourceShouldBeValidDataContext(targetObj, sources[1].Invoke(context), sourcePath2);
            BindingSourceShouldBeValid(sources[2].Invoke(context),
                GetMemberPath(model, sourceModel => sourceModel.IntProperty), model);
        }
예제 #2
0
        public void ParserShouldParseMultiExpressionWithCustomObjectValueDynamic1()
        {
            const string targetPath = "Text";
            const string sourcePath1 = "SourceText1";
            const string sourcePath2 = "SourceText2";
            const string sourcePath3 = "Item1";
            const string objectName = "TestObject";
            const string binding = "Text SourceText1 + SourceText2 == $TestObject.Item1";
            var target = new object();
            var tuple = new Tuple<int>(10);
            var expressionObject = new BindingResourceObject(tuple);
            var args = new object[] { 9, 1, tuple.Item1 };

            var provider = new BindingProvider();
            var resolver = new BindingResourceResolver();
            BindingServiceProvider.ResourceResolver = resolver;
            resolver.AddObject(objectName, expressionObject, true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: provider);

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single());
            IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
            path.Path.ShouldEqual(targetPath);

            var expression = context.GetData(BindingBuilderConstants.MultiExpression);
            expression(context, args).ShouldEqual(true);

            var sources = context.GetData(BindingBuilderConstants.Sources);
            BindingSourceShouldBeValidDataContext(target, sources[0].Invoke(context), sourcePath1);
            BindingSourceShouldBeValidDataContext(target, sources[1].Invoke(context), sourcePath2);
            BindingSourceShouldBeValid(sources[2].Invoke(context), sourcePath3, tuple);
        }
예제 #3
0
        public void ParserShouldParseConverterCultureFromResource()
        {
            const string binding = "Text Text, ConverterCulture=$param";
            var cultureInfo = new CultureInfo("ru-RU");
            var resolver = new BindingResourceResolver();
            resolver.AddObject("param", new BindingResourceObject(cultureInfo), true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: new BindingProvider());
            BindingServiceProvider.ResourceResolver = resolver;

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, new object(), null).Single());
            context.GetData(BindingBuilderConstants.ConverterCulture)
                .Invoke(EmptyContext)
                .ShouldEqual(cultureInfo);
        }
예제 #4
0
        public void ParserShouldParseCommandParameterFromResource()
        {
            const string value = "value";
            const string binding = "Text Text, CommandParameter=$param";
            var resolver = new BindingResourceResolver();
            resolver.AddObject("param", new BindingResourceObject(value), true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: new BindingProvider());
            BindingServiceProvider.ResourceResolver = resolver;

            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, new object(), null).Single());
            context.GetData(BindingBuilderConstants.CommandParameter)
                .Invoke(EmptyContext)
                .ShouldEqual(value);
        }
        public void ParserShouldParseTargetNullValueFromResource()
        {
            const string value = "value";
            const string binding = "Text Text, TargetNullValue=$param";
            var resolver = new BindingResourceResolver();
            resolver.AddObject("param", new BindingResourceObject(value), true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: new BindingProvider());
            BindingServiceProvider.ResourceResolver = resolver;

            var context = new BindingBuilder(bindingParser.Parse(new object(), binding, null, null).Single());
            context.GetData(BindingBuilderConstants.TargetNullValue)
                .ShouldEqual(value);
        }
        public void ParserShouldParseMultiExpressionWithCustomObjectValueStatic2()
        {
            const string targetPath = "Text";
            const string sourcePath1 = "SourceText1";
            const string sourcePath2 = "SourceText2";
            const string objectName = "TestObject";
            const string binding = "Text (SourceText1 + SourceText2).GetHashCode() == $$TestObject.GetHashCode()";
            var target = new object();
            var args = new object[] { 9, 1 };

            var provider = new BindingProvider();
            var resolver = new BindingResourceResolver();
            BindingServiceProvider.ResourceResolver = resolver;
            resolver.AddObject(objectName, new BindingResourceObject(10), true);
            IBindingParser bindingParser = CreateBindingParser(bindingProvider: provider);

            var context = new BindingBuilder(bindingParser.Parse(target, binding, null, null).Single());
            IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
            path.Path.ShouldEqual(targetPath);

            var expression = context.GetData(BindingBuilderConstants.MultiExpression);
            expression(context, args).ShouldEqual(true);

            var sources = context.GetData(BindingBuilderConstants.Sources);
            BindingSourceShouldBeValidDataContext(target, sources[0].Invoke(context), sourcePath1);
            BindingSourceShouldBeValidDataContext(target, sources[1].Invoke(context), sourcePath2);
        }