Esempio n. 1
0
        public void ProcessRequestsShouldProcessRequests()
        {
            var testHostLaunchedPayload = new TestHostLaunchedPayload();

            testHostLaunchedPayload.ProcessId = 1234;

            this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(this.beforeTestRunStart)
            .Returns(new Message()
            {
                MessageType = MessageType.TestHostLaunched, Payload = JToken.FromObject(testHostLaunchedPayload)
            })
            .Returns(this.afterTestRunEnd);

            this.mockDataCollectionManager.Setup(x => x.SessionStarted()).Returns(true);
            this.mockDataCollectionManager.Setup(x => x.TestHostLaunched(It.IsAny <int>()));
            this.mockDataSerializer.Setup(x => x.DeserializePayload <TestHostLaunchedPayload>(It.Is <Message>(y => y.MessageType == MessageType.TestHostLaunched)))
            .Returns(testHostLaunchedPayload);

            this.requestHandler.ProcessRequests();

            this.mockDataCollectionTestCaseEventHandler.Verify(x => x.InitializeCommunication(), Times.Once);
            this.mockDataCollectionTestCaseEventHandler.Verify(x => x.WaitForRequestHandlerConnection(It.IsAny <int>()), Times.Once);
            this.mockDataCollectionTestCaseEventHandler.Verify(x => x.ProcessRequests(), Times.Once);

            // Verify SessionStarted events
            this.mockDataCollectionManager.Verify(x => x.SessionStarted(), Times.Once);
            this.mockCommunicationManager.Verify(x => x.SendMessage(MessageType.BeforeTestRunStartResult, It.IsAny <BeforeTestRunStartResult>()), Times.Once);

            // Verify TestHostLaunched events
            this.mockDataCollectionManager.Verify(x => x.TestHostLaunched(1234), Times.Once);

            // Verify AfterTestRun events.
            this.mockDataCollectionManager.Verify(x => x.SessionEnded(It.IsAny <bool>()), Times.Once);
            this.mockCommunicationManager.Verify(x => x.SendMessage(MessageType.AfterTestRunEndResult, It.IsAny <Collection <AttachmentSet> >()), Times.Once);
        }
        /// <inheritdoc />
        public void TestHostLaunched(int processId)
        {
            var payload = new TestHostLaunchedPayload();

            payload.ProcessId = processId;

            this.dataCollectionRequestSender.SendTestHostLaunched(payload);
        }
        public void ProcessRequestsShouldAddSourceDirectoryToTestPluginCache()
        {
            var testHostLaunchedPayload = new TestHostLaunchedPayload();

            testHostLaunchedPayload.ProcessId = 1234;

            var    temp        = Path.GetTempPath();
            string runSettings = "<RunSettings><RunConfiguration><TestAdaptersPaths></TestAdaptersPaths></RunConfiguration></RunSettings>";

            this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(this.beforeTestRunStart)
            .Returns(new Message()
            {
                MessageType = MessageType.TestHostLaunched, Payload = JToken.FromObject(testHostLaunchedPayload)
            })
            .Returns(this.afterTestRunEnd);

            this.mockDataCollectionManager.Setup(x => x.SessionStarted(It.IsAny <SessionStartEventArgs>())).Returns(true);
            this.mockDataCollectionManager.Setup(x => x.TestHostLaunched(It.IsAny <int>()));
            this.mockDataSerializer.Setup(x => x.DeserializePayload <TestHostLaunchedPayload>(It.Is <Message>(y => y.MessageType == MessageType.TestHostLaunched)))
            .Returns(testHostLaunchedPayload);
            var beforeTestRunSTartPayload = new BeforeTestRunStartPayload
            {
                SettingsXml = runSettings,
                Sources     = new List <string>
                {
                    Path.Combine(temp, "dir1", "test1.dll"),
                    Path.Combine(temp, "dir2", "test2.dll"),
                    Path.Combine(temp, "dir3", "test3.dll")
                }
            };

            this.mockDataSerializer.Setup(x => x.DeserializePayload <BeforeTestRunStartPayload>(It.Is <Message>(y => y.MessageType == MessageType.BeforeTestRunStart)))
            .Returns(beforeTestRunSTartPayload);
            this.mockFileHelper.Setup(x => x.DirectoryExists($@"{temp}dir1")).Returns(true);
            this.mockFileHelper.Setup(x => x.EnumerateFiles($@"{temp}dir1", SearchOption.AllDirectories, @"Collector.dll")).Returns(new List <string> {
                Path.Combine(temp, "dir1", "abc.DataCollector.dll")
            });

            this.requestHandler.ProcessRequests();

            this.mockFileHelper.Verify(x => x.EnumerateFiles($@"{temp}dir1", SearchOption.AllDirectories, @"Collector.dll"), Times.Once);
            Assert.IsTrue(TestPluginCache.Instance.GetExtensionPaths(@"Collector.dll").Contains(Path.Combine(temp, "dir1", "abc.DataCollector.dll")));
        }
Esempio n. 4
0
 /// <inheritdoc/>
 public void SendTestHostLaunched(TestHostLaunchedPayload testHostLaunchedPayload)
 {
     this.communicationManager.SendMessage(MessageType.TestHostLaunched, testHostLaunchedPayload);
 }