From c5a7134b3da9c31e6e0cee3def5b0094dda900c2 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 12:39:47 +0200 Subject: [PATCH] Tests for design mode client --- .../DesignMode/DesignModeClientTests.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 98befe71f8..e34ec2335c 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client.DesignMode; + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; @@ -405,6 +406,81 @@ public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTes this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.DiscoveryComplete, It.IsAny()), Times.Once()); } + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndFinalizationCompleteOnExceptionInFinalization() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Callback(() => complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.FinalizeMultiTestRun( + It.IsAny(), + It.IsAny())) + .Throws(new Exception()); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + } + + [TestMethod] + public void DesignModeClientConnectShouldSendTestMessageAndDiscoverCompleteOnTestPlatformExceptionInFinalization() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + this.mockCommunicationManager + .Setup(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny())) + .Callback(() => complateEvent.Set()); + this.mockTestRequestManager.Setup( + rm => rm.FinalizeMultiTestRun( + It.IsAny(), + It.IsAny())) + .Throws(new TestPlatformException("Hello world")); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + Assert.IsTrue(this.complateEvent.WaitOne(Timeout), "Finalization not completed."); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Once()); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == null)), Times.Once()); + } + + [TestMethod] + public void DesignModeClientConnectShouldCallRequestManagerForFinalizationStart() + { + var payload = new MultiTestRunFinalizationPayload(); + var startFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationStart, Payload = JToken.FromObject(payload) }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(startFinalization); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.FinalizeMultiTestRun(It.IsAny(), It.IsAny())); + } + + [TestMethod] + public void DesignModeClientConnectShouldCallRequestManagerForFinalizationCancel() + { + var cancelFinalization = new Message { MessageType = MessageType.MultiTestRunFinalizationCancel }; + this.mockCommunicationManager.Setup(cm => cm.WaitForServerConnection(It.IsAny())).Returns(true); + this.mockCommunicationManager.SetupSequence(cm => cm.ReceiveMessage()).Returns(cancelFinalization); + + this.designModeClient.ConnectToClientAndProcessRequests(PortNumber, this.mockTestRequestManager.Object); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.IsAny()), Times.Never); + this.mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.IsAny()), Times.Never); + this.mockTestRequestManager.Verify(rm => rm.CancelMultiTestRunFinalization()); + } + [TestMethod] public void DesignModeClientConnectShouldSendTestMessageAndExecutionCompleteOnExceptionInTestRun() {