How to use ProxyDiscoveryManager class of Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client package

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager

ProxyDiscoveryManager.cs

Source:ProxyDiscoveryManager.cs Github

copy

Full Screen

...19 using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;20 /// <summary>21 /// Orchestrates discovery operations for the engine communicating with the client.22 /// </summary>23 public class ProxyDiscoveryManager : ProxyOperationManager, IProxyDiscoveryManager, ITestDiscoveryEventsHandler224 {25 private readonly ITestRuntimeProvider testHostManager;26 private IDataSerializer dataSerializer;27 private CancellationTokenSource cancellationTokenSource;28 private bool isCommunicationEstablished;29 private IRequestData requestData;30 private ITestDiscoveryEventsHandler2 baseTestDiscoveryEventsHandler;31 #region Constructors32 /// <summary>33 /// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class.34 /// </summary>35 /// <param name="requestData">The Request Data for providing discovery services and data.</param>36 /// <param name="testRequestSender">Test request sender instance.</param>37 /// <param name="testHostManager">Test host manager instance.</param>38 public ProxyDiscoveryManager(IRequestData requestData, ITestRequestSender testRequestSender, ITestRuntimeProvider testHostManager)39 : this(requestData, testRequestSender, testHostManager, JsonDataSerializer.Instance, CrossPlatEngine.Constants.ClientConnectionTimeout)40 {41 this.testHostManager = testHostManager;42 }43 /// <summary>44 /// Initializes a new instance of the <see cref="ProxyDiscoveryManager"/> class.45 /// Constructor with Dependency injection. Used for unit testing.46 /// </summary>47 /// <param name="requestSender">48 /// The request Sender.49 /// </param>50 /// <param name="testHostManager">51 /// Test host Manager instance52 /// </param>53 /// <param name="dataSerializer"></param>54 /// <param name="clientConnectionTimeout">55 /// The client Connection Timeout56 /// </param>57 internal ProxyDiscoveryManager(58 IRequestData requestData,59 ITestRequestSender requestSender,60 ITestRuntimeProvider testHostManager,61 IDataSerializer dataSerializer,62 int clientConnectionTimeout)63 : base(requestData, requestSender, testHostManager, clientConnectionTimeout)64 {65 this.dataSerializer = dataSerializer;66 this.testHostManager = testHostManager;67 this.cancellationTokenSource = new CancellationTokenSource();68 this.isCommunicationEstablished = false;69 this.requestData = requestData;70 }71 #endregion72 #region IProxyDiscoveryManager implementation.73 /// <summary>74 /// Ensure that the discovery component of engine is ready for discovery usually by loading extensions.75 /// </summary>76 public void Initialize()77 {78 }79 /// <summary>80 /// Discovers tests81 /// </summary>82 /// <param name="discoveryCriteria">Settings, parameters for the discovery request</param>83 /// <param name="eventHandler">EventHandler for handling discovery events from Engine</param>84 public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)85 {86 this.baseTestDiscoveryEventsHandler = eventHandler;87 try88 {89 this.isCommunicationEstablished = this.SetupChannel(discoveryCriteria.Sources, this.cancellationTokenSource.Token);90 if (this.isCommunicationEstablished)91 {92 this.InitializeExtensions(discoveryCriteria.Sources);93 discoveryCriteria.UpdateDiscoveryCriteria(testHostManager);94 this.RequestSender.DiscoverTests(discoveryCriteria, this);95 }96 }97 catch (Exception exception)98 {99 EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);100 // Log to vs ide test output101 var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.Message };102 var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);103 this.HandleRawMessage(rawMessage);104 // Log to vstest.console105 // Send a discovery complete to caller. Similar logic is also used in ParallelProxyDiscoveryManager.DiscoverTestsOnConcurrentManager106 // Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager107 // created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error108 // and the test host is lost as well.109 this.HandleLogMessage(TestMessageLevel.Error, exception.Message);110 var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(-1, true);111 this.HandleDiscoveryComplete(discoveryCompleteEventsArgs, new List<ObjectModel.TestCase>());112 }113 }114 /// <inheritdoc/>115 public void Abort()116 {117 // This is no-op for the moment. There is no discovery abort message?118 }119 /// <inheritdoc/>...

Full Screen

Full Screen

ParallelDiscoveryEventsHandler.cs

Source:ParallelDiscoveryEventsHandler.cs Github

copy

Full Screen

...16 /// ParallelDiscoveryEventsHandler for handling the discovery events in case of parallel discovery17 /// </summary>18 internal class ParallelDiscoveryEventsHandler : ITestDiscoveryEventsHandler219 {20 private IProxyDiscoveryManager proxyDiscoveryManager;21 private ITestDiscoveryEventsHandler2 actualDiscoveryEventsHandler;22 private IParallelProxyDiscoveryManager parallelProxyDiscoveryManager;23 private ParallelDiscoveryDataAggregator discoveryDataAggregator;24 private IDataSerializer dataSerializer;25 private IRequestData requestData;26 public ParallelDiscoveryEventsHandler(IRequestData requestData,27 IProxyDiscoveryManager proxyDiscoveryManager,28 ITestDiscoveryEventsHandler2 actualDiscoveryEventsHandler,29 IParallelProxyDiscoveryManager parallelProxyDiscoveryManager,30 ParallelDiscoveryDataAggregator discoveryDataAggregator) :31 this(requestData, proxyDiscoveryManager, actualDiscoveryEventsHandler, parallelProxyDiscoveryManager, discoveryDataAggregator, JsonDataSerializer.Instance)32 {33 }34 internal ParallelDiscoveryEventsHandler(IRequestData requestData,35 IProxyDiscoveryManager proxyDiscoveryManager,36 ITestDiscoveryEventsHandler2 actualDiscoveryEventsHandler,37 IParallelProxyDiscoveryManager parallelProxyDiscoveryManager,38 ParallelDiscoveryDataAggregator discoveryDataAggregator,39 IDataSerializer dataSerializer)40 {41 this.proxyDiscoveryManager = proxyDiscoveryManager;42 this.actualDiscoveryEventsHandler = actualDiscoveryEventsHandler;43 this.parallelProxyDiscoveryManager = parallelProxyDiscoveryManager;44 this.discoveryDataAggregator = discoveryDataAggregator;45 this.dataSerializer = dataSerializer;46 this.requestData = requestData;47 }48 /// <inheritdoc/>49 public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable<TestCase> lastChunk)50 {51 var totalTests = discoveryCompleteEventArgs.TotalCount;52 var isAborted = discoveryCompleteEventArgs.IsAborted;53 // we get discovery complete events from each host process54 // so we cannot "complete" the actual operation until all sources are consumed55 // We should not block last chunk results while we aggregate overall discovery data56 if (lastChunk != null)57 {58 ConvertToRawMessageAndSend(MessageType.TestCasesFound, lastChunk);59 this.HandleDiscoveredTests(lastChunk);60 }61 // Aggregate for final discovery complete62 discoveryDataAggregator.Aggregate(totalTests, isAborted);63 // Aggregate Discovery Data Metrics64 discoveryDataAggregator.AggregateDiscoveryDataMetrics(discoveryCompleteEventArgs.Metrics);65 // Do not send TestDiscoveryComplete to actual test discovery handler66 // We need to see if there are still sources left - let the parallel manager decide67 var parallelDiscoveryComplete = this.parallelProxyDiscoveryManager.HandlePartialDiscoveryComplete(68 this.proxyDiscoveryManager,69 totalTests,70 null, // lastChunk should be null as we already sent this data above71 isAborted);72 if (parallelDiscoveryComplete)73 {74 // In case of sequential discovery - RawMessage would have contained a 'DiscoveryCompletePayload' object75 // To send a raw message - we need to create raw message from an aggregated payload object76 var testDiscoveryCompletePayload = new DiscoveryCompletePayload()77 {78 TotalTests = discoveryDataAggregator.TotalTests,79 IsAborted = discoveryDataAggregator.IsAborted,80 LastDiscoveredTests = null81 };...

Full Screen

Full Screen

ProxyBaseManagerTests.cs

Source:ProxyBaseManagerTests.cs Github

copy

Full Screen

...87 {88 this.mockChannel.Raise(c => c.MessageReceived += null, this.mockChannel.Object,89 new MessageReceivedEventArgs { Data = data });90 }91 protected ProxyDiscoveryManager GetProxyDiscoveryManager()92 {93 this.SetupAndInitializeTestRequestSender();94 var testDiscoveryManager = new ProxyDiscoveryManager(95 mockRequestData.Object,96 testRequestSender,97 mockTestHostManager.Object,98 mockDataSerializer.Object,99 this.mockFileHelper.Object);100 return testDiscoveryManager;101 }102 internal ProxyExecutionManager GetProxyExecutionManager()103 {104 this.SetupAndInitializeTestRequestSender();105 this.mockFileHelper.Setup(fh => fh.Exists(It.IsAny<string>())).Returns(true);106 var testExecutionManager = new ProxyExecutionManager(mockRequestData.Object, testRequestSender,107 mockTestHostManager.Object, mockDataSerializer.Object, this.mockFileHelper.Object);108 return testExecutionManager;...

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 var proxyDiscoveryManager = new ProxyDiscoveryManager();15 proxyDiscoveryManager.DiscoverTests(new List<string>() { "C:\\Test\\TestProject1.dll" }, null, new DiscoveryEventHandler());16 }17 }18 {19 public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)20 {21 foreach (var testCase in discoveredTestCases)22 {23 Console.WriteLine(testCase.DisplayName);24 }25 }26 public void HandleDiscoveryComplete(int totalTests, IEnumerable<TestCase> lastChunk)27 {28 Console.WriteLine("Total Tests: " + totalTests);29 }30 public void HandleLogMessage(TestMessageLevel level, string message)31 {32 Console.WriteLine(message);33 }34 }35}36using Microsoft.VisualStudio.TestPlatform.ObjectModel;37using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;38using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;39using Microsoft.VisualStudio.TestPlatform.TestHost;40using System;41using System.Collections.Generic;42using System.Linq;43using System.Text;44using System.Threading.Tasks;45{46 {47 static void Main(string[] args)48 {49 var requestSender = new TestRequestSender();50 requestSender.InitializeCommunication();51 requestSender.DiscoverTests(new List<string>() { "C:\\Test\\TestProject1.dll" }, null, new DiscoveryEventHandler());52 }53 }54 {55 public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)56 {57 foreach (var testCase in discoveredTestCases)58 {59 Console.WriteLine(testCase.DisplayName);60 }61 }62 public void HandleDiscoveryComplete(int totalTests, IEnumerable<TestCase> lastChunk)63 {64 Console.WriteLine("Total Tests: " + totalTests);65 }66 public void HandleLogMessage(TestMessageLevel level, string message)67 {68 Console.WriteLine(message);69 }70 }71}

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 ProxyDiscoveryManager proxyDiscoveryManager = new ProxyDiscoveryManager();12 Console.WriteLine(proxyDiscoveryManager.GetType().Assembly.GetName().Version);13 Console.ReadKey();14 }15 }16}

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 static void Main(string[] args)13 {14 var request = new DiscoveryRequest(@"C:\Users\user\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.dll", null, null, new TestPlatformOptions(), new TestLoggerEvents());15 var proxyDiscoveryManager = new ProxyDiscoveryManager();16 var discoveryEventHandler = new DiscoveryEventHandler();17 var discoveryResult = proxyDiscoveryManager.StartDiscovery(request, discoveryEventHandler);18 discoveryResult.Wait();19 Console.WriteLine("Press any key to exit");20 Console.ReadKey();21 }22 }23 {24 public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTests)25 {26 Console.WriteLine("No of discovered tests: " + discoveredTests.Count());27 }28 public void HandleDiscoveryComplete(int totalTests, IEnumerable<TestCase> lastChunk)29 {30 Console.WriteLine("Discovery Complete");31 }32 public void HandleLogMessage(TestMessageLevel level, string message)33 {34 Console.WriteLine("Log message: " + message);35 }36 public void HandleRawMessage(string rawMessage)37 {38 Console.WriteLine("Raw message: " + rawMessage);39 }40 public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)41 {42 Console.WriteLine("Test Run Stats Change");43 }44 }45}46using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine;47using Microsoft.VisualStudio.TestPlatform.ObjectModel;48using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;49using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55{56 {57 static void Main(string[] args)58 {59 var request = new DiscoveryRequest(@"C:\Users\user\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\ConsoleApp1.dll", null,

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1var proxyDiscoveryManager = new ProxyDiscoveryManager();2var proxyDiscoveryRequest = new ProxyDiscoveryRequest();3proxyDiscoveryRequest.DiscoveryCriteria = new DiscoveryCriteria(new List<string> { "1.cs" }, 1, string.Empty, null);4var proxyDiscoveryEventsHandler = new ProxyDiscoveryEventsHandler();5var discoveryResult = proxyDiscoveryManager.DiscoverTests(proxyDiscoveryRequest, proxyDiscoveryEventsHandler);6Console.WriteLine(discoveryResult.DiscoveryResultStats.TotalTests);7Console.WriteLine(discoveryResult.DiscoveryResultStats.TotalTests);8dotnet test 1.csproj --logger "trx;LogFileName=1.trx"

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 ProxyDiscoveryManager proxyDiscoveryManager = new ProxyDiscoveryManager();12 var proxySettings = proxyDiscoveryManager.GetProxySettings();13 Console.WriteLine("Proxy settings are as follows:");14 Console.WriteLine("Proxy address: " + proxySettings.ProxyAddress);15 Console.WriteLine("Proxy username: " + proxySettings.ProxyUsername);16 Console.WriteLine("Proxy password: " + proxySettings.ProxyPassword);17 Console.WriteLine("Proxy Bypass List: " + proxySettings.ProxyBypassList);18 Console.WriteLine("Proxy Bypass On Local: " + proxySettings.ProxyBypassOnLocal);19 Console.WriteLine("Proxy Use Default Credentials: " + proxySettings.ProxyUseDefaultCredentials);20 Console.WriteLine("Proxy Use System Default: " + proxySettings.ProxyUseSystemDefault);21 Console.WriteLine("Proxy Enabled: " + proxySettings.ProxyEnabled);22 Console.WriteLine("Proxy Auto Detect: " + proxySettings.ProxyAutoDetect);23 Console.WriteLine("Proxy Bypass On Local: " + proxySettings.ProxyBypassOnLocal);24 Console.WriteLine("Proxy Bypass List: " + proxySettings.ProxyBypassList);25 Console.ReadLine();26 }27 }28}

Full Screen

Full Screen

ProxyDiscoveryManager

Using AI Code Generation

copy

Full Screen

1var discoveryManager = new ProxyDiscoveryManager();2var discoveryCriteria = new DiscoveryCriteria(new List<string> { "1.cs" }, 1, null, null);3var discoveryEventHandler = new DiscoveryEventHandler();4discoveryManager.DiscoverTests(discoveryCriteria, discoveryEventHandler);5var testCases = discoveryEventHandler.DiscoveredTestCases;6var discoveryManager = new ProxyDiscoveryManager();7var discoveryCriteria = new DiscoveryCriteria(new List<string> { "2.cs" }, 1, null, null);8var discoveryEventHandler = new DiscoveryEventHandler();9discoveryManager.DiscoverTests(discoveryCriteria, discoveryEventHandler);10var testCases = discoveryEventHandler.DiscoveredTestCases;11var discoveryManager = new ProxyDiscoveryManager();12var discoveryCriteria = new DiscoveryCriteria(new List<string> { "3.cs" }, 1, null, null);13var discoveryEventHandler = new DiscoveryEventHandler();14discoveryManager.DiscoverTests(discoveryCriteria, discoveryEventHandler);15var testCases = discoveryEventHandler.DiscoveredTestCases;16var discoveryManager = new ProxyDiscoveryManager();17var discoveryCriteria = new DiscoveryCriteria(new List<string> { "4.cs" }, 1, null, null);18var discoveryEventHandler = new DiscoveryEventHandler();19discoveryManager.DiscoverTests(discoveryCriteria, discoveryEventHandler);20var testCases = discoveryEventHandler.DiscoveredTestCases;

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.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful