public void AfterTestRunShouldHandleSocketFailureGracefully()
        {
            var socketCommManager           = new SocketCommunicationManager();
            var dataCollectionRequestSender = new DataCollectionRequestSender(socketCommManager, JsonDataSerializer.Instance);

#if NET46
            var dataCollectionLauncher = new DefaultDataCollectionLauncher();
#else
            var dataCollectionLauncher = new DotnetDataCollectionLauncher();
#endif
            using (var proxyDataCollectionManager = new ProxyDataCollectionManager(ObjectModel.Architecture.AnyCPU, this.runSettings, dataCollectionRequestSender, dataCollectionLauncher))
            {
                proxyDataCollectionManager.BeforeTestRunStart(true, true, this.mockTestMessageEventHandler.Object);

                var result = Process.GetProcessById(dataCollectionLauncher.DataCollectorProcess.Id);
                Assert.IsNotNull(result);

                socketCommManager.StopClient();

                var attachments = proxyDataCollectionManager.AfterTestRunEnd(false, this.mockTestMessageEventHandler.Object);

                Assert.IsNull(attachments);

                // Give time to datacollector process to exit.
                Assert.IsTrue(result.WaitForExit(500));
            }
        }
Exemple #2
0
 public void Initialize()
 {
     this.mockDataCollectionRequestSender = new Mock <IDataCollectionRequestSender>();
     this.mockDataCollectionLauncher      = new Mock <IDataCollectionLauncher>();
     this.mockProcessHelper          = new Mock <IProcessHelper>();
     this.proxyDataCollectionManager = new ProxyDataCollectionManager(string.Empty, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);
 }
Exemple #3
0
 public void Initialize()
 {
     this.mockDataCollectionRequestSender = new Mock <IDataCollectionRequestSender>();
     this.mockDataCollectionLauncher      = new Mock <IDataCollectionLauncher>();
     this.mockProcessHelper     = new Mock <IProcessHelper>();
     this.mockRequestData       = new Mock <IRequestData>();
     this.mockMetricsCollection = new Mock <IMetricsCollection>();
     this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object);
     this.proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, string.Empty, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);
 }
Exemple #4
0
        public void SendTestHostInitiazliedShouldPassProcessIdToRequestSender()
        {
            string runsettings = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><RunSettings><RunConfiguration></RunConfiguration></RunSettings>";

            this.proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, runsettings, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);

            this.proxyDataCollectionManager.TestHostLaunched(1234);

            this.mockDataCollectionRequestSender.Verify(x => x.SendTestHostLaunched(It.Is <TestHostLaunchedPayload>(y => y.ProcessId == 1234)));
        }
        public void BeforeTestRunStartShouldGetEnviornmentVariables()
        {
            var dataCollectionRequestSender = new DataCollectionRequestSender();

            using (var proxyDataCollectionManager = new ProxyDataCollectionManager(ObjectModel.Architecture.AnyCPU, this.runSettings, dataCollectionRequestSender, this.dataCollectionLauncher))
            {
                var result = proxyDataCollectionManager.BeforeTestRunStart(true, true, this.mockTestMessageEventHandler.Object);

                Assert.AreEqual(1, result.EnvironmentVariables.Count);
            }
        }
Exemple #6
0
        public void BeforeTestRunStartShouldGetEnviornmentVariables()
        {
            var dataCollectionRequestSender = new DataCollectionRequestSender();

            using (var proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, this.runSettings, dataCollectionRequestSender, this.processHelper, this.dataCollectionLauncher))
            {
                proxyDataCollectionManager.Initialize();

                var result = proxyDataCollectionManager.BeforeTestRunStart(true, true, this.mockTestMessageEventHandler.Object);

                Assert.AreEqual(1, result.EnvironmentVariables.Count);
            }
        }
Exemple #7
0
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            mockDataCollectionClient.Setup(dc => dc.BeforeTestRunStart(It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>())).Throws(new System.Exception("MyException"));
            mockDataCollectionClient.Setup(dc => dc.AfterTestRunEnd(It.IsAny <bool>(), It.IsAny <ITestMessageEventHandler>()));

            ProxyDataCollectionManager proxyDataCollectonManager = new ProxyDataCollectionManager(Architecture.AnyCPU, string.Empty, new DummyDataCollectionRequestSender(), new DummyDataCollectionLauncher());

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize();
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.ExceptionMessages);
            Assert.AreEqual(1, proxyExecutionManager.DataCollectionRunEventsHandler.ExceptionMessages.Count);
        }
        public void AfterTestRunShouldSendGetAttachments()
        {
            var dataCollectionRequestSender = new DataCollectionRequestSender();

            using (var proxyDataCollectionManager = new ProxyDataCollectionManager(ObjectModel.Architecture.AnyCPU, this.runSettings, dataCollectionRequestSender, this.dataCollectionLauncher))
            {
                proxyDataCollectionManager.BeforeTestRunStart(true, true, this.mockTestMessageEventHandler.Object);

                var attachments = proxyDataCollectionManager.AfterTestRunEnd(false, this.mockTestMessageEventHandler.Object);

                Assert.AreEqual("CustomDataCollector", attachments[0].DisplayName);
                Assert.AreEqual("my://custom/datacollector", attachments[0].Uri.ToString());
                Assert.IsTrue(attachments[0].Attachments[0].Uri.ToString().Contains("filename.txt"));
            }
        }
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            var mockRequestSender = new Mock <IDataCollectionRequestSender>();

            mockRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(It.IsAny <string>(), It.IsAny <ITestMessageEventHandler>())).Throws(new Exception("MyException"));

            var mockDataCollectionLauncher = new Mock <IDataCollectionLauncher>();
            var proxyDataCollectonManager  = new ProxyDataCollectionManager(string.Empty, mockRequestSender.Object, this.mockProcessHelper.Object, mockDataCollectionLauncher.Object);

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize();
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.Messages);
            Assert.AreEqual(TestMessageLevel.Error, proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item1);
            Assert.AreEqual("MyException", proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2);
        }
Exemple #10
0
        public void BeforeTestRunStartShouldPassRunSettingsWithExtensionsFolderUpdatedAsTestAdapterPath()
        {
            string runsettings = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><RunSettings><RunConfiguration></RunConfiguration></RunSettings>";

            this.proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, runsettings, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);

            BeforeTestRunStartResult res = new BeforeTestRunStartResult(new Dictionary <string, string>(), 123);

            this.mockDataCollectionRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(It.IsAny <string>(), It.IsAny <ITestMessageEventHandler>())).Returns(res);

            var result = this.proxyDataCollectionManager.BeforeTestRunStart(true, true, null);

            var extensionsFolderPath = Path.Combine(Path.GetDirectoryName(typeof(ITestPlatform).GetTypeInfo().Assembly.Location), "Extensions");
            var expectedSettingsXML  = $"<?xml version=\"1.0\" encoding=\"utf-8\"?><RunSettings><RunConfiguration><TestAdaptersPaths>{extensionsFolderPath}</TestAdaptersPaths></RunConfiguration></RunSettings>";

            this.mockDataCollectionRequestSender.Verify(
                x => x.SendBeforeTestRunStartAndGetResult(expectedSettingsXML, It.IsAny <ITestMessageEventHandler>()), Times.Once);
        }
Exemple #11
0
        public void ProxyDataCollectionShouldLogEnabledDataCollectors()
        {
            string settings = @"<RunSettings>
              <DataCollectionRunSettings>
                <DataCollectors>
                    <DataCollector friendlyName=""Code Coverage"" uri=""datacollector://Microsoft/CodeCoverage/2.0"" assemblyQualifiedName=""Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"">
                </DataCollector>
              </DataCollectors>
             </DataCollectionRunSettings>
           </RunSettings>";

            this.mockRequestData.Setup(rd => rd.IsTelemetryOptedIn).Returns(true);

            var proxyExecutionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, settings, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);

            var resultString = "{ FriendlyName = Code Coverage, Uri = datacollector://microsoft/CodeCoverage/2.0 }";

            this.mockMetricsCollection.Verify(rd => rd.Add(TelemetryDataConstants.DataCollectorsEnabled, resultString), Times.Once);
        }
        public void SendBeforeTestRunStartAndGetResultShouldBeInvokedWithCorrectTestSources()
        {
            var testSources = new List <string>()
            {
                "abc.dll", "efg.dll"
            };

            this.proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, string.Empty, testSources, this.mockDataCollectionRequestSender.Object, this.mockProcessHelper.Object, this.mockDataCollectionLauncher.Object);

            BeforeTestRunStartResult res = new BeforeTestRunStartResult(new Dictionary <string, string>(), 123);

            this.mockDataCollectionRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(string.Empty, testSources, It.IsAny <ITestMessageEventHandler>())).Returns(res);

            var result = this.proxyDataCollectionManager.BeforeTestRunStart(true, true, null);

            this.mockDataCollectionRequestSender.Verify(
                x => x.SendBeforeTestRunStartAndGetResult(string.Empty, testSources, It.IsAny <ITestMessageEventHandler>()), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(res.DataCollectionEventsPort, result.DataCollectionEventsPort);
            Assert.AreEqual(res.EnvironmentVariables.Count, result.EnvironmentVariables.Count);
        }
        public void InitializeShouldSaveExceptionMessagesIfThrownByDataCollectionProcess()
        {
            var mockRequestSender = new Mock <IDataCollectionRequestSender>();
            var testSources       = new List <string>()
            {
                "abc.dll", "efg.dll"
            };

            mockRequestSender.Setup(x => x.SendBeforeTestRunStartAndGetResult(string.Empty, testSources, It.IsAny <ITestMessageEventHandler>())).Throws(new Exception("MyException"));
            mockRequestSender.Setup(x => x.WaitForRequestHandlerConnection(It.IsAny <int>())).Returns(true);

            var mockDataCollectionLauncher = new Mock <IDataCollectionLauncher>();
            var proxyDataCollectonManager  = new ProxyDataCollectionManager(this.mockRequestData.Object, string.Empty, testSources, mockRequestSender.Object, this.mockProcessHelper.Object, mockDataCollectionLauncher.Object);

            var proxyExecutionManager = new ProxyExecutionManagerWithDataCollection(this.mockRequestData.Object, this.mockRequestSender.Object, this.mockTestHostManager.Object, proxyDataCollectonManager);

            proxyExecutionManager.Initialize(false);
            Assert.IsNotNull(proxyExecutionManager.DataCollectionRunEventsHandler.Messages);
            Assert.AreEqual(TestMessageLevel.Error, proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item1);
            StringAssert.Contains(proxyExecutionManager.DataCollectionRunEventsHandler.Messages[0].Item2, "MyException");
        }
Exemple #14
0
        public void AfterTestRunShouldHandleSocketFailureGracefully()
        {
            var socketCommManager           = new SocketCommunicationManager();
            var dataCollectionRequestSender = new DataCollectionRequestSender(socketCommManager, JsonDataSerializer.Instance);
            var dataCollectionLauncher      = DataCollectionLauncherFactory.GetDataCollectorLauncher(this.processHelper, this.runSettings);

            using (var proxyDataCollectionManager = new ProxyDataCollectionManager(this.mockRequestData.Object, this.runSettings, dataCollectionRequestSender, this.processHelper, dataCollectionLauncher))
            {
                proxyDataCollectionManager.Initialize();
                proxyDataCollectionManager.BeforeTestRunStart(true, true, this.mockTestMessageEventHandler.Object);

                var result = Process.GetProcessById(dataCollectionLauncher.DataCollectorProcessId);
                Assert.IsNotNull(result);

                socketCommManager.StopClient();

                var attachments = proxyDataCollectionManager.AfterTestRunEnd(false, this.mockTestMessageEventHandler.Object);

                Assert.IsNull(attachments);

                // Give time to datacollector process to exit.
                Assert.IsTrue(result.WaitForExit(500));
            }
        }
Exemple #15
0
 public void Initialize()
 {
     this.mockDataCollectionRequestSender = new DummyDataCollectionRequestSender();
     this.mockDataCollectionLauncher      = new DummyDataCollectionLauncher();
     this.proxyDataCollectionManager      = new ProxyDataCollectionManager(Architecture.AnyCPU, string.Empty, this.mockDataCollectionRequestSender, this.mockDataCollectionLauncher);
 }