/// <summary>
 /// Construct an AssertionResult with actual/expected
 /// </summary>
 public AssertionResult(AssertionStatus status, object actual, object expected, string message, string stackTrace)
 {
     Status     = status;
     Message    = message;
     StackTrace = stackTrace;
     Actual     = actual;
     Expected   = expected;
 }
Example #2
0
        private static TestResult Report(AssertionStatus status, object actual, object expected, string message, params object[] args)
        {
            var result = TestExecutionContext.CurrentContext.CurrentResult;

            result.RecordAssertion(status, actual, expected, message, GetStackTrace());
            result.RecordTestCompletion();
            return(result);
        }
Example #3
0
        internal static void RecordAssertionIntoTestResult(AssertionStatus status, string message, string stackTrace)
        {
            object testResult = GetCurrentTestResult();

            object statusConverted = Enum.Parse(AssertionStatusType.Value, status.ToString());

            MethodInfo recordAssertionMethod = TestResultType.Value.GetMethodWithThrowOnError("RecordAssertion", AssertionStatusType.Value, typeof(string), typeof(string));

            recordAssertionMethod.InvokeAsLambda(testResult, statusConverted, message, stackTrace);
        }
Example #4
0
        private static string ResolveResultPrefix(AssertionStatus status)
        {
            switch (status)
            {
            case AssertionStatus.Passed:
                return(null);

            case AssertionStatus.Warning:
                return(WarningResultPrefix);

            case AssertionStatus.Failed:
                return(FailedResultPrefix);

            case AssertionStatus.Exception:
                return(ExceptionResultPrefix);

            default:
                throw ExceptionFactory.CreateForUnsupportedEnumValue(status, nameof(status));
            }
        }
Example #5
0
        private ResultState AssertionStatusToResultState(AssertionStatus status)
        {
            switch (status)
            {
            case AssertionStatus.Inconclusive:
                return(ResultState.Inconclusive);

            default:
            case AssertionStatus.Passed:
                return(ResultState.Success);

            case AssertionStatus.Warning:
                return(ResultState.Warning);

            case AssertionStatus.Failed:
                return(ResultState.Failure);

            case AssertionStatus.Error:
                return(ResultState.Error);
            }
        }
Example #6
0
        public void TestHasFailedAssertionsPropertyReturnsIfTestsHasFailedAssertion([Values] bool hasResult,
                                                                                    [Values] bool hasAssertions, [Values] AssertionStatus status)
        {
            bool expected = hasResult && hasAssertions && status != AssertionStatus.Passed;
            IList <AssertionResult> assertions = new List <AssertionResult>
            {
                new AssertionResult(AssertionStatus.Passed, "message", "trace"),
                null,
                new AssertionResult(status, "message", "trace"),
                new AssertionResult(AssertionStatus.Passed, "message", "trace")
            };

            TestResultForTest resultInstance = new TestResultForTest();

            resultInstance.AssertionResults = hasAssertions ? assertions : null;
            ITestResult result = hasResult ? resultInstance : null;

            INUnitTestResult test = new NUnitTestResult(result);

            Assert.AreEqual(expected, test.HasFailedAssertions);
            if (hasResult && hasAssertions)
            {
                CollectionAssert.AreEqual(assertions, test.AssertionResults);
            }
            else
            {
                CollectionAssert.IsEmpty(test.AssertionResults);
            }
        }
Example #7
0
 public void RecordAssertion(AssertionStatus status, string?message, string?stackTrace)
 {
     RecordAssertion(new AssertionResult(status, message, stackTrace));
 }
Example #8
0
 public void RecordAssertion(AssertionStatus status, string?message)
 {
     RecordAssertion(status, message, null);
 }
 /// <summary>
 /// Construct an AssertionResult
 /// </summary>
 public AssertionResult(AssertionStatus status, string message, string stackTrace) : this(status, null, null, message, stackTrace)
 {
 }
Example #10
0
 public Assertion(AssertionStatus status, string message)
 {
     Status = status;
     Message = message;
 }
Example #11
0
 /// <summary>
 /// Record an assertion result
 /// </summary>
 public void RecordAssertion(AssertionStatus status, object actual, object expected, string message)
 {
     RecordAssertion(status, actual, expected, message, null);
 }
Example #12
0
 public AssertionResult(AssertionStatus status, string?message, string?stackTrace)
 {
     Status     = status;
     Message    = message;
     StackTrace = stackTrace;
 }
Example #13
0
 /// <summary>
 /// Record an assertion result
 /// </summary>
 public void RecordAssertion(AssertionStatus status, object actual, object expected, string message, string stackTrace)
 {
     RecordAssertion(new AssertionResult(status, actual, expected, message, stackTrace));
 }
Example #14
0
        public void TestFailedAssertionsStringPropertyReturnsIfFormattedFailedAssertionString([Values] bool hasResult,
                                                                                              [Values] bool hasAssertions, [Values] bool missingIsNull, [Values] AssertionStatus status)
        {
            string nl          = Environment.NewLine;
            string missing     = missingIsNull ? null : string.Empty;
            bool   expected    = hasResult && hasAssertions && status != AssertionStatus.Passed;
            string expectedMsg = expected
                ? $"Assertion Status: {status}{nl}message 2{nl}StackTrace:{nl}trace 2{nl}" +
                                 $"Assertion Status: {status}{nl}StackTrace:{nl}trace 3{nl}" +
                                 $"Assertion Status: {status}{nl}message 4"
                : string.Empty;
            IList <AssertionResult> assertions = new List <AssertionResult>
            {
                new AssertionResult(AssertionStatus.Passed, "message 1", "trace 1"),
                null,
                new AssertionResult(status, "message 2", "trace 2"),
                new AssertionResult(status, missing, "trace 3"),
                new AssertionResult(status, "message 4", missing),
            };

            TestResultForTest resultInstance = new TestResultForTest();

            resultInstance.AssertionResults = hasAssertions ? assertions : null;
            ITestResult result = hasResult ? resultInstance : null;

            INUnitTestResult test = new NUnitTestResult(result);

            Assert.AreEqual(expected, test.HasFailedAssertions);
            Assert.AreEqual(expectedMsg, test.FailedAssertionsString);
            if (hasResult && hasAssertions)
            {
                CollectionAssert.AreEqual(assertions, test.AssertionResults);
            }
            else
            {
                CollectionAssert.IsEmpty(test.AssertionResults);
            }
        }
Example #15
0
 /// <summary>
 /// Construct an AssertionResult
 /// </summary>
 public AssertionResult(AssertionStatus status, string message, string stackTrace)
 {
     Status = status;
     Message = message;
     StackTrace = stackTrace;
 }
Example #16
0
 public Assertion(AssertionStatus status, string message)
 {
     Status  = status;
     Message = message;
 }
Example #17
0
 /// <summary>
 /// Record an assertion result
 /// </summary>
 public void RecordAssertion(AssertionStatus status, string message = null, string stackTrace = null)
 {
     RecordAssertion(new AssertionResult(status, message, stackTrace));
 }