/// <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; }
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); }
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); }
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)); } }
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); } }
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); } }
public void RecordAssertion(AssertionStatus status, string?message, string?stackTrace) { RecordAssertion(new AssertionResult(status, message, stackTrace)); }
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) { }
public Assertion(AssertionStatus status, string message) { Status = status; Message = message; }
/// <summary> /// Record an assertion result /// </summary> public void RecordAssertion(AssertionStatus status, object actual, object expected, string message) { RecordAssertion(status, actual, expected, message, null); }
public AssertionResult(AssertionStatus status, string?message, string?stackTrace) { Status = status; Message = message; StackTrace = stackTrace; }
/// <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)); }
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); } }
/// <summary> /// Construct an AssertionResult /// </summary> public AssertionResult(AssertionStatus status, string message, string stackTrace) { Status = status; Message = message; StackTrace = stackTrace; }
/// <summary> /// Record an assertion result /// </summary> public void RecordAssertion(AssertionStatus status, string message = null, string stackTrace = null) { RecordAssertion(new AssertionResult(status, message, stackTrace)); }