public void ReplayWhere(IAssertionTool tool, Func <AssertionData, int, bool> condition, string msg, params object[] fmt)
        {
            List <Exception> errors = new List <Exception>();

            foreach (var d in _memory.Where(condition))
            {
                try
                {
                    d.Visit(tool);
                }
                catch (Exception eError)
                {
                    errors.Add(eError);
                }
            }

            if (errors.Any())
            {
                tool.Accept(new AssertionFailure(
                                null, null, null, null, null,
                                msg, fmt, new AggregateException("One or more errors ocurred while replaying assertion set", errors), null,
                                tool.ContextGetData()));
            }
        }
 public static void Inconclusive(this IAssertionTool tool, string msg, params object[] fmt)
 {
     tool.Accept(new AssertionDeclaredInconclusive(msg, fmt, tool.ContextGetData()));
 }
 public static void Inconclusive(this IAssertionTool tool, string msg)
 {
     tool.Accept(new AssertionDeclaredInconclusive("{0}", new object[] { msg }, tool.ContextGetData()));
 }
 public static void Inconclusive(this IAssertionTool tool)
 {
     tool.Accept(new AssertionDeclaredInconclusive("{0}", new object[] { "Test Status Inconclusive" }, tool.ContextGetData()));
 }
 public static void Fail(this IAssertionTool tool)
 {
     tool.Accept(new AssertionDeclaredFailure("{0}", new object[] { "Test Failed" }, tool.ContextGetData()));
 }
Beispiel #6
0
        public static void Throws <T>(this IAssertionTool assertTool, Expression <Func <object> > test, Exception exc, string message, params object[] fmt)
        {
            if (fmt == null)
            {
                fmt = new object[] { };
            }
            if (fmt.Length <= 0)
            {
                fmt     = new object[] { message };
                message = "{0}";
            }

            Exception internalError = null;

            try
            {
                assertTool.GetExpressionEvaluator().Eval(test);
            }
            catch (Exception eError)
            {
                internalError = eError;
            }

            if (internalError is T)
            {
                assertTool.Accept(new AssertionSuccess(test.Body, null, null, null, null, message, fmt, exc, internalError, assertTool.ContextGetData()));
            }
            else
            {
                assertTool.Accept(new AssertionFailure(test.Body, null, null, null, null, message, fmt, exc, internalError, assertTool.ContextGetData()));
            }
        }
Beispiel #7
0
        public static void Check <T1, T2>(this IAssertionTool assertTool, Expression <Func <T1> > expected1, Expression <Func <T2> > actual1, Expression <Func <T1, T2, bool> > test, Exception exc, string message, params object[] fmt)
        {
            if (fmt == null)
            {
                fmt = new object[] { };
            }
            if (fmt.Length <= 0)
            {
                fmt     = new object[] { message };
                message = "{0}";
            }

            bool      result        = false;
            Exception internalError = null;

            object[] actualVals   = null;
            object[] expectedVals = null;
            ParameterExpression[] expectedRefs = null;
            ParameterExpression[] actualRefs   = null;

            T1 expectedVal = default(T1); T2 actualVal = default(T2);
            EvaluatedExpressionException expectedException = null, actualException = null;

            // We are intentionally invokign the actual result first.
            // * This is very useful when you want the FilesystemAssertionRepository to automatically create expectations for your tests
            try {
                actualVal  = assertTool.GetExpressionEvaluator().Eval(actual1);
                actualVals = new object[] { actualVal };
                actualRefs = new[] { test.Parameters[1] };
            } catch (Exception eError) {
                actualException = new EvaluatedExpressionException(actual1, eError);
            }

            try {
                expectedVal  = assertTool.GetExpressionEvaluator().Eval(expected1);
                expectedVals = new object[] { expectedVal };
                expectedRefs = new[] { test.Parameters[0] };
            } catch (Exception eError) {
                expectedException = new EvaluatedExpressionException(expected1, eError);
            }

            if (expectedException == null && actualException == null)
            {
                try {
                    result = assertTool.GetExpressionEvaluator().Eval(test, expectedVal, actualVal);
                } catch (Exception eError) {
                    internalError = new EvaluatedExpressionException(test, eError);
                }
            }
            else if (expectedException != null && actualException != null)
            {
                internalError = new AggregateException(expectedException, actualException);
            }
            else if (expectedException != null)
            {
                internalError = expectedException;
            }
            else if (actualException != null)
            {
                internalError = actualException;
            }
            else
            {
                throw new InvalidOperationException("This exception should be logically impossible to reach");
            }

            var finalExpression = Expression.Invoke(
                test,
                expected1.Body,
                actual1.Body
                );

            if (!result)
            {
                assertTool.Accept(new AssertionFailure(finalExpression, expectedRefs, expectedVals, actualRefs, actualVals, message, fmt, exc, internalError, assertTool.ContextGetData()));
            }
            else
            {
                assertTool.Accept(new AssertionSuccess(finalExpression, expectedRefs, expectedVals, actualRefs, actualVals, message, fmt, exc, internalError, assertTool.ContextGetData()));
            }
        }