Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestSender.StartTestRun
TestRequestSenderTests.cs
Source:TestRequestSenderTests.cs
...134 [TestMethod]135 public void EndSessionShouldNotSendSessionEndMessageIfTestHostProcessExited()136 {137 this.SetupFakeCommunicationChannel();138 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);139 this.testRequestSender.OnClientProcessExit("Dummy Message");140 this.testRequestSender.EndSession();141 this.mockDataSerializer.Verify(ds => ds.SerializeMessage(MessageType.SessionEnd), Times.Once);142 }143 [TestMethod]144 public void EndSessionShouldNotSendTestRunCancelMessageIfClientDisconnected()145 {146 this.SetupFakeCommunicationChannel();147 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);148 this.RaiseClientDisconnectedEvent();149 this.testRequestSender.SendTestRunCancel();150 this.mockChannel.Verify(mockChannel => mockChannel.Send(MessageType.CancelTestRun), Times.Never);151 }152 [TestMethod]153 public void EndSessionShouldNotSendTestRunAbortMessageIfClientDisconnected()154 {155 this.SetupFakeCommunicationChannel();156 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);157 this.RaiseClientDisconnectedEvent();158 this.testRequestSender.SendTestRunAbort();159 this.mockChannel.Verify(mockChannel => mockChannel.Send(MessageType.CancelTestRun), Times.Never);160 }161 [DataTestMethod]162 [DataRow("")]163 [DataRow(" ")]164 [DataRow(null)]165 public void OnClientProcessExitShouldSendErrorMessageIfStdErrIsEmpty(string stderr)166 {167 this.SetupFakeCommunicationChannel();168 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);169 this.testRequestSender.OnClientProcessExit(stderr);170 var expectedErrorMessage = "Reason: Test host process crashed";171 this.RaiseClientDisconnectedEvent();172 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.EndsWith(expectedErrorMessage))), Times.Once);173 }174 [TestMethod]175 public void OnClientProcessExitShouldNotSendErrorMessageIfOperationNotStarted()176 {177 this.SetupFakeCommunicationChannel();178 this.testRequestSender.OnClientProcessExit("Dummy Stderr");179 this.RaiseClientDisconnectedEvent();180 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains("Dummy Stderr"))), Times.Never);181 }182 [TestMethod]183 public void OnClientProcessExitShouldNotSendRawMessageIfOperationNotStarted()184 {185 this.SetupFakeCommunicationChannel();186 this.testRequestSender.OnClientProcessExit("Dummy Stderr");187 this.RaiseClientDisconnectedEvent();188 this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.TestMessage, It.Is<TestMessagePayload>(p => p.Message.Contains("Dummy Stderr"))), Times.Never);189 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage(It.IsAny<string>()), Times.Never);190 }191 #region Version Check Tests192 [TestMethod]193 public void CheckVersionWithTestHostShouldSendHighestSupportedVersion()194 {195 this.SetupDeserializeMessage(MessageType.VersionCheck, 99);196 this.SetupRaiseMessageReceivedOnCheckVersion();197 this.SetupFakeCommunicationChannel();198 this.testRequestSender.CheckVersionWithTestHost();199 this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.VersionCheck, DUMMYPROTOCOLVERSION), Times.Once);200 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);201 }202 [TestMethod]203 public void CheckVersionWithTestHostShouldThrowIfTestHostVersionDoesNotMatch()204 {205 this.SetupDeserializeMessage(MessageType.ProtocolError, string.Empty);206 this.SetupRaiseMessageReceivedOnCheckVersion();207 this.SetupFakeCommunicationChannel();208 Assert.ThrowsException<TestPlatformException>(() => this.testRequestSender.CheckVersionWithTestHost());209 }210 [TestMethod]211 public void CheckVersionWithTestHostShouldThrowIfUnexpectedResponseIsReceived()212 {213 this.SetupDeserializeMessage(MessageType.TestCasesFound, string.Empty);214 this.SetupRaiseMessageReceivedOnCheckVersion();215 this.SetupFakeCommunicationChannel();216 Assert.ThrowsException<TestPlatformException>(() => this.testRequestSender.CheckVersionWithTestHost());217 }218 [TestMethod]219 public void CheckVersionWithTestHostShouldThrowIfProtocolNegotiationTimeouts()220 {221 Environment.SetEnvironmentVariable(EnvironmentHelper.VstestConnectionTimeout, "0");222 this.SetupFakeCommunicationChannel();223 var message = Assert.ThrowsException<TestPlatformException>(() => this.testRequestSender.CheckVersionWithTestHost()).Message;224 Assert.AreEqual(message, TestRequestSenderTests.TimoutErrorMessage);225 }226 #endregion227 #region Discovery Protocol Tests228 [TestMethod]229 public void InitializeDiscoveryShouldSendCommunicationMessageWithCorrectParameters()230 {231 this.SetupFakeCommunicationChannel();232 this.testRequestSender.InitializeDiscovery(this.pathToAdditionalExtensions);233 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.DiscoveryInitialize, this.pathToAdditionalExtensions, 1), Times.Once);234 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);235 }236 [TestMethod]237 public void InitializeDiscoveryShouldSendCommunicationMessageWithCorrectParametersWithVersion()238 {239 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);240 this.testRequestSender.InitializeDiscovery(this.pathToAdditionalExtensions);241 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.DiscoveryInitialize, this.pathToAdditionalExtensions, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once);242 }243 [TestMethod]244 public void DiscoverTestsShouldSendStartDiscoveryMessageOnChannel()245 {246 this.SetupFakeCommunicationChannel();247 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);248 this.mockDataSerializer.Verify(249 s => s.SerializePayload(MessageType.StartDiscovery, It.IsAny<DiscoveryCriteria>(), DEFAULTPROTOCOLVERSION),250 Times.Once);251 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);252 }253 [TestMethod]254 public void DiscoverTestsShouldSendStartDiscoveryMessageOnChannelWithVersion()255 {256 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);257 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);258 this.mockDataSerializer.Verify(259 s => s.SerializePayload(MessageType.StartDiscovery, It.IsAny<DiscoveryCriteria>(), DUMMYNEGOTIATEDPROTOCOLVERSION),260 Times.Once);261 }262 [TestMethod]263 public void DiscoverTestsShouldNotifyRawMessageOnMessageReceived()264 {265 this.SetupDeserializeMessage(MessageType.TestMessage, new TestMessagePayload());266 this.SetupFakeCommunicationChannel();267 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);268 this.RaiseMessageReceivedEvent();269 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleRawMessage("DummyData"), Times.Once);270 }271 [TestMethod]272 public void DiscoverTestsShouldNotifyDiscoveredTestsOnTestCasesFoundMessageReceived()273 {274 this.SetupDeserializeMessage<IEnumerable<TestCase>>(MessageType.TestCasesFound, new TestCase[2]);275 this.SetupFakeCommunicationChannel();276 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);277 this.RaiseMessageReceivedEvent();278 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveredTests(It.Is<IEnumerable<TestCase>>(t => t.Count() == 2)));279 }280 [TestMethod]281 public void DiscoverTestsShouldNotifyDiscoveryCompleteOnCompleteMessageReceived()282 {283 var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false };284 this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload);285 this.SetupFakeCommunicationChannel();286 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);287 this.RaiseMessageReceivedEvent();288 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(It.Is<DiscoveryCompleteEventArgs>(dc => dc.IsAborted == false && dc.TotalCount == 10), null));289 }290 [TestMethod]291 public void DiscoverTestsShouldStopServerOnCompleteMessageReceived()292 {293 var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false };294 this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload);295 this.SetupFakeCommunicationChannel();296 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);297 this.RaiseMessageReceivedEvent();298 this.mockServer.Verify(ms => ms.Stop());299 }300 [TestMethod]301 public void DiscoverTestShouldNotifyLogMessageOnTestMessageReceived()302 {303 var message = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = "Message1" };304 this.SetupDeserializeMessage(MessageType.TestMessage, message);305 this.SetupFakeCommunicationChannel();306 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);307 this.RaiseMessageReceivedEvent();308 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Message1"));309 }310 [TestMethod]311 public void DiscoverTestShouldNotifyLogMessageIfExceptionThrownOnMessageReceived()312 {313 this.SetupExceptionOnMessageReceived();314 this.SetupFakeCommunicationChannel();315 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);316 this.RaiseMessageReceivedEvent();317 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains("Dummy Message"))));318 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleRawMessage("SerializedMessage"), Times.Once);319 }320 [TestMethod]321 public void DiscoverTestShouldNotifyDiscoveryCompleteIfExceptionThrownOnMessageReceived()322 {323 this.SetupExceptionOnMessageReceived();324 this.SetupFakeCommunicationChannel();325 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);326 this.RaiseMessageReceivedEvent();327 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(It.Is<DiscoveryCompleteEventArgs>(dc => dc.IsAborted == true && dc.TotalCount == -1), null));328 }329 [TestMethod]330 public void DiscoverTestsShouldNotAbortDiscoveryIfClientDisconnectedAndOperationIsComplete()331 {332 var completePayload = new DiscoveryCompletePayload { TotalTests = 10, IsAborted = false };333 this.SetupDeserializeMessage(MessageType.DiscoveryComplete, completePayload);334 this.SetupFakeCommunicationChannel();335 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);336 this.RaiseMessageReceivedEvent(); // Raise discovery complete337 this.RaiseClientDisconnectedEvent();338 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.IsAny<string>()), Times.Never);339 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(new DiscoveryCompleteEventArgs(-1, true), null), Times.Never);340 }341 [TestMethod]342 public void DiscoverTestShouldNotifyLogMessageIfClientDisconnected()343 {344 // Expect default error message since we've not set any client exit message345 var expectedErrorMessage = "Reason: Unable to communicate";346 this.SetupFakeCommunicationChannel();347 this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.TestMessage, It.Is<TestMessagePayload>(p => p.Message.Contains(expectedErrorMessage))))348 .Returns("Serialized error");349 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);350 this.RaiseClientDisconnectedEvent();351 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains(expectedErrorMessage))));352 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleRawMessage(It.Is<string>(s => !string.IsNullOrEmpty(s) && s.Equals("Serialized error"))), Times.Once);353 }354 [TestMethod]355 public void DiscoverTestShouldNotifyLogMessageIfClientDisconnectedWithClientExit()356 {357 this.SetupFakeCommunicationChannel();358 this.mockDataSerializer.Setup(ds => ds.SerializePayload(MessageType.TestMessage, It.Is<TestMessagePayload>(p => p.Message.Contains("Dummy Stderr"))))359 .Returns("Serialized Stderr");360 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);361 this.testRequestSender.OnClientProcessExit("Dummy Stderr");362 this.RaiseClientDisconnectedEvent();363 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains("Dummy Stderr"))), Times.Once);364 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleRawMessage(It.Is<string>(s => !string.IsNullOrEmpty(s) && s.Equals("Serialized Stderr"))), Times.Once);365 }366 [TestMethod]367 public void DiscoverTestShouldNotifyDiscoveryCompleteIfClientDisconnected()368 {369 this.SetupFakeCommunicationChannel();370 this.testRequestSender.DiscoverTests(new DiscoveryCriteria(), this.mockDiscoveryEventsHandler.Object);371 this.RaiseClientDisconnectedEvent();372 this.mockDiscoveryEventsHandler.Verify(eh => eh.HandleDiscoveryComplete(It.Is<DiscoveryCompleteEventArgs>(dc => dc.IsAborted == true && dc.TotalCount == -1), null));373 }374 #endregion375 #region Execution Protocol Tests376 [TestMethod]377 public void InitializeExecutionShouldSendCommunicationMessageWithCorrectParameters()378 {379 this.SetupFakeCommunicationChannel();380 this.testRequestSender.InitializeExecution(this.pathToAdditionalExtensions);381 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.ExecutionInitialize, this.pathToAdditionalExtensions, 1), Times.Once);382 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);383 }384 [TestMethod]385 public void InitializeExecutionShouldSendCommunicationMessageWithCorrectParametersWithVersion()386 {387 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);388 this.testRequestSender.InitializeExecution(this.pathToAdditionalExtensions);389 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.ExecutionInitialize, this.pathToAdditionalExtensions, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once);390 }391 [TestMethod]392 public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannel()393 {394 this.SetupFakeCommunicationChannel();395 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);396 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DEFAULTPROTOCOLVERSION), Times.Once);397 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);398 }399 [TestMethod]400 public void StartTestRunShouldSendStartTestExecutionWithSourcesOnChannelWithVersion()401 {402 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);403 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);404 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithSources, this.testRunCriteriaWithSources, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once);405 }406 [TestMethod]407 public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannel()408 {409 var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null);410 this.SetupFakeCommunicationChannel();411 this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object);412 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DEFAULTPROTOCOLVERSION), Times.Once);413 this.mockChannel.Verify(mc => mc.Send(It.IsAny<string>()), Times.Once);414 }415 [TestMethod]416 public void StartTestRunWithTestsShouldSendStartTestExecutionWithTestsOnChannelWithVersion()417 {418 var runCriteria = new TestRunCriteriaWithTests(new TestCase[2], "runsettings", null, null);419 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);420 this.testRequestSender.StartTestRun(runCriteria, this.mockExecutionEventsHandler.Object);421 this.mockDataSerializer.Verify(d => d.SerializePayload(MessageType.StartTestExecutionWithTests, runCriteria, DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once);422 }423 [TestMethod]424 public void StartTestRunShouldNotifyRawMessageOnMessageReceived()425 {426 this.SetupDeserializeMessage(MessageType.TestMessage, new TestMessagePayload());427 this.SetupFakeCommunicationChannel();428 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);429 this.RaiseMessageReceivedEvent();430 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("DummyData"), Times.Once);431 }432 [TestMethod]433 public void StartTestRunShouldNotifyTestRunStatsChangeOnRunStatsMessageReceived()434 {435 var testRunChangedArgs = new TestRunChangedEventArgs(436 null,437 new Microsoft.VisualStudio.TestPlatform.ObjectModel.TestResult[2],438 new TestCase[2]);439 this.SetupDeserializeMessage(MessageType.TestRunStatsChange, testRunChangedArgs);440 this.SetupFakeCommunicationChannel();441 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);442 this.RaiseMessageReceivedEvent();443 this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunStatsChange(testRunChangedArgs), Times.Once);444 }445 [TestMethod]446 public void StartTestRunShouldNotifyExecutionCompleteOnRunCompleteMessageReceived()447 {448 var testRunCompletePayload = new TestRunCompletePayload449 {450 TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.MaxValue),451 LastRunTests = new TestRunChangedEventArgs(null, null, null),452 RunAttachments = new List<AttachmentSet>()453 };454 this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload);455 this.SetupFakeCommunicationChannel();456 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);457 this.RaiseMessageReceivedEvent();458 this.mockExecutionEventsHandler.Verify(459 eh => eh.HandleTestRunComplete(460 testRunCompletePayload.TestRunCompleteArgs,461 testRunCompletePayload.LastRunTests,462 testRunCompletePayload.RunAttachments,463 It.IsAny<ICollection<string>>()),464 Times.Once);465 }466 [TestMethod]467 public void StartTestRunShouldStopServerOnRunCompleteMessageReceived()468 {469 var testRunCompletePayload = new TestRunCompletePayload470 {471 TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.MaxValue),472 LastRunTests = new TestRunChangedEventArgs(null, null, null),473 RunAttachments = new List<AttachmentSet>()474 };475 this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload);476 this.SetupFakeCommunicationChannel();477 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);478 this.RaiseMessageReceivedEvent();479 this.mockServer.Verify(ms => ms.Stop());480 }481 [TestMethod]482 public void StartTestRunShouldNotifyLogMessageOnTestMessageReceived()483 {484 var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = "Dummy" };485 this.SetupDeserializeMessage(MessageType.TestMessage, testMessagePayload);486 this.SetupFakeCommunicationChannel();487 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);488 this.RaiseMessageReceivedEvent();489 this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, "Dummy"), Times.Once);490 }491 [TestMethod]492 public void StartTestRunShouldNotifyLaunchWithDebuggerOnMessageReceived()493 {494 var launchMessagePayload = new TestProcessStartInfo();495 this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload);496 this.SetupFakeCommunicationChannel();497 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);498 this.RaiseMessageReceivedEvent();499 this.mockExecutionEventsHandler.Verify(eh => eh.LaunchProcessWithDebuggerAttached(launchMessagePayload), Times.Once);500 }501 [TestMethod]502 public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceived()503 {504 var launchMessagePayload = new TestProcessStartInfo();505 this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload);506 this.SetupFakeCommunicationChannel();507 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);508 this.RaiseMessageReceivedEvent();509 this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny<int>(), 1), Times.Once);510 this.mockChannel.Verify(c => c.Send(It.IsAny<string>()), Times.AtLeastOnce);511 }512 [TestMethod]513 public void StartTestRunShouldSendLaunchDebuggerAttachedCallbackOnMessageReceivedWithVersion()514 {515 var launchMessagePayload = new TestProcessStartInfo();516 this.SetupFakeChannelWithVersionNegotiation(DUMMYNEGOTIATEDPROTOCOLVERSION);517 this.SetupDeserializeMessage(MessageType.LaunchAdapterProcessWithDebuggerAttached, launchMessagePayload);518 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);519 this.RaiseMessageReceivedEvent();520 this.mockDataSerializer.Verify(ds => ds.SerializePayload(MessageType.LaunchAdapterProcessWithDebuggerAttachedCallback, It.IsAny<int>(), DUMMYNEGOTIATEDPROTOCOLVERSION), Times.Once);521 }522 [TestMethod]523 public void StartTestRunShouldNotifyLogMessageIfExceptionIsThrownOnMessageReceived()524 {525 this.SetupExceptionOnMessageReceived();526 this.SetupFakeCommunicationChannel();527 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);528 this.RaiseMessageReceivedEvent();529 this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains("Dummy Message"))), Times.Once);530 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("SerializedMessage"), Times.Once);531 }532 [TestMethod]533 public void StartTestRunShouldNotifyExecutionCompleteIfExceptionIsThrownOnMessageReceived()534 {535 this.SetupExceptionOnMessageReceived();536 this.SetupFakeCommunicationChannel();537 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);538 this.RaiseMessageReceivedEvent();539 this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunComplete(It.Is<TestRunCompleteEventArgs>(t => t.IsAborted), null, null, null), Times.Once);540 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("SerializedAbortedPayload"), Times.Once);541 }542 [TestMethod]543 public void StartTestRunShouldNotNotifyExecutionCompleteIfClientDisconnectedAndOperationComplete()544 {545 var testRunCompletePayload = new TestRunCompletePayload546 {547 TestRunCompleteArgs = new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.MaxValue),548 LastRunTests = new TestRunChangedEventArgs(null, null, null),549 RunAttachments = new List<AttachmentSet>()550 };551 this.SetupDeserializeMessage(MessageType.ExecutionComplete, testRunCompletePayload);552 this.SetupFakeCommunicationChannel();553 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);554 this.RaiseMessageReceivedEvent(); // Raise test run complete555 this.RaiseClientDisconnectedEvent();556 this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunComplete(It.Is<TestRunCompleteEventArgs>(t => t.IsAborted), null, null, null), Times.Never);557 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("SerializedAbortedPayload"), Times.Never);558 }559 [TestMethod]560 public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnected()561 {562 this.SetupFakeCommunicationChannel();563 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);564 this.RaiseClientDisconnectedEvent();565 // Expect default error message since we've not set any client exit message566 var expectedErrorMessage = "Reason: Unable to communicate";567 this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains(expectedErrorMessage))), Times.Once);568 }569 [TestMethod]570 public void StartTestRunShouldNotifyErrorLogMessageIfClientDisconnectedWithClientExit()571 {572 this.SetupFakeCommunicationChannel();573 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);574 this.testRequestSender.OnClientProcessExit("Dummy Stderr");575 this.RaiseClientDisconnectedEvent();576 var expectedErrorMessage = "Reason: Test host process crashed : Dummy Stderr";577 this.mockExecutionEventsHandler.Verify(eh => eh.HandleLogMessage(TestMessageLevel.Error, It.Is<string>(s => s.Contains(expectedErrorMessage))), Times.Once);578 }579 [TestMethod]580 public void StartTestRunShouldNotifyExecutionCompleteIfClientDisconnected()581 {582 this.SetupOperationAbortedPayload();583 this.SetupFakeCommunicationChannel();584 this.testRequestSender.StartTestRun(this.testRunCriteriaWithSources, this.mockExecutionEventsHandler.Object);585 this.RaiseClientDisconnectedEvent();586 this.mockExecutionEventsHandler.Verify(eh => eh.HandleTestRunComplete(It.Is<TestRunCompleteEventArgs>(t => t.IsAborted), null, null, null), Times.Once);587 this.mockExecutionEventsHandler.Verify(eh => eh.HandleRawMessage("SerializedAbortedPayload"), Times.Once);588 }589 [TestMethod]590 public void SendTestRunCancelShouldSendCancelTestRunMessage()591 {592 this.SetupFakeCommunicationChannel();593 this.testRequestSender.SendTestRunCancel();594 this.mockDataSerializer.Verify(ds => ds.SerializeMessage(MessageType.CancelTestRun), Times.Once);595 this.mockChannel.Verify(c => c.Send(It.IsAny<string>()), Times.Once);596 }597 [TestMethod]598 public void SendTestRunAbortShouldSendAbortTestRunMessage()...
StartTestRun
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;10using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;11using System.IO;12{13 {14 static void Main(string[] args)15 {16 TestRequestSender sender = new TestRequestSender();17 sender.InitializeCommunication();18 sender.StartTestRun(new List<string>() { Path.Combine(Environment.CurrentDirectory, "1.dll") }, 1, false, new TestPlatformOptions(), new TestRunCriteria(new List<string>() { "1.dll" }, 1));19 Console.ReadLine();20 }21 }22}
StartTestRun
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;9{10 {11 static void Main(string[] args)12 {13 var sender = new TestRequestSender();14 sender.InitializeCommunication();15</RunSettings>";16 var runCriteria = new TestRunCriteria(new List<string>() { @"C:\Users\Public\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.dll" }, 1, false, new TestPlatformOptions(), runsettings);17 sender.StartTestRun(runCriteria, new ConsoleRunEventsHandler());18 Console.ReadLine();19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;28using Microsoft.VisualStudio.TestPlatform.ObjectModel;29using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;30{31 {32 static void Main(string[] args)33 {34 var sender = new TestRequestSender();35 sender.InitializeCommunication();
StartTestRun
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Diagnostics;4using System.IO;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;9using Microsoft.VisualStudio.TestPlatform.ObjectModel;10using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;11using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;12{13 {14 static void Main(string[] args)15 {16 TestRequestSender testRequestSender = new TestRequestSender();17 testRequestSender.InitializeCommunication();18 testRequestSender.StartTestRun(new List<st
StartTestRun
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 static void Main(string[] args)12 {13 var testRequestSender = new TestRequestSender();14 testRequestSender.InitializeCommunication();15 var runSettings = new Dictionary<string, object>();16 runSettings.Add("TestRunParameters", new Dictionary<string, string> { { "param1", "value1" }, { "param2", "value2" } });17 var runConfiguration = new TestRunConfiguration();18 var runCriteria = new TestRunCriteria(new List<string> { @"C:\Users\Public\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.dll" }, 0, false, runConfiguration, runSettings);19 testRequestSender.StartTestRun(runCriteria);20 }21 }22}
StartTestRun
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;10using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;11{12 {13 static void Main(string[] args)14 {15 var testRunCriteria = new TestRunCriteria(new List<string>() { "D:\\TestProject\\TestProject\\bin\\Debug\\TestProject.dll" }, 1);16 testRunCriteria.FrequencyOfRunStatsChangeEvent = 1;17 var testRunEventsHandler = new TestRunEventsHandler();18 var testRequestSender = new TestRequestSender();19 testRequestSender.InitializeCommunication();20 testRequestSender.StartTestRun(testRunCriteria, testRunEventsHandler);21 Console.ReadLine();22 }23 }24 {25 public void HandleLogMessage(TestMessageLevel level, string message)26 {27 Console.WriteLine(message);28 }29 public void HandleRawMessage(string rawMessage)30 {31 Console.WriteLine(rawMessage);32 }33 public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteEventArgs, TestRunChangedEventArgs[] testRunChangedEvents, ICollection<AttachmentSet> runAttachments)34 {35 Console.WriteLine("Test Run Complete");36 }37 public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedEventArgs)38 {39 Console.WriteLine("Test Run Stats Change");40 }41 }42}43Microsoft (R) Visual C# Compiler version 2.0.0.61204 (d6c4c6a4)44Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
StartTestRun
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;7{8 {9 static void Main(string[] args)10 {11 TestRequestSender testRequestSender = new TestRequestSender();12 testRequestSender.StartTestRun("testrunsettings.xml");13 }14 }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;22{23 {24 static void Main(string[] args)25 {26 TestRequestSender testRequestSender = new TestRequestSender();27 testRequestSender.StartTestRun("testrunsettings.xml");28 }29 }30}31using System;32using System.Collections.Generic;33using System.Linq;34using System.Text;35using System.Threading.Tasks;36using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;37{38 {39 static void Main(string[] args)40 {41 TestRequestSender testRequestSender = new TestRequestSender();42 testRequestSender.StartTestRun("testrunsettings.xml");43 }44 }45}46using System;47using System.Collections.Generic;48using System.Linq;49using System.Text;50using System.Threading.Tasks;51using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;52{53 {54 static void Main(string[] args)55 {56 TestRequestSender testRequestSender = new TestRequestSender();57 testRequestSender.StartTestRun("testrunsettings.xml");58 }59 }60}61using System;62using System.Collections.Generic;63using System.Linq;64using System.Text;65using System.Threading.Tasks;66using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;67{68 {69 static void Main(string[] args)70 {71 TestRequestSender testRequestSender = new TestRequestSender();72 testRequestSender.StartTestRun("testrunsettings.xml");73 }74 }75}76using System;77using System.Collections.Generic;78using System.Linq;79using System.Text;80using System.Threading.Tasks;81using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;82{83 {84 static void Main(string[] args)85 {86 TestRequestSender testRequestSender = new TestRequestSender();87 testRequestSender.StartTestRun("testrunsettings.xml");88 }89 }90}91using System;92using S stem.Collections.Gene ic;93using System.Linq;94using System.Text;95us n System.T reading.Tasks;96using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;97{98 {99 sta ic void Main(string[] args)100 {101 TestRequestSender testRequestSender = new TestRequestSender();102 testRequestSender.StartTestRun("testrunsettings.xml");103 }104 }105}106using System;107using System.Collections.Generic;108using System.Linq;109using System.Text;110using System.Threading.Tasks;111using Microsoft.VisualStudio.TestPlatform.Communication testRequestSender.InitializeCommunication();112 testRequestSender.StartTestRun(testRunCriteria, testRunEventsHandler);113 Console.ReadLine();114 }115 }116 {117 public void HandleLogMessage(TestMessageLevel level, string message)118 {119 Console.WriteLine(message);120 }121 public void HandleRawMessage(string rawMessage)122 {123 Console.WriteLine(rawMessage);124 }125 public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteEventArgs, TestRunChangedEventArgs[] testRunChangedEvents, ICollection<AttachmentSet> runAttachments)126 {127 Console.WriteLine("Test Run Complete");128 }129 public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedEventArgs)130 {131 Console.WriteLine("Test Run Stats Change");132 }133 }134}135Microsoft (R) Visual C# Compiler version 2.0.0.61204 (d6c4c6a4)136Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0
StartTestRun
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;7{8 {9 static void Main(string[] args)10 {11 TestRequestSender testRequestSender = new TestRequestSender();12 testRequestSender.StartTestRun("testrunsettings.xml");13 }14 }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;22{23 {24 static void Main(string[] args)25 {26 TestRequestSender testRequestSender = new TestRequestSender();27 testRequestSender.StartTestRun("testrunsettings.xml");28 }29 }30}31using System;32using System.Collections.Generic;33using System.Linq;34using System.Text;35using System.Threading.Tasks;36using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;37{38 {39 static void Main(string[] args)40 {41 TestRequestSender testRequestSender = new TestRequestSender();42 testRequestSender.StartTestRun("testrunsettings.xml");43 }44 }45}46using System;47using System.Collections.Generic;48using System.Linq;49using System.Text;50using System.Threading.Tasks;51using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;52{53 {54 static void Main(string[] args)55 {56 TestRequestSender testRequestSender = new TestRequestSender();57 testRequestSender.StartTestRun("testrunsettings.xml");58 }59 }60}61using System;62using System.Collections.Generic;63using System.Linq;64using System.Text;65using System.Threading.Tasks;
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!!