Ejemplo n.º 1
0
        /// <summary>
        /// Starts a chain of assertions on <paramref name="value"/>.
        /// Asserts that <paramref name="value"/> is not `null`.
        /// </summary>
        public static Assertable <T> HasValue <T>(T value, string name = null)
            where T : class
        {
            var parameter = DebugValueExpressionVisitor.GetDebugExpresssion(name ?? "value", value);

            if (value == null)
            {
                TestFrameworkProvider.Fail(GetDiagnosticMessage(Expression.NotEqual(parameter, Expression.Constant(null, typeof(T))), null, s_emptyContext));
                return(Assertable <T> .NoOp());
            }

            return(Assertable <T> .FromValueExpression(value, parameter));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts a chain of assertions on the result of <paramref name="valueExpression"/>.
        /// Asserts that the result of <paramref name="valueExpression"/> is not `null`.
        /// </summary>
        public static Assertable <T> HasValue <T>(Expression <Func <T> > valueExpression)
            where T : class
        {
            if (valueExpression == null)
            {
                throw new ArgumentNullException(nameof(valueExpression));
            }

            var(value, message) = GetValueOrNullMessage(valueExpression, s_emptyContext);

            if (message != null)
            {
                TestFrameworkProvider.Fail(message);
                return(Assertable <T> .NoOp());
            }

            return(Assertable <T> .FromValueExpression(value, valueExpression.Body));
        }