/// <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;
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 7
0
 public void RecordAssertion(AssertionStatus status, string?message, string?stackTrace)
 {
     RecordAssertion(new AssertionResult(status, message, stackTrace));
 }
Esempio n. 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)
 {
 }
Esempio n. 10
0
 public Assertion(AssertionStatus status, string message)
 {
     Status = status;
     Message = message;
 }
Esempio n. 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);
 }
Esempio n. 12
0
 public AssertionResult(AssertionStatus status, string?message, string?stackTrace)
 {
     Status     = status;
     Message    = message;
     StackTrace = stackTrace;
 }
Esempio n. 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));
 }
Esempio n. 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);
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Construct an AssertionResult
 /// </summary>
 public AssertionResult(AssertionStatus status, string message, string stackTrace)
 {
     Status = status;
     Message = message;
     StackTrace = stackTrace;
 }
Esempio n. 16
0
 public Assertion(AssertionStatus status, string message)
 {
     Status  = status;
     Message = message;
 }
Esempio n. 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));
 }