From d81f34f9206d14655bee6cd12858d88d441fab90 Mon Sep 17 00:00:00 2001 From: Vineeth Hanumanth <39301309+hvinett@users.noreply.github.com> Date: Thu, 12 Sep 2019 14:32:57 +0530 Subject: [PATCH] Notify translation layer for any errors and warning logged during session (#2165) * subscribed to test session manager and added unit tests * only warning and error are shown to IDE --- .../DesignMode/DesignModeClient.cs | 22 ++++++++++++- .../DesignMode/DesignModeClientTests.cs | 32 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs index 41e6b135ae..6e3c8b16f3 100644 --- a/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs +++ b/src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs @@ -5,12 +5,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode { using System; using System.Collections.Generic; + using System.Data; using System.Globalization; using System.Net; using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; + using Microsoft.VisualStudio.TestPlatform.Common.Logging; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -41,6 +43,8 @@ public class DesignModeClient : IDesignModeClient protected Action onAckMessageReceived; + private TestSessionMessageLogger testSessionMessageLogger; + /// /// Initializes a new instance of the class. /// @@ -66,6 +70,8 @@ internal DesignModeClient(ICommunicationManager communicationManager, IDataSeria this.communicationManager = communicationManager; this.dataSerializer = dataSerializer; this.platformEnvironment = platformEnvironment; + this.testSessionMessageLogger = TestSessionMessageLogger.Instance; + this.testSessionMessageLogger.TestRunMessage += this.TestRunMessageHandler; } /// @@ -171,7 +177,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager) case MessageType.StartDiscovery: { - var discoveryPayload = this.dataSerializer.DeserializePayload(message); + var discoveryPayload = this.dataSerializer.DeserializePayload(message); this.StartDiscovery(discoveryPayload, testRequestManager); break; } @@ -311,6 +317,20 @@ public void SendTestMessage(TestMessageLevel level, string message) this.communicationManager.SendMessage(MessageType.TestMessage, payload); } + /// + /// Sends the test session logger warning and error messages to IDE; + /// + /// + /// + public void TestRunMessageHandler(object sender, TestRunMessageEventArgs e) + { + if (e.Level == TestMessageLevel.Error || e.Level == TestMessageLevel.Warning) + { + var payload = new TestMessagePayload { MessageLevel = e.Level, Message = e.Message }; + this.communicationManager.SendMessage(MessageType.TestMessage, payload); + } + } + private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool skipTestHostLaunch) { Task.Run( diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs index 2b63e8891d..5b834a3b27 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode { using System; using System.Linq; + using System.Linq.Expressions; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -17,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -65,6 +67,36 @@ public void DesignModeClientInitializeShouldInstantiateClassAndCreateClient() Assert.IsNotNull(DesignModeClient.Instance); } + [TestMethod] + public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisError() + { + this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny())); + + this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Error, "message")); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny(),It.IsAny()), Times.Once()); + } + + [TestMethod] + public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisWarning() + { + this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny())); + + this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Warning, "message")); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny(), It.IsAny()), Times.Once()); + } + + [TestMethod] + public void TestRunMessageHandlerShouldNotCallCommmunicationManagerIfMessageisInformational() + { + this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny())); + + this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Informational, "message")); + + this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny(), It.IsAny()), Times.Never()); + } + [TestMethod] public void DesignModeClientConnectShouldSetupChannel() {