public async void OnlyIncludesLongRunningTests() { var sink = new TestableTestExecutionSink(longRunningSeconds: 1); var events = new List <ILongRunningTestsMessage>(); sink.LongRunningTestsEvent += args => events.Add(args.Message); var testCase1 = Substitute.For <ITestCase>(); var testCase2 = Substitute.For <ITestCase>(); sink.OnMessage(Substitute.For <ITestAssemblyStarting>()); sink.OnMessage(new TestCaseStarting(testCase1)); await sink.AdvanceClockAsync(500); sink.OnMessage(new TestCaseStarting(testCase2)); // Started later, hasn't run long enough await sink.AdvanceClockAsync(500); sink.OnMessage(new TestCaseFinished(testCase1, 8009, 1, 0, 0)); sink.OnMessage(new TestCaseFinished(testCase2, 8009, 1, 0, 0)); sink.OnMessage(Substitute.For <ITestAssemblyFinished>()); var @event = Assert.Single(events); Assert.Equal(TimeSpan.FromSeconds(1), @event.ConfiguredLongRunningTime); var receivedTestCasePair = Assert.Single(@event.TestCases); Assert.Same(testCase1, receivedTestCasePair.Key); Assert.Equal(TimeSpan.FromSeconds(1), receivedTestCasePair.Value); }
public async void LongRunningTest_Once_WithoutLongRunningTestHandler() { var events = new List <IDiagnosticMessage>(); var diagSink = Substitute.For <IMessageSinkWithTypes>(); diagSink.WhenForAnyArgs(x => x.OnMessageWithTypes(null, null)) .Do(callInfo => { var message = callInfo.Arg <IMessageSinkMessage>(); var diagnosticMessage = message as IDiagnosticMessage; if (diagnosticMessage != null) { events.Add(diagnosticMessage); } }); var sink = new TestableTestExecutionSink(diagnosticMessageSink: diagSink, longRunningSeconds: 1); var testCase = Substitute.For <ITestCase>(); testCase.DisplayName.Returns("My test display name"); sink.OnMessage(Substitute.For <ITestAssemblyStarting>()); sink.OnMessage(new TestCaseStarting(testCase)); await sink.AdvanceClockAsync(1000); sink.OnMessage(new TestCaseFinished(testCase, 8009, 1, 0, 0)); sink.OnMessage(Substitute.For <ITestAssemblyFinished>()); var @event = Assert.Single(events); Assert.Equal("[Long Running Test] 'My test display name', Elapsed: 00:00:01", @event.Message); }
public async void LongRunningTest_Twice_WithLongRunningTestHandler() { var sink = new TestableTestExecutionSink(longRunningSeconds: 1); var events = new List <ILongRunningTestsMessage>(); sink.LongRunningTestsEvent += args => events.Add(args.Message); var testCase = Substitute.For <ITestCase>(); sink.OnMessage(Substitute.For <ITestAssemblyStarting>()); sink.OnMessage(new TestCaseStarting(testCase)); await sink.AdvanceClockAsync(1000); await sink.AdvanceClockAsync(500); await sink.AdvanceClockAsync(500); sink.OnMessage(new TestCaseFinished(testCase, 8009, 1, 0, 0)); sink.OnMessage(Substitute.For <ITestAssemblyFinished>()); Assert.Collection(events, @event => { Assert.Equal(TimeSpan.FromSeconds(1), @event.ConfiguredLongRunningTime); var receivedTestCasePair = Assert.Single(@event.TestCases); Assert.Same(testCase, receivedTestCasePair.Key); Assert.Equal(TimeSpan.FromSeconds(1), receivedTestCasePair.Value); }, @event => { Assert.Equal(TimeSpan.FromSeconds(1), @event.ConfiguredLongRunningTime); var receivedTestCasePair = Assert.Single(@event.TestCases); Assert.Same(testCase, receivedTestCasePair.Key); Assert.Equal(TimeSpan.FromSeconds(2), receivedTestCasePair.Value); } ); }
public async void ShortRunningTests_NoMessages() { var sink = new TestableTestExecutionSink(longRunningSeconds: 1); var events = new List <ILongRunningTestsMessage>(); sink.LongRunningTestsEvent += args => events.Add(args.Message); var testCase1 = Substitute.For <ITestCase>(); sink.OnMessage(Substitute.For <ITestAssemblyStarting>()); sink.OnMessage(new TestCaseStarting(testCase1)); await sink.AdvanceClockAsync(100); sink.OnMessage(new TestCaseFinished(testCase1, 8009, 1, 0, 0)); sink.OnMessage(Substitute.For <ITestAssemblyFinished>()); Assert.Empty(events); }