Example #1
0
        private void ReportFailure(string message)
        {
            // Record the failure in an <assertion> element
            var result = TestExecutionContext.CurrentContext.CurrentResult;

            result.RecordAssertion(AssertionStatus.Failed, message, GetStackTrace());
            result.RecordTestCompletion();
            StackFilter.DefaultFilter.Filter(SystemEnvironmentFilter.Filter(Environment.StackTrace));
            throw new AssertionException(result.Message);
        }
Example #2
0
 /// <summary>
 /// Asserts that a condition is true. If the condition is false the method throws
 /// an NUnit.Framework.AssertionException.
 /// </summary>
 /// <param name="condition">A lambda that returns a Boolean</param>
 /// <param name="getExceptionMessage">A function to build the message included with the Exception</param>
 public static void That(Func <bool> condition, Func <string> getExceptionMessage)
 {
     try
     {
         if (condition())
         {
             Assert.That(condition, getExceptionMessage);
             LogHelper.LoggerForCurrentTest.Assert("Asserting boolean lambda condition -- success.", true);
         }
         else
         {
             if (IsSkipBug())
             {
                 TestExecutionContext.CurrentContext.CurrentResult.RecordAssertion(AssertionStatus.Warning, "Triaged test case failure", StackFilter.DefaultFilter.Filter(SystemEnvironmentFilter.Filter(Environment.StackTrace)));
             }
             else
             {
                 Assert.That(condition, getExceptionMessage);
                 LogHelper.LoggerForCurrentTest.Assert("Asserting boolean lambda condition -- success.", true);
             }
         }
     }
     catch (AssertionException e)
     {
         LogHelper.LoggerForCurrentTest.Assert("Asserting boolean lambda condition -- fail. User exception message: " + getExceptionMessage?.Invoke(), false, exceptionMessage: e.ToString());
         throw;
     }
 }
Example #3
0
 /// <summary>
 /// Asserts that a condition is true. If the condition is false the method throws
 /// an NUnit.Framework.AssertionException.
 /// </summary>
 /// <param name="condition">The evaluated condition</param>
 /// <param name="message">The message to display if the condition is false</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 public static void That(bool condition, string message, params object[] args)
 {
     try
     {
         if (condition)
         {
             Assert.That(condition, message, args);
             LogHelper.LoggerForCurrentTest.Assert("Asserting boolean condition -- success.", true);
         }
         else
         {
             if (IsSkipBug())
             {
                 TestExecutionContext.CurrentContext.CurrentResult.RecordAssertion(AssertionStatus.Warning, "Triaged test case failure", StackFilter.DefaultFilter.Filter(SystemEnvironmentFilter.Filter(Environment.StackTrace)));
             }
             else
             {
                 Assert.That(condition, message, args);
                 LogHelper.LoggerForCurrentTest.Assert("Asserting boolean condition -- success.", true);
             }
         }
     }
     catch (AssertionException e)
     {
         LogHelper.LoggerForCurrentTest.Assert("Asserting boolean condition -- fail. User exception message: " + string.Format(message, args), false, exceptionMessage: e.ToString());
         throw;
     }
 }