From daaef855543dc1c3bdc46964cda9b756f43193fd Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Thu, 11 Jun 2020 13:02:51 +0200 Subject: [PATCH] Tests for events handler --- ...tiTestRunFinalizationEventsHandlerTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs new file mode 100644 index 0000000000..26d50e6edc --- /dev/null +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +namespace Microsoft.TestPlatform.Client.UnitTests.MultiTestRunFinalization +{ + using Microsoft.VisualStudio.TestPlatform.Client.MultiTestRunFinalization; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + using Moq; + + [TestClass] + public class MultiTestRunFinalizationEventsHandlerTests + { + private readonly Mock mockCommunicationManager; + private readonly IMultiTestRunFinalizationEventsHandler handler; + + public MultiTestRunFinalizationEventsHandlerTests() + { + this.mockCommunicationManager = new Mock(); + this.handler = new MultiTestRunFinalizationEventsHandler(mockCommunicationManager.Object); + } + + [TestMethod] + public void EventsHandlerHandleLogMessageShouldSendTestMessage() + { + string message = "error message"; + + handler.HandleLogMessage(TestMessageLevel.Error, message); + + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.TestMessage, It.Is(p => p.MessageLevel == TestMessageLevel.Error && p.Message == message))); + } + + [TestMethod] + public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinalizationCompleteMessage() + { + var attachments = new[] { new AttachmentSet(new System.Uri("http://www.bing.com/"), "code coverage") }; + + handler.HandleMultiTestRunFinalizationComplete(attachments); + + mockCommunicationManager.Verify(cm => cm.SendMessage(MessageType.MultiTestRunFinalizationComplete, It.Is(p => p.Attachments == attachments))); + } + + [TestMethod] + public void EventsHandlerHandleRawMessageShouldDoNothing() + { + handler.HandleRawMessage("any"); + + mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny()), Times.Never); + mockCommunicationManager.Verify(cm => cm.SendMessage(It.IsAny(), It.IsAny()), Times.Never); + } + } +}