public static ITestFailed TestFailed( ITest test, decimal executionTime, string output, Exception ex) { var testCase = test.TestCase; var testMethod = testCase.TestMethod; var testClass = testMethod.TestClass; var testCollection = testClass.TestCollection; var testAssembly = testCollection.TestAssembly; var metadata = ExceptionUtility.ExtractMetadata(ex); var result = Substitute.For <ITestFailed, InterfaceProxy <ITestFailed> >(); result.ExceptionParentIndices.Returns(metadata.ExceptionParentIndices); result.ExceptionTypes.Returns(metadata.ExceptionTypes); result.ExecutionTime.Returns(executionTime); result.Messages.Returns(metadata.Messages); result.Output.Returns(output); result.StackTraces.Returns(metadata.StackTraces); result.Test.Returns(test); result.TestAssembly.Returns(testAssembly); result.TestCase.Returns(testCase); result.TestClass.Returns(testClass); result.TestCollection.Returns(testCollection); result.TestMethod.Returns(testMethod); return(result); }
public static ITestCleanupFailure TestCleanupFailure( ITest test, Exception ex) { var testCase = test.TestCase; var testMethod = testCase.TestMethod; var testClass = testMethod.TestClass; var testCollection = testClass.TestCollection; var testAssembly = testCollection.TestAssembly; var metadata = ExceptionUtility.ExtractMetadata(ex); var result = Substitute.For <ITestCleanupFailure, InterfaceProxy <ITestCleanupFailure> >(); result.ExceptionParentIndices.Returns(metadata.ExceptionParentIndices); result.ExceptionTypes.Returns(metadata.ExceptionTypes); result.Messages.Returns(metadata.Messages); result.StackTraces.Returns(metadata.StackTraces); result.Test.Returns(test); result.TestAssembly.Returns(testAssembly); result.TestCase.Returns(testCase); result.TestClass.Returns(testClass); result.TestCollection.Returns(testCollection); result.TestMethod.Returns(testMethod); return(result); }
static void AssertErrorMetadata( _IErrorMetadata metadata, Exception ex) { var(exceptionTypes, messages, _, exceptionParentIndices, _) = ExceptionUtility.ExtractMetadata(ex); Assert.Equal(exceptionParentIndices, metadata.ExceptionParentIndices); Assert.Equal(exceptionTypes, metadata.ExceptionTypes, StringComparer.Ordinal); Assert.Equal(messages, metadata.Messages, StringComparer.Ordinal); }
static void AssertErrorMetadata( _IErrorMetadata metadata, Exception ex) { var convertedMetadata = ExceptionUtility.ExtractMetadata(ex); Assert.Equal(convertedMetadata.ExceptionParentIndices, metadata.ExceptionParentIndices); Assert.Equal(convertedMetadata.ExceptionTypes, metadata.ExceptionTypes, StringComparer.Ordinal); Assert.Equal(convertedMetadata.Messages, metadata.Messages, StringComparer.Ordinal); Assert.Equal(convertedMetadata.StackTraces, metadata.StackTraces, StringComparer.Ordinal); }
public static IErrorMessage ErrorMessage(Exception ex) { var metadata = ExceptionUtility.ExtractMetadata(ex); var result = Substitute.For <IErrorMessage, InterfaceProxy <IErrorMessage> >(); result.ExceptionParentIndices.Returns(metadata.ExceptionParentIndices); result.ExceptionTypes.Returns(metadata.ExceptionTypes); result.Messages.Returns(metadata.Messages); result.StackTraces.Returns(metadata.StackTraces); return(result); }
public static ITestAssemblyCleanupFailure TestAssemblyCleanupFailure( ITestAssembly testAssembly, Exception ex) { var metadata = ExceptionUtility.ExtractMetadata(ex); var result = Substitute.For <ITestAssemblyCleanupFailure, InterfaceProxy <ITestAssemblyCleanupFailure> >(); result.ExceptionParentIndices.Returns(metadata.ExceptionParentIndices); result.ExceptionTypes.Returns(metadata.ExceptionTypes); result.Messages.Returns(metadata.Messages); result.StackTraces.Returns(metadata.StackTraces); result.TestAssembly.Returns(testAssembly); return(result); }
public static async void ConvertsTestFailed() { (string?[] ExceptionTypes, string[] Messages, string?[] StackTraces, int[] ExceptionParentIndices, FailureCause _)errorMetadata; try { throw new Exception(); } catch (Exception e) { errorMetadata = ExceptionUtility.ExtractMetadata(e); } TestResult?testResult = null; var listener = Substitute.For <ITestListener>(); listener .WhenAny(l => l.TestFinished(null)) .Do <TestResult>(result => testResult = result); await using var sink = new ResultSink(listener, 42); sink.OnMessage(TestData.TestClassStarting(testClass: typeof(object).FullName !)); sink.OnMessage(TestData.TestMethodStarting(testMethod: nameof(object.GetHashCode))); sink.OnMessage(TestData.TestStarting(testDisplayName: "Display Name")); var message = TestData.TestFailed( exceptionParentIndices: errorMetadata.ExceptionParentIndices, exceptionTypes: errorMetadata.ExceptionTypes, executionTime: 123.45m, messages: errorMetadata.Messages, stackTraces: errorMetadata.StackTraces ); sink.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(object), testResult.FixtureType); Assert.Equal(nameof(object.GetHashCode), testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Failed, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(42, testResult.TotalTests); Assert.Equal($"{errorMetadata.ExceptionTypes[0]} : {errorMetadata.Messages[0]}", testResult.Message); Assert.Equal(errorMetadata.StackTraces[0], testResult.StackTrace); }