Skip to content

Commit d81f34f

Browse files
hvinettsinghsarab
authored andcommitted
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
1 parent 0b1362e commit d81f34f

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/Microsoft.TestPlatform.Client/DesignMode/DesignModeClient.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.DesignMode
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Data;
89
using System.Globalization;
910
using System.Net;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213

1314
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper;
15+
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
1416
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
1517
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
1618
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;
@@ -41,6 +43,8 @@ public class DesignModeClient : IDesignModeClient
4143

4244
protected Action<Message> onAckMessageReceived;
4345

46+
private TestSessionMessageLogger testSessionMessageLogger;
47+
4448
/// <summary>
4549
/// Initializes a new instance of the <see cref="DesignModeClient"/> class.
4650
/// </summary>
@@ -66,6 +70,8 @@ internal DesignModeClient(ICommunicationManager communicationManager, IDataSeria
6670
this.communicationManager = communicationManager;
6771
this.dataSerializer = dataSerializer;
6872
this.platformEnvironment = platformEnvironment;
73+
this.testSessionMessageLogger = TestSessionMessageLogger.Instance;
74+
this.testSessionMessageLogger.TestRunMessage += this.TestRunMessageHandler;
6975
}
7076

7177
/// <summary>
@@ -171,7 +177,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
171177

172178
case MessageType.StartDiscovery:
173179
{
174-
var discoveryPayload = this.dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message);
180+
var discoveryPayload = this.dataSerializer.DeserializePayload<DiscoveryRequestPayload>(message);
175181
this.StartDiscovery(discoveryPayload, testRequestManager);
176182
break;
177183
}
@@ -311,6 +317,20 @@ public void SendTestMessage(TestMessageLevel level, string message)
311317
this.communicationManager.SendMessage(MessageType.TestMessage, payload);
312318
}
313319

320+
/// <summary>
321+
/// Sends the test session logger warning and error messages to IDE;
322+
/// </summary>
323+
/// <param name="sender"></param>
324+
/// <param name="e"></param>
325+
public void TestRunMessageHandler(object sender, TestRunMessageEventArgs e)
326+
{
327+
if (e.Level == TestMessageLevel.Error || e.Level == TestMessageLevel.Warning)
328+
{
329+
var payload = new TestMessagePayload { MessageLevel = e.Level, Message = e.Message };
330+
this.communicationManager.SendMessage(MessageType.TestMessage, payload);
331+
}
332+
}
333+
314334
private void StartTestRun(TestRunRequestPayload testRunPayload, ITestRequestManager testRequestManager, bool skipTestHostLaunch)
315335
{
316336
Task.Run(

test/Microsoft.TestPlatform.Client.UnitTests/DesignMode/DesignModeClientTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode
44
{
55
using System;
66
using System.Linq;
7+
using System.Linq.Expressions;
78
using System.Net;
89
using System.Threading;
910
using System.Threading.Tasks;
@@ -17,6 +18,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Client.UnitTests.DesignMode
1718
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1819
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
1920
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;
21+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
2022
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
2123
using Microsoft.VisualStudio.TestTools.UnitTesting;
2224

@@ -65,6 +67,36 @@ public void DesignModeClientInitializeShouldInstantiateClassAndCreateClient()
6567
Assert.IsNotNull(DesignModeClient.Instance);
6668
}
6769

70+
[TestMethod]
71+
public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisError()
72+
{
73+
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));
74+
75+
this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Error, "message"));
76+
77+
this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(),It.IsAny<TestMessagePayload>()), Times.Once());
78+
}
79+
80+
[TestMethod]
81+
public void TestRunMessageHandlerShouldCallCommmunicationManagerIfMessageisWarning()
82+
{
83+
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));
84+
85+
this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Warning, "message"));
86+
87+
this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(), It.IsAny<TestMessagePayload>()), Times.Once());
88+
}
89+
90+
[TestMethod]
91+
public void TestRunMessageHandlerShouldNotCallCommmunicationManagerIfMessageisInformational()
92+
{
93+
this.mockCommunicationManager.Setup(cm => cm.SendMessage(It.IsAny<string>()));
94+
95+
this.designModeClient.TestRunMessageHandler(new object(), new TestRunMessageEventArgs(TestMessageLevel.Informational, "message"));
96+
97+
this.mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny<string>(), It.IsAny<TestMessagePayload>()), Times.Never());
98+
}
99+
68100
[TestMethod]
69101
public void DesignModeClientConnectShouldSetupChannel()
70102
{

0 commit comments

Comments
 (0)