示例#1
0
        public IEnumerable <ExpectationResult> Assert(object fromWhen)
        {
            var partiallyApplied = PartialApplicationVisitor.Apply(_expression, fromWhen);
            ExpectationResult result;

            try
            {
                PAssert.PAssert.IsTrue(partiallyApplied);
                result =
                    (new ExpectationResult
                {
                    Passed = true,
                    Text = PAssert.PAssert.CreateSimpleFormatFor(partiallyApplied),
                    OriginalExpression = _expression
                });
            }
            catch (Exception ex)
            {
                result =
                    (new ExpectationResult
                {
                    Passed = false,
                    Text = PAssert.PAssert.CreateSimpleFormatFor(partiallyApplied),
                    OriginalExpression = _expression,
                    Exception = ex
                });
            }
            yield return(result);
        }
示例#2
0
        public static Expression <Func <bool> > Apply <T>(Expression <Func <T, bool> > expr, object value)
        {
            var paramExprToReplace = expr.Parameters[0];
            var valueToApply       = Expression.Constant(value, value.GetType());
            var visitor            = new PartialApplicationVisitor(paramExprToReplace, valueToApply);

            var oldBody = expr.Body;
            var newBody = visitor.Visit(oldBody);

            return(Expression.Lambda <Func <bool> >(newBody));
        }