Skip to content

Commit

Permalink
Notify translation layer for any errors and warning logged during ses…
Browse files Browse the repository at this point in the history
…sion (#2165)

* subscribed to test session manager and added unit tests
* only warning and error are shown to IDE
  • Loading branch information
hvinett authored and singhsarab committed Sep 12, 2019
1 parent 0b1362e commit d81f34f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +43,8 @@ public class DesignModeClient : IDesignModeClient

protected Action<Message> onAckMessageReceived;

private TestSessionMessageLogger testSessionMessageLogger;

/// <summary>
/// Initializes a new instance of the <see cref="DesignModeClient"/> class.
/// </summary>
Expand All @@ -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;
}

/// <summary>
Expand Down Expand Up @@ -171,7 +177,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)

case MessageType.StartDiscovery:
{
var discoveryPayload = this.dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message);
var discoveryPayload = this.dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message);
this.StartDiscovery(discoveryPayload, testRequestManager);
break;
}
Expand Down Expand Up @@ -311,6 +317,20 @@ public void SendTestMessage(TestMessageLevel level, string message)
this.communicationManager.SendMessage(MessageType.TestMessage, payload);
}

/// <summary>
/// Sends the test session logger warning and error messages to IDE;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -65,6 +67,36 @@ public void DesignModeClientInitializeShouldInstantiateClassAndCreateClient()
Assert.IsNotNull(DesignModeClient.Instance);
}

[TestMethod]
public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisError()
{
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));

this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Error, "message"));

this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(),It.IsAny<TestMessagePayload>()), Times.Once());
}

[TestMethod]
public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisWarning()
{
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));

this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Warning, "message"));

this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(), It.IsAny<TestMessagePayload>()), Times.Once());
}

[TestMethod]
public void TestRunMessageHandlerShouldNotCallCommmunicationManagerIfMessageisInformational()
{
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));

this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Informational, "message"));

this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(), It.IsAny<TestMessagePayload>()), Times.Never());
}

[TestMethod]
public void DesignModeClientConnectShouldSetupChannel()
{
Expand Down

0 comments on commit d81f34f

Please sign in to comment.