public static void ConvertsITestFailed() { Exception ex; try { throw new Exception(); } catch (Exception e) { ex = e; } TestResult testResult = null; var listener = Substitute.For <ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do <TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener, 42); var message = Mocks.TestFailed(typeof(string), "Contains", "Display Name", executionTime: 123.45M, ex: ex); visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", 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("System.Exception : " + ex.Message, testResult.Message); Assert.Equal(ex.StackTrace, testResult.StackTrace); }
public void ConvertsITestSkipped() { TestResult testResult = null; var listener = Substitute.For <ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do <TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener); var message = new TestSkipped { TestCase = new TestCase(typeof(string), "Contains"), TestDisplayName = "Display Name", ExecutionTime = 123.45M, Reason = "I forgot how to run" }; visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Ignored, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(1, testResult.TotalTests); Assert.Equal("I forgot how to run", testResult.Message); }
public static void SignalsFinishedEventUponReceiptOfITestAssemblyFinished() { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener, 42); var message = Substitute.For <ITestAssemblyFinished>(); visitor.OnMessage(message); Assert.True(visitor.Finished.WaitOne(0)); }
public void SignalsFinishedEventUponReceiptOfITestAssemblyFinished() { var listener = Substitute.For<ITestListener>(); var visitor = new ResultVisitor(listener); var message = Substitute.For<ITestAssemblyFinished>(); visitor.OnMessage(message); Assert.True(visitor.Finished.WaitOne(0)); }
public void Success_MovesToSuccess() { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = TestRunState.NoTests }; visitor.OnMessage(new TestPassed()); Assert.Equal(TestRunState.Success, visitor.TestRunState); }
public static void Skip_StaysInCurrentState(TestRunState initialState) { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener, 42) { TestRunState = initialState }; visitor.OnMessage(Substitute.For <ITestSkipped>()); Assert.Equal(initialState, visitor.TestRunState); }
public static void FailureSetsStateToFailed(TestRunState initialState) { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener, 42) { TestRunState = initialState }; visitor.OnMessage(Mocks.TestFailed(typeof(Object), "GetHashCode")); Assert.Equal(TestRunState.Failure, visitor.TestRunState); }
public static void Skip_MovesToSuccess() { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener, 42) { TestRunState = TestRunState.NoTests }; visitor.OnMessage(Substitute.For <ITestSkipped>()); Assert.Equal(TestRunState.Success, visitor.TestRunState); }
public void Success_StaysInCurrentState(TestRunState initialState) { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = initialState }; visitor.OnMessage(new TestPassed()); Assert.Equal(initialState, visitor.TestRunState); }
public void FailureSetsStateToFailed(TestRunState initialState) { var listener = Substitute.For <ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = initialState }; visitor.OnMessage(new TestFailed()); Assert.Equal(TestRunState.Failure, visitor.TestRunState); }
public static void ConvertsITestPassed() { TestResult testResult = null; var listener = Substitute.For <ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do <TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener, 42); var message = Mocks.TestPassed(typeof(string), "Contains", "Display Name", executionTime: 123.45M); visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Passed, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(42, testResult.TotalTests); }
public static void LogsTestFailure(IMessageSinkMessage message, string messageType) { var listener = Substitute.For <ITestListener>(); using (var visitor = new ResultVisitor(listener, 42) { TestRunState = TestRunState.NoTests }) { visitor.OnMessage(message); Assert.Equal(TestRunState.Failure, visitor.TestRunState); var testResult = listener.Captured(x => x.TestFinished(null)).Arg <TestResult>(); Assert.Equal($"*** {messageType} ***", testResult.Name); Assert.Equal(TestState.Failed, testResult.State); Assert.Equal(1, testResult.TotalTests); Assert.Equal("ExceptionType : This is my message \t\r\n", testResult.Message); Assert.Equal("Line 1\r\nLine 2\r\nLine 3", testResult.StackTrace); } }
public void ConvertsITestFailed() { Exception ex; try { throw new Exception(); } catch (Exception e) { ex = e; } TestResult testResult = null; var listener = Substitute.For <ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do <TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener); var message = new TestFailed(ex) { TestCase = new TestCase(typeof(string), "Contains"), TestDisplayName = "Display Name", ExecutionTime = 123.45M, }; visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Failed, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(1, testResult.TotalTests); Assert.Equal(ExceptionUtility.GetMessage(ex), testResult.Message); Assert.Equal(ExceptionUtility.GetStackTrace(ex), testResult.StackTrace); }
public void ConvertsITestFailed() { Exception ex; try { throw new Exception(); } catch (Exception e) { ex = e; } TestResult testResult = null; var listener = Substitute.For<ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do<TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener); var message = new TestFailed(ex) { TestCase = new TestCase(typeof(string), "Contains"), TestDisplayName = "Display Name", ExecutionTime = 123.45M, }; visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Failed, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(1, testResult.TotalTests); Assert.Equal(ExceptionUtility.GetMessage(ex), testResult.Message); Assert.Equal(ExceptionUtility.GetStackTrace(ex), testResult.StackTrace); }
public void Success_MovesToSuccess() { var listener = Substitute.For<ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = TestRunState.NoTests }; visitor.OnMessage(new TestPassed()); Assert.Equal(TestRunState.Success, visitor.TestRunState); }
public void Success_StaysInCurrentState(TestRunState initialState) { var listener = Substitute.For<ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = initialState }; visitor.OnMessage(new TestPassed()); Assert.Equal(initialState, visitor.TestRunState); }
public void FailureSetsStateToFailed(TestRunState initialState) { var listener = Substitute.For<ITestListener>(); var visitor = new ResultVisitor(listener) { TestRunState = initialState }; visitor.OnMessage(new TestFailed()); Assert.Equal(TestRunState.Failure, visitor.TestRunState); }
public void ConvertsITestPassed() { TestResult testResult = null; var listener = Substitute.For<ITestListener>(); listener.WhenAny(l => l.TestFinished(null)) .Do<TestResult>(result => testResult = result); var visitor = new ResultVisitor(listener); var message = new TestPassed { TestCase = new TestCase(typeof(string), "Contains"), TestDisplayName = "Display Name", ExecutionTime = 123.45M }; visitor.OnMessage(message); Assert.NotNull(testResult); Assert.Same(typeof(string), testResult.FixtureType); Assert.Equal("Contains", testResult.Method.Name); Assert.Equal("Display Name", testResult.Name); Assert.Equal(TestState.Passed, testResult.State); Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds); Assert.Equal(1, testResult.TotalTests); }