/// <inheritdoc/> public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler discoveryEventsHandler) { try { this.communicationManager.SendMessage(MessageType.StartDiscovery, discoveryCriteria, version: this.protocolVersion); var isDiscoveryComplete = false; // Cycle through the messages that the testhost sends. // Currently each of the operations are not separate tasks since they should not each take much time. This is just a notification. while (!isDiscoveryComplete) { var rawMessage = this.TryReceiveRawMessage(); if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose("Received message: {0}", rawMessage); } // Send raw message first to unblock handlers waiting to send message to IDEs discoveryEventsHandler.HandleRawMessage(rawMessage); var message = this.dataSerializer.DeserializeMessage(rawMessage); if (string.Equals(MessageType.TestCasesFound, message.MessageType)) { var testCases = this.dataSerializer.DeserializePayload <IEnumerable <TestCase> >(message); discoveryEventsHandler.HandleDiscoveredTests(testCases); } else if (string.Equals(MessageType.DiscoveryComplete, message.MessageType)) { var discoveryCompletePayload = this.dataSerializer.DeserializePayload <DiscoveryCompletePayload>(message); discoveryEventsHandler.HandleDiscoveryComplete( discoveryCompletePayload.TotalTests, discoveryCompletePayload.LastDiscoveredTests, discoveryCompletePayload.IsAborted); isDiscoveryComplete = true; } else if (string.Equals(MessageType.TestMessage, message.MessageType)) { var testMessagePayload = this.dataSerializer.DeserializePayload <TestMessagePayload>(message); discoveryEventsHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); } } } catch (Exception ex) { this.OnDiscoveryAbort(discoveryEventsHandler, ex); } }
// simulate the discovery of tests private static void DiscoverTests(IEnumerable <string> sources, string discoverySettings, ITestDiscoveryEventsHandler discoveryEventsHandler, ICollection <TestCase> tests, bool aborted) { Task.Run(() => discoveryEventsHandler.HandleDiscoveredTests(tests)). ContinueWith((t, u) => discoveryEventsHandler.HandleDiscoveryComplete((int)u, null, aborted), tests.Count); }
/// <inheritdoc /> public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler discoveryEventsHandler) { this.messageEventHandler = discoveryEventsHandler; this.onDisconnected = (disconnectedEventArgs) => { this.OnDiscoveryAbort(discoveryEventsHandler, disconnectedEventArgs.Error, true); }; this.onMessageReceived = (sender, args) => { try { var rawMessage = args.Data; // Currently each of the operations are not separate tasks since they should not each take much time. This is just a notification. if (EqtTrace.IsInfoEnabled) { EqtTrace.Info("TestRequestSender: Received message: {0}", rawMessage); } // Send raw message first to unblock handlers waiting to send message to IDEs discoveryEventsHandler.HandleRawMessage(rawMessage); var data = this.dataSerializer.DeserializeMessage(rawMessage); switch (data.MessageType) { case MessageType.TestCasesFound: var testCases = this.dataSerializer.DeserializePayload <IEnumerable <TestCase> >(data); discoveryEventsHandler.HandleDiscoveredTests(testCases); break; case MessageType.DiscoveryComplete: var discoveryCompletePayload = this.dataSerializer.DeserializePayload <DiscoveryCompletePayload>(data); discoveryEventsHandler.HandleDiscoveryComplete( discoveryCompletePayload.TotalTests, discoveryCompletePayload.LastDiscoveredTests, discoveryCompletePayload.IsAborted); this.SetOperationComplete(); break; case MessageType.TestMessage: var testMessagePayload = this.dataSerializer.DeserializePayload <TestMessagePayload>( data); discoveryEventsHandler.HandleLogMessage( testMessagePayload.MessageLevel, testMessagePayload.Message); break; } } catch (Exception ex) { this.OnDiscoveryAbort(discoveryEventsHandler, ex, false); } }; this.channel.MessageReceived += this.onMessageReceived; var message = this.dataSerializer.SerializePayload( MessageType.StartDiscovery, discoveryCriteria, this.protocolVersion); this.channel.Send(message); }