private void CheckForTimeout() { if (CurrentTest != null && CurrentTest.Duration > _testTimeout) { CurrentTest.TimedOut(CurrentTest.Duration.TotalSeconds); _logger.TestThrew(CurrentTest); // fake skipping of all unfinished tests for (int i = _tests.Count; i < _testCount; ++i) { var dummyTest = new Test(string.Format("UnknownTest{0}", i)); _tests.Add(dummyTest); CurrentTest.Threw("Previous test timed out"); _logger.TestThrew(CurrentTest); } _currentState = State.Finished; _isFinished.Set(); } }
public void EventOccured(NameValueCollection eventDetails) { lock (_lock) { var eventType = eventDetails.Get("event"); if (eventType == "ready") { if (CurrentState != State.WaitingForReady) { throw new InvalidOperationException("Unexpected 'ready'-event"); } _testCount = int.Parse(eventDetails.Get("testCount")); _currentState = State.Ready; return; } if (CurrentState < State.Ready) { throw new InvalidOperationException(string.Format("Unexpected '{0}'-event", eventType)); } var testName = eventDetails.Get("testName"); var us = eventDetails["us"] != null?int.Parse(eventDetails["us"]) : -1; switch (eventType) { case "testStarted": if (CurrentState != State.Ready) { throw new InvalidOperationException("Unexpected 'testStarted'-event"); } var test = new Test(testName); _tests.Add(test); _currentState = State.Running; CurrentTest.Started(); break; case "testPassed": if (CurrentState != State.Running) { throw new InvalidOperationException("Unexpected 'testPassed'-event"); } if (!CurrentTest.Name.Equals(testName)) { throw new InvalidOperationException("Event for wrong test"); } CurrentTest.Passed(us); _logger.TestPassed(CurrentTest); _currentState = State.Ready; break; case "testIgnored": if (CurrentState != State.Running) { throw new InvalidOperationException("Unexpected 'testIgnored'-event"); } if (!CurrentTest.Name.Equals(testName)) { throw new InvalidOperationException("Event for wrong test"); } CurrentTest.Ignored(eventDetails.Get("reason")); _logger.TestIgnored(CurrentTest); _currentState = State.Ready; break; case "testAsserted": if (CurrentState != State.Running) { throw new InvalidOperationException("Unexpected 'testAsserted'-event"); } if (!CurrentTest.Name.Equals(testName)) { throw new InvalidOperationException("Event for wrong test"); } CurrentTest.Asserted(Assertion.From(eventDetails)); _logger.TestAsserted(CurrentTest); _currentState = State.Ready; break; case "testThrew": if (CurrentState != State.Running) { throw new InvalidOperationException("Unexpected 'testThrew'-event"); } if (!CurrentTest.Name.Equals(testName)) { throw new InvalidOperationException("Event for wrong test"); } CurrentTest.Threw(eventDetails.Get("message")); _logger.TestThrew(CurrentTest); _currentState = State.Ready; break; case "internalError": _logger.InternalError(eventDetails.Get("message")); break; default: throw new Exception(string.Format("Internal Error: Unknown event '{0}' (name={1})", eventType, testName)); } if (_tests.Count == _testCount && _currentState == State.Ready) { End(); } } }