How to use StartDiscovery method of Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient.StartDiscovery

DesignModeClient.cs

Source:DesignModeClient.cs Github

copy

Full Screen

...131 var extensionPaths = this.communicationManager.DeserializePayload<IEnumerable<string>>(message);132 testRequestManager.InitializeExtensions(extensionPaths, skipExtensionFilters: true);133 break;134 }135 case MessageType.StartDiscovery:136 {137 var discoveryPayload = this.dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message); 138 this.StartDiscovery(discoveryPayload, testRequestManager);139 break;140 }141 case MessageType.GetTestRunnerProcessStartInfoForRunAll:142 case MessageType.GetTestRunnerProcessStartInfoForRunSelected:143 {144 var testRunPayload =145 this.communicationManager.DeserializePayload<TestRunRequestPayload>(146 message);147 this.StartTestRun(testRunPayload, testRequestManager, skipTestHostLaunch: true);148 break;149 }150 case MessageType.TestRunAllSourcesWithDefaultHost:151 case MessageType.TestRunSelectedTestCasesDefaultHost:152 {153 var testRunPayload =154 this.communicationManager.DeserializePayload<TestRunRequestPayload>(155 message);156 this.StartTestRun(testRunPayload, testRequestManager, skipTestHostLaunch: false);157 break;158 }159 case MessageType.CancelTestRun:160 {161 testRequestManager.CancelTestRun();162 break;163 }164 case MessageType.AbortTestRun:165 {166 testRequestManager.AbortTestRun();167 break;168 }169 case MessageType.CustomTestHostLaunchCallback:170 {171 this.onAckMessageReceived?.Invoke(message);172 break;173 }174 case MessageType.SessionEnd:175 {176 EqtTrace.Info("DesignModeClient: Session End message received from server. Closing the connection.");177 isSessionEnd = true;178 this.Dispose();179 break;180 }181 default:182 {183 EqtTrace.Info("DesignModeClient: Invalid Message received: {0}", message);184 break;185 }186 }187 }188 catch (Exception ex)189 {190 EqtTrace.Error("DesignModeClient: Error processing request: {0}", ex);191 isSessionEnd = true;192 this.Dispose();193 }194 }195 while (!isSessionEnd);196 }197 /// <summary>198 /// Send a custom host launch message to IDE199 /// </summary>200 /// <param name="testProcessStartInfo">201 /// The test Process Start Info.202 /// </param>203 /// <returns>204 /// The <see cref="int"/>.205 /// </returns>206 public int LaunchCustomHost(TestProcessStartInfo testProcessStartInfo)207 {208 lock (ackLockObject)209 {210 var waitHandle = new AutoResetEvent(false);211 Message ackMessage = null;212 this.onAckMessageReceived = (ackRawMessage) =>213 {214 ackMessage = ackRawMessage;215 waitHandle.Set();216 };217 this.communicationManager.SendMessage(MessageType.CustomTestHostLaunch, testProcessStartInfo);218 // LifeCycle of the TP through DesignModeClient is maintained by the IDEs or user-facing-clients like LUTs, who call TestPlatform219 // TP is handing over the control of launch to these IDEs and so, TP has to wait indefinite220 // Even if TP has a timeout here, there is no way TP can abort or stop the thread/task that is hung in IDE or LUT221 // Even if TP can abort the API somehow, TP is essentially putting IDEs or Clients in inconsistent state without having info on222 // Since the IDEs own user-UI-experience here, TP will let the custom host launch as much time as IDEs define it for their users223 waitHandle.WaitOne();224 this.onAckMessageReceived = null;225 var ackPayload = this.dataSerializer.DeserializePayload<CustomHostLaunchAckPayload>(ackMessage);226 if (ackPayload.HostProcessId > 0)227 {228 return ackPayload.HostProcessId;229 }230 else231 {232 throw new TestPlatformException(ackPayload.ErrorMessage);233 }234 }235 }236 /// <summary>237 /// Send the raw messages to IDE238 /// </summary>239 /// <param name="rawMessage"></param>240 public void SendRawMessage(string rawMessage)241 {242 this.communicationManager.SendRawMessage(rawMessage);243 }244 private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool skipTestHostLaunch)245 {246 Task.Run(247 delegate248 {249 try250 {251 testRequestManager.ResetOptions();252 var customLauncher = skipTestHostLaunch ?253 DesignModeTestHostLauncherFactory.GetCustomHostLauncherForTestRun(this, testRunPayload) : null;254 testRequestManager.RunTests(testRunPayload, customLauncher, new DesignModeTestEventsRegistrar(this), this.protocolConfig);255 }256 catch (Exception ex)257 {258 EqtTrace.Error("DesignModeClient: Exception in StartTestRun: " + ex);259 // If there is an exception during test run request creation or some time during the process260 // In such cases, TestPlatform will never send a TestRunComplete event and IDE need to be sent a run complete message261 // We need recoverability in translationlayer-designmode scenarios262 var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };263 this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);264 var runCompletePayload = new TestRunCompletePayload()265 {266 TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, true, ex, null, TimeSpan.MinValue),267 LastRunTests = null268 };269 // Send run complete to translation layer270 this.communicationManager.SendMessage(MessageType.ExecutionComplete, runCompletePayload);271 }272 });273 }274 private void StartDiscovery(DiscoveryRequestPayload discoveryRequestPayload, ITestRequestManager testRequestManager)275 {276 Task.Run(277 delegate278 {279 try280 {281 testRequestManager.ResetOptions();282 testRequestManager.DiscoverTests(discoveryRequestPayload, new DesignModeTestEventsRegistrar(this), this.protocolConfig);283 }284 catch (Exception ex)285 {286 EqtTrace.Error("DesignModeClient: Exception in StartDiscovery: " + ex);287 // If there is an exception during test discovery request creation or some time during the process288 // In such cases, TestPlatform will never send a DiscoveryComplete event and IDE need to be sent a discovery complete message289 // We need recoverability in translationlayer-designmode scenarios290 var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = ex.ToString() };291 this.communicationManager.SendMessage(MessageType.TestMessage, testMessagePayload);292 var payload = new DiscoveryCompletePayload()293 {294 IsAborted = true,295 LastDiscoveredTests = null,296 TotalTests = -1297 };298 // Send run complete to translation layer299 this.communicationManager.SendMessage(MessageType.DiscoveryComplete, payload);300 }...

Full Screen

Full Screen

StartDiscovery

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9{10 {11 static void Main(string[] args)12 {13 var client = new DesignModeClient();14 var request = new DiscoveryRequest();15 var handler = new DiscoveryEventHandler();16 client.DiscoverTests(request, handler);17 Console.ReadLine();18 }19 }20}21using System;22using System.Collections.Generic;23using System.Linq;24using System.Text;25using System.Threading.Tasks;26using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;27using Microsoft.VisualStudio.TestPlatform.ObjectModel;28using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;29{30 {31 static void Main(string[] args)32 {33 var client = new DesignModeClient();34 var request = new TestRunRequest();35 var handler = new TestRunEventHandler();36 client.StartTestRun(request, handler);37 Console.ReadLine();38 }39 }40}41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;47using Microsoft.VisualStudio.TestPlatform.ObjectModel;48using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;49{50 {51 static void Main(string[] args)52 {53 var client = new DesignModeClient();54 var request = new TestRunRequest();55 var handler = new TestRunEventHandler();56 client.StartTestDiscovery(request, handler);57 Console.ReadLine();58 }59 }60}61using System;62using System.Collections.Generic;63using System.Linq;64using System.Text;65using System.Threading.Tasks;66using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;67using Microsoft.VisualStudio.TestPlatform.ObjectModel;68using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;69{70 {71 static void Main(string[] args)72 {73 var client = new DesignModeClient();

Full Screen

Full Screen

StartDiscovery

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Text;4using System.Threading.Tasks;5using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;6using Microsoft.VisualStudio.TestPlatform.ObjectModel;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9{10 {11 static void Main(string[] args)12 {13 StartDiscovery();14 }15 private static void StartDiscovery()16 {17 var designModeClient = new DesignModeClient();18 designModeClient.OnDiscoveryComplete += DesignModeClient_OnDiscoveryComplete;19 designModeClient.OnDiscoveryMessage += DesignModeClient_OnDiscoveryMessage;20 designModeClient.OnDiscoveryProgress += DesignModeClient_OnDiscoveryProgress;21 designModeClient.StartDiscovery("C:\\Users\\myuser\\source\\repos\\TestProject1\\TestProject1\\bin\\Debug\\netcoreapp2.2\\TestProject1.dll", new TestPlatformOptions(), new TestLoggerEvents(new TestLoggerEventsHandler()));22 }23 private static void DesignModeClient_OnDiscoveryComplete(object sender, DiscoveryCompleteEventArgs e)24 {25 Console.WriteLine("Discovery complete");26 }27 private static void DesignModeClient_OnDiscoveryMessage(object sender, DiscoveryMessageEventArgs e)28 {29 Console.WriteLine("Discovery message: {0}", e.Message);30 }31 private static void DesignModeClient_OnDiscoveryProgress(object sender, DiscoveryProgressEventArgs e)32 {33 Console.WriteLine("Discovered tests: {0}", e.DiscoveredTests);34 }35 }36}

Full Screen

Full Screen

StartDiscovery

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using Microsoft.VisualStudio.TestPlatform.ObjectModel;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;5using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;6{7 {8 static void Main(string[] args)9 {10 var client = new Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient();11 var request = new DiscoveryRequest();12 var handler = new DiscoveryEventHandler();13 client.StartDiscovery(request, handler);14 Console.ReadKey();15 }16 }17 {18 public override IEnumerable<string> Sources => new List<string> { "2.dll" };19 }20 {21 public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable<TestCase> lastChunk)22 {23 throw new NotImplementedException();24 }25 public void HandleDiscoveredTests(DiscoveredTestsEventArgs discoveredTestsEventArgs)26 {27 throw new NotImplementedException();28 }29 public void HandleLogMessage(TestPlatformEventArg

Full Screen

Full Screen

StartDiscovery

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10{11 {12 static void Main(string[] args)13 {14 var client = new DesignModeClient();15 ar sourcs = ew Lis<string>();16 sources.dd(@"C:\Uses\test\Downloads\test1\test1\bin\Debu\tet1dll");17 var discoveryEvents = new DiscoveryEvents();18 client.StartDiscovery(sources, discoveryEvents);19 nsole.ReadLine();20 }21 }22 {23 {24 Console.WriteLine("Discovery complete"25using System; discoveredTests)26 {27 Console.WriteLine("HandleDiscoveredTests");28 }29 public void HandleLogMessage(TestMessageLevel level, string message)30 {31 Console.WriteLine("HandleLogMessage");32 }33 public void HandleRawMessage(string rawMessage)34 {35 Console.WriteLine("HandleRawMessage");36 }37 public void HandleTestRunMessage(TestMessageLevel level, string message)38 {39 Console.WriteLine("HandleTestRunMessage");40 }41 }42}43Error 1 The type or namespace name 'DesignMode' does not exist in the namespace'Microsoft.VisualStudio.TestPlatform.Client' (are you missing an assembly reference?) C:\Users\test\Downloads\test1\test1\3.cs 3 7 test144using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;49using Microsoft.VisualStudio.TestPlatform.ObjectModel;50using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;51using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;52using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;53using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;54using System.Threading;55using System.Diagnostics;56using System.IO;57using System.Reflection;58using System.Xml;59using System.Xml.Linq;60using System.Xml.XPath;61{62 {63 static void Main(string[] args)64 {65 <TestAdaptersPaths>C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\TestPlatform\Extensions\Microsoft\TestWindow</TestAdaptersPaths>66 </RunSettings>";67 var testSources = new List<string>();68 testSources.Add(@"C:\Users\saksham\Desktop\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll");69 var designModeClient = new DesignModeClient();70 designModeClient.StartDiscovery(runSettings, testSources);71 var discoveryEventHandler = new DiscoveryEventHandler();72 designModeClient.DiscoverTests(testSources, runSettings, discoveryEventHandler);73 Console.ReadLine();74 }75 }76 {77 public void HandleDiscoveryComplete(int totalTests, IEnumerable<TestCase> lastChunk, bool isAborted, IEnumerable<DiscoveryCompleteEventArgs2> discoveryCompleteEventArgs)78 {79 Console.WriteLine("Total tests: " + totalTests);80 Console.WriteLine("Last chunk: " + lastChunk.Count());81 Console.WriteLine("Is aborted: " + isAborted);82 Console.WriteLine("Discovery complete event args: " + discoveryCompleteEventArgs.Count());83 }84 public void HandleDiscoveredTests(IEnumerable<TestCase> discovered

Full Screen

Full Screen

StartDiscovery

Using AI Code Generation

copy

Full Screen

1using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;7 using Microsoft.VisualStudio.TestPlatform.ObjectModel;8{9 {10 static void Main( string [] args)11 {12 DesignModeClient client = new DesignModeClient();13 client.StartDiscovery( new DiscoveryCriteria( "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\TestWindow\\vstest.console.exe" ));14 client.StopDiscovery();15 client.StartTestRun( new TestRunCriteria( "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\TestWindow\\vstest.console.exe" ));16 client.StopTestRun();17 }18 }19}20using System;21 using System.Collections.Generic;22 using System.Linq;23 using System.Text;24 using System.Threading.Tasks;25 using Microsoft.VisualStudio.TestPlatform.Client.DesignMode;26 using Microsoft.VisualStudio.TestPlatform.ObjectModel;27{28 {29 static void Main( string [] args)30 {31 DesignModeClient client = new DesignModeClient();32 client.StartDiscovery( new DiscoveryCriteria( "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\TestWindow\\vstest.console.exe" ));33 client.StopDiscovery();34 client.StartTestRun( new TestRunCriteria( "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\TestWindow\\vstest.console.exe" ));35 client.StopTestRun();36 }37 }38}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful