Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestSender.WaitForRequestHandlerConnection
ProxyOperationManagerTests.cs
Source:ProxyOperationManagerTests.cs
...41 "vstest.console process failed to connect to testhost process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout.";42 public ProxyOperationManagerTests()43 {44 this.mockRequestSender = new Mock<ITestRequestSender>();45 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(connectionTimeout, It.IsAny<CancellationToken>())).Returns(true);46 this.mockRequestData = new Mock<IRequestData>();47 this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(new Mock<IMetricsCollection>().Object);48 this.testOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object);49 }50 [TestCleanup]51 public void Cleanup()52 {53 Environment.SetEnvironmentVariable(EnvironmentHelper.VstestConnectionTimeout, string.Empty);54 }55 [TestMethod]56 public void SetupChannelShouldLaunchTestHost()57 {58 var expectedStartInfo = new TestProcessStartInfo();59 this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123);60 this.mockTestHostManager.Setup(61 th => th.GetTestHostProcessStartInfo(Enumerable.Empty<string>(), null, It.IsAny<TestRunnerConnectionInfo>()))62 .Returns(expectedStartInfo);63 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());64 this.mockTestHostManager.Verify(thl => thl.LaunchTestHostAsync(It.Is<TestProcessStartInfo>(si => si == expectedStartInfo), It.IsAny<CancellationToken>()), Times.Once);65 }66 [TestMethod]67 public void SetupChannelShouldCreateTimestampedLogFileForHost()68 {69 this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123);70 EqtTrace.InitializeTrace("log.txt", PlatformTraceLevel.Verbose);71 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());72 this.mockTestHostManager.Verify(73 th =>74 th.GetTestHostProcessStartInfo(75 It.IsAny<IEnumerable<string>>(),76 null,77 It.Is<TestRunnerConnectionInfo>(78 t => t.LogFile.Contains("log.host." + DateTime.Now.ToString("yy-MM-dd"))79 && t.LogFile.Contains("_" + Thread.CurrentThread.ManagedThreadId + ".txt"))));80#if NET45181 EqtTrace.TraceLevel = TraceLevel.Off;82#else83 EqtTrace.TraceLevel = PlatformTraceLevel.Off;84#endif85 }86 [TestMethod]87 public void SetupChannelShouldAddRunnerProcessIdForTestHost()88 {89 this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123);90 91 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());92 this.mockTestHostManager.Verify(93 th =>94 th.GetTestHostProcessStartInfo(95 It.IsAny<IEnumerable<string>>(),96 null,97 It.Is<TestRunnerConnectionInfo>(t => t.RunnerProcessId.Equals(Process.GetCurrentProcess().Id))));98 }99 [TestMethod]100 public void SetupChannelShouldAddCorrectTraceLevelForTestHost()101 {102#if NET451103 EqtTrace.TraceLevel = TraceLevel.Info;104#else105 EqtTrace.TraceLevel = PlatformTraceLevel.Info;106#endif107 this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123);108 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());109 this.mockTestHostManager.Verify(110 th =>111 th.GetTestHostProcessStartInfo(112 It.IsAny<IEnumerable<string>>(),113 null,114 It.Is<TestRunnerConnectionInfo>(t => t.TraceLevel == (int)PlatformTraceLevel.Info)));115 }116 [TestMethod]117 public void SetupChannelShouldSetupServerForCommunication()118 {119 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());120 this.mockRequestSender.Verify(s => s.InitializeCommunication(), Times.Once);121 }122 [TestMethod]123 public void SetupChannelShouldCallHostServerIfRunnerIsServer()124 {125 var connectionInfo = new TestHostConnectionInfo126 {127 Endpoint = IPAddress.Loopback + ":0",128 Role = ConnectionRole.Host,129 Transport = Transport.Sockets130 };131 ProtocolConfig protocolConfig = new ProtocolConfig { Version = 2 };132 var mockCommunicationServer = new Mock<ICommunicationEndPoint>();133 mockCommunicationServer.Setup(mc => mc.Start(connectionInfo.Endpoint)).Returns(IPAddress.Loopback + ":123").Callback(134 () => { mockCommunicationServer.Raise(s=>s.Connected += null, mockCommunicationServer.Object, new ConnectedEventArgs(this.mockChannel.Object)); });135 var testRequestSender = new TestRequestSender(mockCommunicationServer.Object, connectionInfo, mockDataSerializer.Object, protocolConfig, CLIENTPROCESSEXITWAIT);136 this.SetupChannelMessage(MessageType.VersionCheck, MessageType.VersionCheck, protocolConfig.Version);137 this.mockTestHostManager.Setup(thm => thm.GetTestHostConnectionInfo()).Returns(connectionInfo);138 var localTestOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, testRequestSender, this.mockTestHostManager.Object);139 localTestOperationManager.SetupChannel(Enumerable.Empty<string>());140 mockCommunicationServer.Verify(s => s.Start(IPAddress.Loopback.ToString()+":0"), Times.Once);141 }142 [TestMethod]143 public void SetupChannelShouldCallSetupClientIfRunnerIsClient()144 {145 var connectionInfo = new TestHostConnectionInfo146 {147 Endpoint = IPAddress.Loopback + ":124",148 Role = ConnectionRole.Host,149 Transport = Transport.Sockets150 };151 ProtocolConfig protocolConfig = new ProtocolConfig { Version = 2 };152 var mockCommunicationEndpoint = new Mock<ICommunicationEndPoint>();153 mockCommunicationEndpoint.Setup(mc => mc.Start(connectionInfo.Endpoint)).Returns(connectionInfo.Endpoint).Callback(() =>154 {155 mockCommunicationEndpoint.Raise(156 s => s.Connected += null,157 mockCommunicationEndpoint.Object,158 new ConnectedEventArgs(this.mockChannel.Object));159 });160 this.SetupChannelMessage(MessageType.VersionCheck, MessageType.VersionCheck, protocolConfig.Version);161 var testRequestSender = new TestRequestSender(mockCommunicationEndpoint.Object, connectionInfo, mockDataSerializer.Object, new ProtocolConfig { Version = 2 }, CLIENTPROCESSEXITWAIT);162 this.mockTestHostManager.Setup(thm => thm.GetTestHostConnectionInfo()).Returns(connectionInfo);163 var localTestOperationManager = new TestableProxyOperationManager(this.mockRequestData.Object, testRequestSender, this.mockTestHostManager.Object);164 localTestOperationManager.SetupChannel(Enumerable.Empty<string>());165 mockCommunicationEndpoint.Verify(s => s.Start(It.IsAny<string>()), Times.Once);166 }167 [TestMethod]168 public void SetupChannelShouldNotInitializeIfConnectionIsAlreadyInitialized()169 {170 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());171 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());172 this.mockRequestSender.Verify(s => s.InitializeCommunication(), Times.Once);173 }174 [TestMethod]175 public void SetupChannelShouldWaitForTestHostConnection()176 {177 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());178 this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>()), Times.Once);179 }180 [TestMethod]181 public void SetupChannelShouldNotWaitForTestHostConnectionIfConnectionIsInitialized()182 {183 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());184 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());185 this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>()), Times.Exactly(1));186 }187 [TestMethod]188 public void SetupChannelShouldHonorTimeOutSetByUser()189 {190 Environment.SetEnvironmentVariable(EnvironmentHelper.VstestConnectionTimeout, "100");191 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(100000, It.IsAny<CancellationToken>())).Returns(true);192 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());193 this.mockRequestSender.Verify(rs => rs.WaitForRequestHandlerConnection(100000, It.IsAny<CancellationToken>()), Times.Exactly(1));194 }195 [TestMethod]196 public void SetupChannelShouldThrowIfWaitForTestHostConnectionTimesOut()197 {198 SetupTestHostLaunched(true);199 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(false);200 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object);201 var message = Assert.ThrowsException<TestPlatformException>(() => operationManager.SetupChannel(Enumerable.Empty<string>())).Message;202 Assert.AreEqual(message, ProxyOperationManagerTests.TimoutErrorMessage);203 }204 [TestMethod]205 public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelled()206 {207 SetupTestHostLaunched(true);208 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(false);209 var cancellationTokenSource = new CancellationTokenSource();210 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource);211 cancellationTokenSource.Cancel();212 var message = Assert.ThrowsException<TestPlatformException>(() => operationManager.SetupChannel(Enumerable.Empty<string>())).Message;213 StringAssert.Equals("Cancelling the operation as requested.", message);214 }215 [TestMethod]216 public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelledDuringLaunchOfTestHost()217 {218 SetupTestHostLaunched(true);219 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(false);220 this.mockTestHostManager.Setup(rs => rs.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>())).Callback(() => Task.Run(() => { throw new OperationCanceledException(); }));221 var cancellationTokenSource = new CancellationTokenSource();222 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource);223 var message = Assert.ThrowsException<TestPlatformException>(() => operationManager.SetupChannel(Enumerable.Empty<string>())).Message;224 StringAssert.Equals("Cancelling the operation as requested.", message);225 }226 [TestMethod]227 public void SetupChannelShouldThrowTestPlatformExceptionIfRequestCancelledPostHostLaunchDuringWaitForHandlerConnection()228 {229 SetupTestHostLaunched(true);230 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(false);231 var cancellationTokenSource = new CancellationTokenSource();232 this.mockTestHostManager.Setup(rs => rs.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>())).Callback(() => cancellationTokenSource.Cancel());233 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, cancellationTokenSource);234 var message = Assert.ThrowsException<TestPlatformException>(() => operationManager.SetupChannel(Enumerable.Empty<string>())).Message;235 StringAssert.Equals("Cancelling the operation as requested.", message);236 }237 [TestMethod]238 public void SetupChannelShouldThrowIfLaunchTestHostFails()239 {240 SetupTestHostLaunched(false);241 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(true);242 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object);243 244 var message = Assert.ThrowsException<TestPlatformException>(() => operationManager.SetupChannel(Enumerable.Empty<string>())).Message;245 Assert.AreEqual(message, string.Format(CultureInfo.CurrentUICulture, Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources.Resources.InitializationFailed));246 }247 [TestMethod]248 public void SetupChannelShouldCheckVersionWithTestHost()249 {250 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());251 this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Once);252 }253 [TestMethod]254 public void SetupChannelShouldThrowExceptionIfVersionCheckFails()255 {256 // Make the version check fail257 this.mockRequestSender.Setup(rs => rs.CheckVersionWithTestHost()).Throws(new TestPlatformException("Version check failed"));258 Assert.ThrowsException<TestPlatformException>(() => this.testOperationManager.SetupChannel(Enumerable.Empty<string>()));259 }260 [TestMethod]261 public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredFalseShouldNotCheckVersionWithTestHost()262 {263 this.SetUpMocksForDotNetTestHost();264 var testHostManager = new TestableDotnetTestHostManager(false, this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockEnvironment.Object);265 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, testHostManager);266 operationManager.SetupChannel(Enumerable.Empty<string>());267 this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Never);268 }269 [TestMethod]270 public void SetupChannelForDotnetHostManagerWithIsVersionCheckRequiredTrueShouldCheckVersionWithTestHost()271 {272 this.SetUpMocksForDotNetTestHost();273 var testHostManager = new TestableDotnetTestHostManager(true, this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockEnvironment.Object);274 var operationManager = new TestableProxyOperationManager(this.mockRequestData.Object, this.mockRequestSender.Object, testHostManager);275 operationManager.SetupChannel(Enumerable.Empty<string>());276 this.mockRequestSender.Verify(rs => rs.CheckVersionWithTestHost(), Times.Once);277 }278 [TestMethod]279 public void CloseShouldEndSessionIfHostWasLaunched()280 {281 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(true);282 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());283 this.testOperationManager.Close();284 this.mockRequestSender.Verify(rs => rs.EndSession(), Times.Once);285 }286 [TestMethod]287 public void CloseShouldNotEndSessionIfHostLaucnhedFailed()288 {289 this.testOperationManager.Close();290 this.mockRequestSender.Verify(rs => rs.EndSession(), Times.Never);291 }292 [TestMethod]293 public void CloseShouldAlwaysCleanTestHost()294 {295 this.testOperationManager.Close();296 this.mockTestHostManager.Verify(th => th.CleanTestHostAsync(It.IsAny<CancellationToken>()), Times.Once);297 }298 [TestMethod]299 public void CloseShouldResetChannelInitialization()300 {301 this.SetupWaitForTestHostExit();302 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(true);303 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());304 this.testOperationManager.Close();305 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());306 this.mockTestHostManager.Verify(th => th.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>()), Times.Exactly(2));307 }308 [TestMethod]309 public void CloseShouldTerminateTesthostProcessIfWaitTimesout()310 {311 // Ensure testhost start returns a dummy process id312 this.mockRequestSender.Setup(rs => rs.WaitForRequestHandlerConnection(this.connectionTimeout, It.IsAny<CancellationToken>())).Returns(true);313 this.testOperationManager.SetupChannel(Enumerable.Empty<string>());314 this.testOperationManager.Close();315 this.mockTestHostManager.Verify(th => th.CleanTestHostAsync(It.IsAny<CancellationToken>()), Times.Once);316 }317 [TestMethod]318 public void CloseShouldNotThrowIfEndSessionFails()319 {320 this.mockRequestSender.Setup(rs => rs.EndSession()).Throws<Exception>();321 this.testOperationManager.Close();322 }323 private void SetupWaitForTestHostExit()324 {325 // Raise host exited when end session is called326 this.mockRequestSender.Setup(rs => rs.EndSession())...
ProxyDiscoveryManagerTests.cs
Source:ProxyDiscoveryManagerTests.cs
...75 public void DiscoverTestsShouldNotInitializeExtensionsOnNoExtensions()76 {77 // Make sure TestPlugincache is refreshed.78 TestPluginCache.Instance = null;79 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);80 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);81 this.mockRequestSender.Verify(s => s.InitializeDiscovery(It.IsAny<IEnumerable<string>>()), Times.Never);82 }83 [TestMethod]84 public void DiscoverTestsShouldNotInitializeExtensionsOnCommunicationFailure()85 {86 // Make sure TestPlugincache is refreshed.87 TestPluginCache.Instance = null;88 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(false);89 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();90 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventHandler.Object);91 this.mockRequestSender.Verify(s => s.InitializeExecution(It.IsAny<IEnumerable<string>>()), Times.Never);92 }93 [TestMethod]94 public void DiscoverTestsShouldAllowRuntimeProviderToUpdateAdapterSource()95 {96 // Make sure TestPlugincache is refreshed.97 TestPluginCache.Instance = null;98 this.mockTestHostManager.Setup(hm => hm.GetTestSources(this.discoveryCriteria.Sources)).Returns(this.discoveryCriteria.Sources);99 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);100 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();101 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventHandler.Object);102 this.mockTestHostManager.Verify(hm => hm.GetTestSources(this.discoveryCriteria.Sources), Times.Once);103 }104 [TestMethod]105 public void DiscoverTestsShouldUpdateTestSourcesIfSourceDiffersFromTestHostManagerSource()106 {107 var actualSources = new List<string> { "actualSource.dll" };108 var inputSource = new List<string> { "inputPackage.appxrecipe" };109 var localDiscoveryCriteria = new DiscoveryCriteria(inputSource, 1, string.Empty);110 this.mockTestHostManager.Setup(hm => hm.GetTestSources(localDiscoveryCriteria.Sources)).Returns(actualSources);111 this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(true));112 this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new List<string>());113 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);114 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();115 this.testDiscoveryManager.DiscoverTests(localDiscoveryCriteria, mockTestDiscoveryEventHandler.Object);116 Assert.IsNotNull(localDiscoveryCriteria.Package);117 // AdapterSourceMap should contain updated testSources.118 Assert.AreEqual(actualSources.FirstOrDefault(), localDiscoveryCriteria.AdapterSourceMap.FirstOrDefault().Value.FirstOrDefault());119 Assert.AreEqual(inputSource.FirstOrDefault(), localDiscoveryCriteria.Package);120 }121 [TestMethod]122 public void DiscoverTestsShouldNotUpdateTestSourcesIfSourceDoNotDifferFromTestHostManagerSource()123 {124 var actualSources = new List<string> { "actualSource.dll" };125 var inputSource = new List<string> { "actualSource.dll" };126 var localDiscoveryCriteria = new DiscoveryCriteria(inputSource, 1, string.Empty);127 this.mockTestHostManager.Setup(hm => hm.GetTestSources(localDiscoveryCriteria.Sources)).Returns(actualSources);128 this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(true));129 this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new List<string>());130 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);131 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();132 this.testDiscoveryManager.DiscoverTests(localDiscoveryCriteria, mockTestDiscoveryEventHandler.Object);133 Assert.IsNull(localDiscoveryCriteria.Package);134 // AdapterSourceMap should contain updated testSources.135 Assert.AreEqual(actualSources.FirstOrDefault(), localDiscoveryCriteria.AdapterSourceMap.FirstOrDefault().Value.FirstOrDefault());136 }137 [TestMethod]138 public void DiscoverTestsShouldNotSendDiscoveryRequestIfCommunicationFails()139 {140 this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>()))141 .Callback(142 () =>143 {144 this.mockTestHostManager.Raise(thm => thm.HostLaunched += null, new HostProviderEventArgs(string.Empty));145 })146 .Returns(Task.FromResult(false));147 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);148 // Make sure TestPlugincache is refreshed.149 TestPluginCache.Instance = null;150 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock<ITestDiscoveryEventsHandler2>();151 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventHandler.Object);152 this.mockRequestSender.Verify(s => s.DiscoverTests(It.IsAny<DiscoveryCriteria>(), It.IsAny<ITestDiscoveryEventsHandler2>()), Times.Never);153 }154 [TestMethod]155 public void DiscoverTestsShouldInitializeExtensionsIfPresent()156 {157 // Make sure TestPlugincache is refreshed.158 TestPluginCache.Instance = null;159 try160 {161 var extensions = new[] { "c:\\e1.dll", "c:\\e2.dll" };162 // Setup Mocks.163 TestPluginCacheTests.SetupMockAdditionalPathExtensions(extensions);164 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);165 this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new[] { "c:\\e1.dll", "c:\\e2.dll" });166 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);167 // Also verify that we have waited for client connection.168 this.mockRequestSender.Verify(s => s.InitializeDiscovery(extensions), Times.Once);169 }170 finally171 {172 TestPluginCache.Instance = null;173 }174 }175 [TestMethod]176 public void DiscoverTestsShouldQueryTestHostManagerForExtensions()177 {178 TestPluginCache.Instance = null;179 try180 {181 TestPluginCacheTests.SetupMockAdditionalPathExtensions(new[] { "c:\\e1.dll" });182 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);183 this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), It.IsAny<IEnumerable<string>>())).Returns(new[] { "he1.dll", "c:\\e1.dll" });184 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);185 this.mockRequestSender.Verify(s => s.InitializeDiscovery(new[] { "he1.dll", "c:\\e1.dll" }), Times.Once);186 }187 finally188 {189 TestPluginCache.Instance = null;190 }191 }192 [TestMethod]193 public void DiscoverTestsShouldPassAdapterToTestHostManagerFromTestPluginCacheExtensions()194 {195 // We are updating extension with testadapter only to make it easy to test.196 // In product code it filter out testadapter from extension197 TestPluginCache.Instance.UpdateExtensions(new List<string> { "abc.TestAdapter.dll", "xyz.TestAdapter.dll" }, false);198 try199 {200 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);201 var expectedResult = TestPluginCache.Instance.GetExtensionPaths(string.Empty);202 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);203 this.mockTestHostManager.Verify(th => th.GetTestPlatformExtensions(It.IsAny<IEnumerable<string>>(), expectedResult), Times.Once);204 }205 finally206 {207 TestPluginCache.Instance = null;208 }209 }210 [TestMethod]211 public void DiscoverTestsShouldNotIntializeTestHost()212 {213 // Setup mocks.214 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);215 // Act.216 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);217 this.mockRequestSender.Verify(s => s.InitializeCommunication(), Times.Once);218 this.mockTestHostManager.Verify(thl => thl.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>()), Times.Once);219 }220 [TestMethod]221 public void DiscoverTestsShouldCatchExceptionAndCallHandleDiscoveryComplete()222 {223 // Setup mocks.224 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock<ITestDiscoveryEventsHandler2>();225 this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny<TestProcessStartInfo>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(false));226 // Act.227 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object);228 // Verify229 mockTestDiscoveryEventsHandler.Verify(s => s.HandleDiscoveryComplete(It.IsAny<DiscoveryCompleteEventArgs>(), It.IsAny<IEnumerable<TestCase>>()));230 mockTestDiscoveryEventsHandler.Verify(s => s.HandleRawMessage(It.IsAny<string>()));231 mockTestDiscoveryEventsHandler.Verify(s => s.HandleLogMessage(TestMessageLevel.Error, It.IsAny<string>()));232 }233 [TestMethod]234 public void DiscoverTestsShouldInitiateServerDiscoveryLoop()235 {236 // Setup mocks.237 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);238 // Act.239 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, null);240 // Assert.241 this.mockRequestSender.Verify(s => s.DiscoverTests(It.IsAny<DiscoveryCriteria>(), this.testDiscoveryManager), Times.Once);242 }243 [TestMethod]244 public void DiscoverTestsCloseTestHostIfRawMessageIsOfTypeDiscoveryComplete()245 {246 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock<ITestDiscoveryEventsHandler2>();247 this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(It.IsAny<string>())).Returns( () =>248 {249 var message = new Message250 {251 MessageType = MessageType.DiscoveryComplete252 };253 return message;254 });255 // Act.256 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object);257 // Verify258 this.mockTestHostManager.Verify(mthm => mthm.CleanTestHostAsync(It.IsAny<CancellationToken>()), Times.Once);259 }260 [TestMethod]261 public void DiscoverTestsShouldNotCloseTestHostIfRawMessageIsNotOfTypeDiscoveryComplete()262 {263 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock<ITestDiscoveryEventsHandler2>();264 this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(It.IsAny<string>())).Returns(() =>265 {266 var message = new Message267 {268 MessageType = MessageType.DiscoveryInitialize269 };270 return message;271 });272 // Act.273 this.testDiscoveryManager.DiscoverTests(this.discoveryCriteria, mockTestDiscoveryEventsHandler.Object);274 // Verify275 this.mockTestHostManager.Verify(mthm => mthm.CleanTestHostAsync(It.IsAny<CancellationToken>()), Times.Never);276 }277 [TestMethod]278 public void DiscoveryManagerShouldPassOnHandleDiscoveredTests()279 {280 Mock<ITestDiscoveryEventsHandler2> mockTestDiscoveryEventsHandler = new Mock<ITestDiscoveryEventsHandler2>();281 this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny<int>())).Returns(true);282 var testCases = new List<TestCase>() { new TestCase("x.y.z", new Uri("x://y"), "x.dll") };283 var rawMessage = "OnDiscoveredTests";284 var message = new Message() { MessageType = MessageType.TestCasesFound, Payload = null };285 this.SetupReceiveRawMessageAsyncAndDeserializeMessageAndInitialize(rawMessage, message);286 var completePayload = new DiscoveryCompletePayload()287 {288 IsAborted = false,289 LastDiscoveredTests = null,290 TotalTests = 1291 };292 var completeMessage = new Message() { MessageType = MessageType.DiscoveryComplete, Payload = null };293 mockTestDiscoveryEventsHandler.Setup(mh => mh.HandleDiscoveredTests(It.IsAny<IEnumerable<TestCase>>())).Callback(294 () =>295 {...
WaitForRequestHandlerConnection
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;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 testRequestSender = new TestRequestSender();15 testRequestSender.InitializeCommunication();16 testRequestSender.WaitForRequestHandlerConnection(1000);17 }18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;26using Microsoft.VisualStudio.TestPlatform.ObjectModel;27using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;28using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;29{30 {31 static void Main(string[] args)32 {33 var testRequestSender = new TestRequestSender();34 testRequestSender.InitializeCommunication();35 }36 }37}38using System;39using System.Collections.Generic;40using System.Linq;41using System.Text;42using System.Threading.Tasks;43using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;44using Microsoft.VisualStudio.TestPlatform.ObjectModel;45using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;46using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;47{48 {49 static void Main(string[] args)50 {51 var testRequestSender = new TestRequestSender();52 testRequestSender.InitializeCommunication();53 }54 }55}56using System;57using System.Collections.Generic;58using System.Linq;59using System.Text;60using System.Threading.Tasks;61using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;62using Microsoft.VisualStudio.TestPlatform.ObjectModel;63using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;64using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;65{66 {67 static void Main(string[] args)68 {69 var testRequestSender = new TestRequestSender();70 testRequestSender.InitializeCommunication();71 }72 }73}
WaitForRequestHandlerConnection
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;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 testRequestSender = new TestRequestSender();15 testRequestSender.WaitForRequestHandlerConnection(10000);16 Console.WriteLine("Connected");17 testRequestSender.InitializeCommunication();18 Console.WriteLine("Initialized");19 testRequestSender.StartTestRun(new TestRunCriteria(new List<string> { @"C:\Users\test\source\repos\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll" }, 1, false, new TestPlatformOptions(), new TestRunCriteria.TestHostLaunc
WaitForRequestHandlerConnection
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;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 TestRequestSender testRequestSender = new TestRequestSender();15 testRequestSender.WaitForRequestHandlerConnection(10000);16 Dictionary<string, string> runSettings = new Dictionary<string, string>();17 runSettings.Add("RunConfiguration.TargetPlatform", "x64");18 runSettings.Add("RunConfiguration.TargetFrameworkVersion", "Framework45");19 TestRunCriteria testRunCriteria = new TestRunCriteria(new List<string>() { "1.dll" }, 1, false, new TestPlatformOptions(), runSettings);20 testRequestSender.StartTestRun(testRunCriteria, new TestRunEventsHandler());21 testRequestSender.WaitForEventCompletion();22 Console.WriteLine("Test run completed");23 Console.ReadLine();24 }25 }26 {27 public void HandleLogMessage(TestMessageLevel level, string message)28 {29 Console.WriteLine(message);30 }31 public void HandleRawMessage(string rawMessage)32 {33 Console.WriteLine(rawMessage);34 }35 public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, CancellationToken cancellationToken, ITestRunStatisticsAggregator runStatsAggregator)36 {37 Console.WriteLine("Test run complete");38 }39 public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)40 {41 Console.WriteLine("Test run stats change");42 }43 }44}45using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;46using Microsoft.VisualStudio.TestPlatform.ObjectModel;47using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;48using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54{55 {56 static void Main(string[] args)57 {
WaitForRequestHandlerConnection
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using System.Threading;7using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;8{9 {10 static void Main(string[] args)11 {12 TestRequestSender testRequestSender = new TestRequestSender();13 testRequestSender.WaitForRequestHandlerConnection(1000);14 }15 }16}17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22using System.Threading;23using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;24{25 {26 static void Main(string[] args)27 {28 TestRequestSender testRequestSender = new TestRequestSender();29 testRequestSender.WaitForRequestHandlerConnection(1000);30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using System.Threading;39using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;40{41 {42 static void Main(string[] args)43 {44 TestRequestSender testRequestSender = new TestRequestSender();45 testRequestSender.WaitForRequestHandlerConnection(1000);46 }47 }48}49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54using System.Threading;55using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;56{57 {58 static void Main(string[] args)59 {60 TestRequestSender testRequestSender = new TestRequestSender();61 testRequestSender.WaitForRequestHandlerConnection(1000);62 }63 }64}65using System;66using System.Collections.Generic;67using System.Linq;68using System.Text;69using System.Threading.Tasks;70using System.Threading;71using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
WaitForRequestHandlerConnection
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;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 TestRequestSender testRequestSender = new TestRequestSender();12 testRequestSender.WaitForRequestHandlerConnection(10);13 }14 }15}
WaitForRequestHandlerConnection
Using AI Code Generation
1var testRequestSender = new TestRequestSender();2testRequestSender.WaitForRequestHandlerConnection(10000);3var testRequestSender = new TestRequestSender();4testRequestSender.WaitForRequestHandlerConnection(10000);5var testRequestSender = new TestRequestSender();6testRequestSender.WaitForRequestHandlerConnection(10000);7var testRequestSender = new TestRequestSender();8testRequestSender.WaitForRequestHandlerConnection(10000);9var testRequestSender = new TestRequestSender();10testRequestSender.WaitForRequestHandlerConnection(10000);11var testRequestSender = new TestRequestSender();12testRequestSender.WaitForRequestHandlerConnection(10000);13var testRequestSender = new TestRequestSender();14testRequestSender.WaitForRequestHandlerConnection(10000);15var testRequestSender = new TestRequestSender();16testRequestSender.WaitForRequestHandlerConnection(10000);
WaitForRequestHandlerConnection
Using AI Code Generation
1var testRequestSender = new TestRequestSender();2testRequestSender.WaitForRequestHandlerConnection(10000);3var testRequestSender = new TestRequestSender();4testRequestSender.WaitForRequestHandlerConnection(10000);5var testRequestSender = new TestRequestSender();6testRequestSender.WaitForRequestHandlerConnection(10000);7var testRequestSender = new TestRequestSender();8testRequestSender.WaitForRequestHandlerConnection(10000);9var testRequestSender = new TestRequestSender();10testRequestSender.WaitForRequestHandlerConnection(10000);11var testRequestSender = new TestRequestSender();12testRequestSender.WaitForRequestHandlerConnection(10000);13var testRequestSender = new TestRequestSender();14testRequestSender.WaitForRequestHandlerConnection(10000);15var testRequestSender = new TestRequestSender();16testRequestSender.WaitForRequestHandlerConnection(10000);
WaitForRequestHandlerConnection
Using AI Code Generation
1{2 {3 static void Main(string[] args)4 {5 TestRequestSender testRequestSender = new TestRequestSender();6 testRequestSender.WaitForRequestHandlerConnection(10);7 }8 }9}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!