public void MergedRestrictionsProperties()
        {
            var exps = new Expression[]
            {
                Expression.Constant(false), Expression.Constant(true),
                Expression.Equal(Expression.Constant(2), Expression.Constant(3))
            };

            BindingRestrictions br = BindingRestrictions.Empty;
            var restrictions       = new List <BindingRestrictions>();

            foreach (var exp in exps)
            {
                BindingRestrictions res = BindingRestrictions.GetExpressionRestriction(exp);
                restrictions.Add(res);
                br = br.Merge(res);
            }

            if (BindingRestrictionsDebugViewType == null)
            {
                return;
            }

            BindingRestrictionsProxyProxy view = GetDebugViewObject(br);

            Assert.False(view.IsEmpty);

            Assert.Equal(br.ToExpression().ToString(), view.ToString());

            BindingRestrictions[] viewedRestrictions = view.Restrictions;

            // Check equal to source restrictions, but not insisting on order.
            Assert.Equal(3, viewedRestrictions.Length);
            Assert.True(viewedRestrictions.All(r => restrictions.Contains(r)));
        }
        public void MergedRestrictionsExpressions()
        {
            var exps = new Expression[]
            {
                Expression.Constant(false), Expression.Constant(true),
                Expression.Equal(Expression.Constant(2), Expression.Constant(3))
            };

            BindingRestrictions br = BindingRestrictions.Empty;

            foreach (var exp in exps)
            {
                br = br.Merge(BindingRestrictions.GetExpressionRestriction(exp));
            }

            if (BindingRestrictionsDebugViewType == null)
            {
                return;
            }

            BindingRestrictionsProxyProxy view = GetDebugViewObject(br);

            // The expression in the view will be a tree of AndAlso nodes.
            // If we examine the expression of the restriction a new AndAlso
            // will be created, so we strip out the leaf expressions and compare
            // with the initial set.

            var        notAndAlso = new List <Expression>();
            Expression vExp       = view.Test;

            Assert.Equal(ExpressionType.AndAlso, vExp.NodeType);

            Stack <Expression> toSplit = new Stack <Expression>();

            for (;;)
            {
                if (vExp.NodeType == ExpressionType.AndAlso)
                {
                    var bin = (BinaryExpression)vExp;
                    toSplit.Push(bin.Left);
                    vExp = bin.Right;
                }
                else
                {
                    notAndAlso.Add(vExp);
                    if (toSplit.Count == 0)
                    {
                        break;
                    }

                    vExp = toSplit.Pop();
                }
            }

            // Check equal to source expressions, but not insisting on order.
            Assert.Equal(3, notAndAlso.Count);
            Assert.True(notAndAlso.All(ex => exps.Contains(ex)));
        }
Esempio n. 3
0
        public void EmptyRestiction()
        {
            BindingRestrictions           empty = BindingRestrictions.Empty;
            BindingRestrictionsProxyProxy view  = GetDebugViewObject(empty);

            Assert.True(view.IsEmpty);
            BindingRestrictions[] restrictions = view.Restrictions;
            Assert.Equal(1, restrictions.Length);
            Assert.Same(empty, restrictions[0]);
            Assert.Same(empty.ToExpression(), view.Test);
            Assert.Equal(empty.ToExpression().ToString(), view.ToString());
        }
Esempio n. 4
0
        public void CustomRestriction()
        {
            ConstantExpression            exp    = Expression.Constant(false);
            BindingRestrictions           custom = BindingRestrictions.GetExpressionRestriction(exp);
            BindingRestrictionsProxyProxy view   = GetDebugViewObject(custom);

            Assert.False(view.IsEmpty);
            BindingRestrictions[] restrictions = view.Restrictions;
            Assert.Equal(1, restrictions.Length);
            Assert.Same(custom, restrictions[0]);
            Assert.NotSame(BindingRestrictions.Empty.ToExpression(), view.Test);
            Assert.Same(exp, view.Test);
            Assert.Equal(exp.ToString(), view.ToString());
        }
        public void EmptyRestiction()
        {
            if (BindingRestrictionsDebugViewType == null)
            {
                throw new SkipTestException("Didn't find DebuggerTypeProxyAttribute on BindingRestrictions.");
            }
            BindingRestrictions           empty = BindingRestrictions.Empty;
            BindingRestrictionsProxyProxy view  = GetDebugViewObject(empty);

            Assert.True(view.IsEmpty);
            BindingRestrictions[] restrictions = view.Restrictions;
            Assert.Equal(1, restrictions.Length);
            Assert.Same(empty, restrictions[0]);
            Assert.Same(empty.ToExpression(), view.Test);
            Assert.Equal(empty.ToExpression().ToString(), view.ToString());
        }
        public void CustomRestriction()
        {
            if (BindingRestrictionsDebugViewType == null)
            {
                throw new SkipTestException("Didn't find DebuggerTypeProxyAttribute on BindingRestrictions.");
            }
            ConstantExpression            exp    = Expression.Constant(false);
            BindingRestrictions           custom = BindingRestrictions.GetExpressionRestriction(exp);
            BindingRestrictionsProxyProxy view   = GetDebugViewObject(custom);

            Assert.False(view.IsEmpty);
            BindingRestrictions[] restrictions = view.Restrictions;
            Assert.Equal(1, restrictions.Length);
            Assert.Same(custom, restrictions[0]);
            Assert.NotSame(BindingRestrictions.Empty.ToExpression(), view.Test);
            Assert.Same(exp, view.Test);
            Assert.Equal(exp.ToString(), view.ToString());
        }