Пример #1
0
        /// <summary>
        /// Discovers tests
        /// </summary>
        /// <param name="discoveryCriteria">Settings, parameters for the discovery request</param>
        /// <param name="eventHandler">EventHandler for handling discovery events from Engine</param>
        public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
        {
            try
            {
                var discoveryEngineStartTime = DateTime.UtcNow;

                this.isCommunicationEstablished = this.SetupChannel(discoveryCriteria.Sources, this.cancellationTokenSource.Token);

                if (this.isCommunicationEstablished)
                {
                    this.InitializeExtensions(discoveryCriteria.Sources);
                    discoveryCriteria.UpdateDiscoveryCriteria(testHostManager);

                    // Collecting Time Taken to Start Discovery Engine
                    var discoveryEngineTotalTime = DateTime.UtcNow - discoveryEngineStartTime;
                    this.requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecToStartDiscoveryEngine, discoveryEngineTotalTime.TotalSeconds.ToString());

                    this.RequestSender.DiscoverTests(discoveryCriteria, eventHandler);
                }
            }
            catch (Exception exception)
            {
                EqtTrace.Error("ProxyDiscoveryManager.DiscoverTests: Failed to discover tests: {0}", exception);

                // Log to vs ide test output
                var testMessagePayload = new TestMessagePayload {
                    MessageLevel = TestMessageLevel.Error, Message = exception.Message
                };
                var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload);
                eventHandler.HandleRawMessage(rawMessage);

                // Log to vstest.console
                // Send a discovery complete to caller. Similar logic is also used in ParallelProxyDiscoveryManager.DiscoverTestsOnConcurrentManager
                // Aborted is `true`: in case of parallel discovery (or non shared host), an aborted message ensures another discovery manager
                // created to replace the current one. This will help if the current discovery manager is aborted due to irreparable error
                // and the test host is lost as well.
                eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.Message);

                var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(-1, true);

                eventHandler.HandleDiscoveryComplete(discoveryCompleteEventsArgs, new List <ObjectModel.TestCase>());
            }
        }
        public void DiscoverTestRunShouldAllowRuntimeProviderToUpdateAdapterSource()
        {
            var inputSources = new List <string> {
                "test.dll"
            };
            var discoveryCriteria = new DiscoveryCriteria(inputSources, 1, string.Empty);
            var mockTestDiscoveryEventsHandler = new Mock <ITestDiscoveryEventsHandler2>();
            var manualResetEvent = new ManualResetEvent(false);

            this.mockTestHostManager.Setup(hm => hm.GetTestSources(discoveryCriteria.Sources)).Returns(discoveryCriteria.Sources);
            this.mockDiscoveryManager.Setup(o => o.DiscoverTests(discoveryCriteria, mockTestDiscoveryEventsHandler.Object)).Callback(
                () => manualResetEvent.Set());

            this.inProcessProxyDiscoveryManager = new InProcessProxyDiscoveryManager(this.mockTestHostManager.Object, this.mockTestHostManagerFactory.Object);
            this.inProcessProxyDiscoveryManager.DiscoverTests(discoveryCriteria, mockTestDiscoveryEventsHandler.Object);

            Assert.IsTrue(manualResetEvent.WaitOne(5000), "IDiscoveryManager.DiscoverTests should get called");
            this.mockTestHostManager.Verify(hm => hm.GetTestSources(inputSources), Times.Once);
        }
Пример #3
0
        public void DiscoverTestsShouldDiscoverTestsInTheSpecifiedSource()
        {
            TestPluginCacheTests.SetupMockExtensions(
                new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },
                () => { });

            var sources = new List <string>
            {
                typeof(DiscoveryManagerTests).GetTypeInfo().Assembly.Location
            };

            var criteria   = new DiscoveryCriteria(sources, 1, null);
            var mockLogger = new Mock <ITestDiscoveryEventsHandler2>();

            this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);

            // Assert that the tests are passed on via the handletestruncomplete event.
            mockLogger.Verify(l => l.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), It.IsAny <IEnumerable <TestCase> >()), Times.Once);
        }
Пример #4
0
        public void DiscoverTestsShouldCallTestPlatformAndSucceed()
        {
            var payload = new DiscoveryRequestPayload()
            {
                Sources = new List <string>()
                {
                    "a", "b"
                }
            };

            var createDiscoveryRequestCalled          = 0;
            DiscoveryCriteria actualDiscoveryCriteria = null;
            var mockDiscoveryRequest = new Mock <IDiscoveryRequest>();

            this.mockTestPlatform.Setup(mt => mt.CreateDiscoveryRequest(It.IsAny <DiscoveryCriteria>())).Callback <DiscoveryCriteria>(
                (discoveryCriteria) =>
            {
                createDiscoveryRequestCalled++;
                actualDiscoveryCriteria = discoveryCriteria;
            }).Returns(mockDiscoveryRequest.Object);

            var mockDiscoveryRegistrar = new Mock <ITestDiscoveryEventsRegistrar>();
            var success = this.testRequestManager.DiscoverTests(payload, mockDiscoveryRegistrar.Object);

            Assert.IsTrue(success, "DiscoverTests call must succeed");

            Assert.AreEqual(createDiscoveryRequestCalled, 1, "CreateDiscoveryRequest must be invoked only once.");
            Assert.AreEqual(2, actualDiscoveryCriteria.Sources.Count(), "All Sources must be used for discovery request");
            Assert.AreEqual("a", actualDiscoveryCriteria.Sources.First(), "First Source in list is incorrect");
            Assert.AreEqual("b", actualDiscoveryCriteria.Sources.ElementAt(1), "Second Source in list is incorrect");

            // Default frequency is set to 10, unless specified in runsettings.
            Assert.AreEqual(10, actualDiscoveryCriteria.FrequencyOfDiscoveredTestsEvent);

            mockDiscoveryRegistrar.Verify(md => md.RegisterDiscoveryEvents(It.IsAny <IDiscoveryRequest>()), Times.Once);
            mockDiscoveryRegistrar.Verify(md => md.UnregisterDiscoveryEvents(It.IsAny <IDiscoveryRequest>()), Times.Once);

            mockDiscoveryRequest.Verify(md => md.DiscoverAsync(), Times.Once);

            mockTestPlatformEventSource.Verify(mt => mt.DiscoveryRequestStart(), Times.Once);
            mockTestPlatformEventSource.Verify(mt => mt.DiscoveryRequestStop(), Times.Once);
        }
Пример #5
0
        /// <inheritdoc/>
        public IProxyDiscoveryManager GetDiscoveryManager(
            IRequestData requestData,
            ITestRuntimeProvider testHostManager,
            DiscoveryCriteria discoveryCriteria)
        {
            var parallelLevel = this.VerifyParallelSettingAndCalculateParallelLevel(
                discoveryCriteria.Sources.Count(),
                discoveryCriteria.RunSettings);

            // Collecting IsParallel enabled.
            requestData.MetricsCollection.Add(
                TelemetryDataConstants.ParallelEnabledDuringDiscovery,
                parallelLevel > 1 ? "True" : "False");

            if (this.ShouldRunInNoIsolation(discoveryCriteria.RunSettings, parallelLevel > 1, false))
            {
                var isTelemetryOptedIn = requestData.IsTelemetryOptedIn;
                var newRequestData     = this.GetRequestData(isTelemetryOptedIn);
                return(new InProcessProxyDiscoveryManager(
                           testHostManager,
                           new TestHostManagerFactory(newRequestData)));
            }

            Func <IProxyDiscoveryManager> proxyDiscoveryManagerCreator = () =>
            {
                var hostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);
                hostManager?.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

                return(new ProxyDiscoveryManager(
                           requestData,
                           new TestRequestSender(requestData.ProtocolConfig, hostManager),
                           hostManager));
            };

            return(testHostManager.Shared
                ? proxyDiscoveryManagerCreator()
                : new ParallelProxyDiscoveryManager(
                       requestData,
                       proxyDiscoveryManagerCreator,
                       parallelLevel,
                       sharedHosts: testHostManager.Shared));
        }
Пример #6
0
        public void DiscoverTestsShouldHandleExceptionOnSendMessage()
        {
            var sources = new List <string>()
            {
                "Hello", "World"
            };
            string settingsXml       = "SettingsXml";
            var    mockHandler       = new Mock <ITestDiscoveryEventsHandler>();
            var    discoveryCriteria = new DiscoveryCriteria(sources, 100, settingsXml);
            var    exception         = new Exception();

            this.mockCommunicationManager.Setup(cm => cm.SendMessage(MessageType.StartDiscovery, discoveryCriteria, this.protocolConfig.Version))
            .Throws(exception);

            this.testRequestSender.DiscoverTests(discoveryCriteria, mockHandler.Object);

            mockHandler.Verify(mh => mh.HandleDiscoveryComplete(-1, null, true), Times.Once);
            mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, It.IsAny <string>()), Times.Once);
            mockHandler.Verify(mh => mh.HandleRawMessage(It.IsAny <string>()), Times.Exactly(2));
        }
Пример #7
0
        public void CreateDiscoveryRequestShouldInitializeManagersAndCreateDiscoveryRequestWithGivenCriteriaAndReturnIt()
        {
            this.discoveryManager.Setup(dm => dm.Initialize()).Verifiable();
            var discoveryCriteria = new DiscoveryCriteria(new List <string> {
                "foo"
            }, 1, null);

            this.hostManager.Setup(hm => hm.GetTestSources(discoveryCriteria.Sources))
            .Returns(discoveryCriteria.Sources);

            this.testEngine.Setup(te => te.GetDiscoveryManager(It.IsAny <IRequestData>(), this.hostManager.Object, It.IsAny <DiscoveryCriteria>(), It.IsAny <ProtocolConfig>())).Returns(this.discoveryManager.Object);
            this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);
            var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object);

            var discoveryRequest = tp.CreateDiscoveryRequest(discoveryCriteria, It.IsAny <ProtocolConfig>());

            this.hostManager.Verify(hm => hm.Initialize(It.IsAny <TestSessionMessageLogger>(), It.IsAny <string>()), Times.Once);
            this.discoveryManager.Verify(dm => dm.Initialize(), Times.Once);
            Assert.AreEqual(discoveryCriteria, discoveryRequest.DiscoveryCriteria);
        }
Пример #8
0
        /// <summary>
        /// Discovers tests
        /// </summary>
        /// <param name="discoveryCriteria">Settings, parameters for the discovery request</param>
        /// <param name="eventHandler">EventHandler for handling discovery events from Engine</param>
        public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler eventHandler)
        {
            try
            {
                if (!this.testHostManager.Shared)
                {
                    // If the test host doesn't support sharing across sources, we must initialize it
                    // with sources.
                    this.InitializeExtensions(discoveryCriteria.Sources);
                }

                this.SetupChannel(discoveryCriteria.Sources);
                this.RequestSender.DiscoverTests(discoveryCriteria, eventHandler);
            }
            catch (Exception exception)
            {
                eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.Message);
                eventHandler.HandleDiscoveryComplete(0, new List <ObjectModel.TestCase>(), false);
            }
        }
Пример #9
0
        /// <summary>
        /// The create discovery request.
        /// </summary>
        /// <param name="discoveryCriteria"> The discovery criteria. </param>
        /// <returns> The <see cref="IDiscoveryRequest"/>. </returns>
        /// <exception cref="ArgumentNullException"> Throws if parameter is null. </exception>
        public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria)
        {
            if (discoveryCriteria == null)
            {
                throw new ArgumentNullException("discoveryCriteria");
            }

            UpdateTestAdapterPaths(discoveryCriteria.RunSettings);

            var runconfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings);
            //var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(runconfiguration);

            var testHostManager = this.TestEngine.GetDefaultTestHostManager(runconfiguration);

            var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria);

            discoveryManager.Initialize();

            return(new DiscoveryRequest(discoveryCriteria, discoveryManager));
        }
Пример #10
0
        public void DiscoverTestsShouldLogIfThereAreNoValidSources()
        {
            var sources = new List <string> {
                "imaginary.dll"
            };
            var criteria   = new DiscoveryCriteria(sources, 100, null);
            var mockLogger = new Mock <ITestDiscoveryEventsHandler2>();

            this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);

            var sourcesString = string.Join(",", sources.ToArray());
            var errorMessage  = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.NoValidSourceFoundForDiscovery, sourcesString);

            mockLogger.Verify(
                l =>
                l.HandleLogMessage(
                    Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning,
                    errorMessage),
                Times.Once);
        }
Пример #11
0
        /// <summary>
        /// The create discovery request.
        /// </summary>
        /// <param name="discoveryCriteria"> The discovery criteria. </param>
        /// <param name="protocolConfig"> Protocol related information.  </param>
        /// <returns> The <see cref="IDiscoveryRequest"/>. </returns>
        /// <exception cref="ArgumentNullException"> Throws if parameter is null. </exception>
        public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig)
        {
            if (discoveryCriteria == null)
            {
                throw new ArgumentNullException(nameof(discoveryCriteria));
            }

            // Update cache with Extension Folder's files
            this.AddExtensionAssemblies(discoveryCriteria.RunSettings);

            var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

            testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

            var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria, protocolConfig);

            discoveryManager.Initialize();

            return(new DiscoveryRequest(discoveryCriteria, discoveryManager));
        }
        public void DiscoverTestsShouldUpdateTestPluginCacheWithExtensionsReturnByTestHost()
        {
            var manualResetEvent = new ManualResetEvent(false);

            this.mockDiscoveryManager.Setup(o => o.Initialize(Enumerable.Empty <string>(), null)).Callback(
                () => manualResetEvent.Set());

            this.mockTestHostManager.Setup(o => o.GetTestPlatformExtensions(It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <string> >())).Returns(new List <string> {
                "C:\\DiscoveryDummy.dll"
            });
            var expectedResult = TestPluginCache.Instance.GetExtensionPaths(string.Empty);

            expectedResult.Add("C:\\DiscoveryDummy.dll");
            var discoveryCriteria = new DiscoveryCriteria(new[] { "test.dll" }, 1, string.Empty);

            this.inProcessProxyDiscoveryManager.DiscoverTests(discoveryCriteria, null);

            Assert.IsTrue(manualResetEvent.WaitOne(5000), "DiscoverTests should call Initialize");
            CollectionAssert.AreEquivalent(expectedResult, TestPluginCache.Instance.GetExtensionPaths(string.Empty));
        }
Пример #13
0
        public void DiscoverTestsErrorScenarioTestTemplates(string errorMessage, Action <string> exitCallback)
        {
            var sources = new List <string>()
            {
                "Hello", "World"
            };
            string settingsXml       = "SettingsXml";
            var    mockHandler       = new Mock <ITestDiscoveryEventsHandler>();
            var    discoveryCriteria = new DiscoveryCriteria(sources, 100, settingsXml);

            this.mockCommunicationManager.Setup(cm => cm.ReceiveRawMessageAsync(It.IsAny <CancellationToken>())).
            Returns(Task.FromResult((string)null)).Callback(() => exitCallback(errorMessage));

            this.testRequestSender.InitializeCommunication();
            this.testRequestSender.DiscoverTests(discoveryCriteria, mockHandler.Object);

            mockHandler.Verify(mh => mh.HandleDiscoveryComplete(-1, null, true), Times.Once);
            mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Error, string.Format(CommunicationUtilitiesResources.AbortedTestDiscovery, errorMessage)), Times.Once);
            mockHandler.Verify(mh => mh.HandleRawMessage(It.IsAny <string>()), Times.Exactly(2));
        }
Пример #14
0
        /// <summary>
        /// Triggers the discovery for the next data object on the concurrent discoverer
        /// Each concurrent discoverer calls this method, once its completed working on previous data
        /// </summary>
        /// <param name="ProxyDiscoveryManager">Proxy discovery manager instance.</param>
        private void DiscoverTestsOnConcurrentManager(IProxyDiscoveryManager proxyDiscoveryManager)
        {
            // Peek to see if we have sources to trigger a discovery
            if (this.TryFetchNextSource(this.sourceEnumerator, out string nextSource))
            {
                if (EqtTrace.IsVerboseEnabled)
                {
                    EqtTrace.Verbose("ProxyParallelDiscoveryManager: Triggering test discovery for next source: {0}", nextSource);
                }

                // Kick off another discovery task for the next source
                var discoveryCriteria = new DiscoveryCriteria(new[] { nextSource }, this.actualDiscoveryCriteria.FrequencyOfDiscoveredTestsEvent, this.actualDiscoveryCriteria.DiscoveredTestEventTimeout, this.actualDiscoveryCriteria.RunSettings);
                Task.Run(() =>
                {
                    if (EqtTrace.IsVerboseEnabled)
                    {
                        EqtTrace.Verbose("ParallelProxyDiscoveryManager: Discovery started.");
                    }

                    proxyDiscoveryManager.DiscoverTests(discoveryCriteria, this.GetHandlerForGivenManager(proxyDiscoveryManager));
                })
                .ContinueWith(t =>
                {
                    // Just in case, the actual discovery couldn't start for an instance. Ensure that
                    // we call discovery complete since we have already fetched a source. Otherwise
                    // discovery will not terminate
                    if (EqtTrace.IsWarningEnabled)
                    {
                        EqtTrace.Warning("ParallelProxyDiscoveryManager: Failed to trigger discovery. Exception: " + t.Exception);
                    }

                    this.GetHandlerForGivenManager(proxyDiscoveryManager).HandleDiscoveryComplete(0, Enumerable.Empty <TestCase>(), true);
                },
                              TaskContinuationOptions.OnlyOnFaulted);
            }

            if (EqtTrace.IsVerboseEnabled)
            {
                EqtTrace.Verbose("ProxyParallelDiscoveryManager: No sources available for discovery.");
            }
        }
Пример #15
0
        public void GetDiscoveryManagerShouldReturnsInProcessProxyDiscoveryManager()
        {
            string settingXml =
                @"<RunSettings>
                    <RunConfiguration>
                        <TargetPlatform>x86</TargetPlatform>
                        <DisableAppDomain>false</DisableAppDomain>
                        <DesignMode>false</DesignMode>
                        <TargetFrameworkVersion>.NETFramework, Version=v4.5</TargetFrameworkVersion>
                    </RunConfiguration >
                 </RunSettings>";

            var discoveryCriteria = new DiscoveryCriteria(new List <string> {
                "1.dll"
            }, 100, settingXml);

            var discoveryManager = this.testEngine.GetDiscoveryManager(this.mockRequestData.Object, this.testableTestRuntimeProvider, discoveryCriteria, this.protocolConfig);

            Assert.IsNotNull(discoveryManager);
            Assert.IsInstanceOfType(discoveryManager, typeof(InProcessProxyDiscoveryManager));
        }
Пример #16
0
        /// <inheritdoc/>
        public IDiscoveryRequest CreateDiscoveryRequest(
            IRequestData requestData,
            DiscoveryCriteria discoveryCriteria,
            TestPlatformOptions options)
        {
            if (discoveryCriteria == null)
            {
                throw new ArgumentNullException(nameof(discoveryCriteria));
            }

            // Update cache with Extension folder's files.
            this.AddExtensionAssemblies(discoveryCriteria.RunSettings);

            // Update extension assemblies from source when design mode is false.
            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings);

            if (!runConfiguration.DesignMode)
            {
                this.AddExtensionAssembliesFromSource(discoveryCriteria.Sources);
            }

            // Initialize loggers.
            var loggerManager = this.TestEngine.GetLoggerManager(requestData);

            loggerManager.Initialize(discoveryCriteria.RunSettings);

            SubscribeLogger(loggerManager, this.VStestLoggerManager);

            var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

            ThrowExceptionIfTestHostManagerIsNull(testHostManager, discoveryCriteria.RunSettings);

            testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

            var discoveryManager = this.TestEngine.GetDiscoveryManager(requestData, testHostManager, discoveryCriteria);

            discoveryManager.Initialize(options?.SkipDefaultAdapters ?? false);

            return(new DiscoveryRequest(requestData, discoveryCriteria, discoveryManager, loggerManager));
        }
Пример #17
0
        public void DiscoveryRequestRaiseShouldInvokeDiscoveryStartHandlerOfLoggersOnlyIfRegistered()
        {
            counter = 0;
            waitHandle.Reset();

            DiscoveryCriteria discoveryCriteria = new DiscoveryCriteria()
            {
                TestCaseFilter = "Name=Test1"
            };
            DiscoveryStartEventArgs discoveryStartEventArgs = new DiscoveryStartEventArgs(discoveryCriteria);

            // mock for IDiscoveryRequest
            var discoveryRequest = new Mock <IDiscoveryRequest>();

            // setup TestLogger
            TestLoggerManager.Instance.AddLogger(new Uri(loggerUri), new Dictionary <string, string>());
            TestLoggerManager.Instance.EnableLogging();

            // Register DiscoveryRequest object
            TestLoggerManager.Instance.RegisterDiscoveryEvents(discoveryRequest.Object);

            //Raise an event on mock object
            discoveryRequest.Raise(
                m => m.OnDiscoveryStart += null,
                discoveryStartEventArgs);

            // Assertions when discovery events registered
            waitHandle.WaitOne();
            Assert.AreEqual(counter, 1);

            // Unregister DiscoveryRequest object
            TestLoggerManager.Instance.UnregisterDiscoveryEvents(discoveryRequest.Object);

            //Raise an event on mock object
            discoveryRequest.Raise(
                m => m.OnDiscoveryStart += null,
                discoveryStartEventArgs);
            // Assertions when discovery events unregistered
            Assert.AreEqual(counter, 1);
        }
Пример #18
0
        public void CreateDiscoveryRequestShouldInitializeLoggerManagerForNonDesignMode()
        {
            this.testEngine.Setup(te => te.GetDiscoveryManager(this.mockRequestData.Object, this.hostManager.Object, It.IsAny <DiscoveryCriteria>())).Returns(this.discoveryManager.Object);
            this.testEngine.Setup(te => te.GetLoggerManager(this.mockRequestData.Object)).Returns(this.loggerManager.Object);

            string settingsXml =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                <RunSettings>
                     <RunConfiguration>
                       <DesignMode>False</DesignMode>
                     </RunConfiguration>
                </RunSettings>";
            var discoveryCriteria = new DiscoveryCriteria(new List <string> {
                "foo"
            }, 10, settingsXml);

            var tp = new TestableTestPlatform(this.testEngine.Object, this.hostManager.Object);

            tp.CreateDiscoveryRequest(this.mockRequestData.Object, discoveryCriteria);

            this.loggerManager.Verify(lm => lm.Initialize(settingsXml));
        }
Пример #19
0
        public ProxyDiscoveryManagerTests()
        {
            this.mockTestHostManager  = new Mock <ITestRuntimeProvider>();
            this.mockRequestSender    = new Mock <ITestRequestSender>();
            this.mockDataSerializer   = new Mock <IDataSerializer>();
            this.testDiscoveryManager = new ProxyDiscoveryManager(
                this.mockRequestSender.Object,
                this.mockTestHostManager.Object,
                this.mockDataSerializer.Object,
                this.testableClientConnectionTimeout);
            this.discoveryCriteria = new DiscoveryCriteria(new[] { "test.dll" }, 1, string.Empty);

            // Default setup test host manager as shared (desktop)
            this.mockTestHostManager.SetupGet(th => th.Shared).Returns(true);
            this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny <TestProcessStartInfo>(), It.IsAny <CancellationToken>()))
            .Callback(
                () =>
            {
                this.mockTestHostManager.Raise(thm => thm.HostLaunched += null, new HostProviderEventArgs(string.Empty));
            })
            .Returns(Task.FromResult(true));
        }
Пример #20
0
        public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.DuckOthers);
            var discoveryCriteria = new DiscoveryCriteria("0A6928D1");
            var options           = new CastOptions(discoveryCriteria);

            CastContext.SetSharedInstance(options);
            Logger.SharedInstance.Delegate = new LoggerDelegate();


            var navigationController = new UINavigationController(new CastVideoListViewController());
            var castContainer        = CastContext.SharedInstance.CreateCastContainerController(navigationController);

            castContainer.MiniMediaControlsItemEnabled = true;

            CastContext.SharedInstance.UseDefaultExpandedMediaControls = true;

            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            Window.RootViewController = castContainer;
            Window.MakeKeyAndVisible();
            return(true);
        }
Пример #21
0
        public void DiscoverTestsShouldSendMetricsOnDiscoveryComplete()
        {
            var metricsCollector = new MetricsCollection();

            metricsCollector.Add("DummyMessage", "DummyValue");

            this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(metricsCollector);

            DiscoveryCompleteEventArgs receivedDiscoveryCompleteEventArgs = null;

            TestPluginCacheHelper.SetupMockExtensions(
                new string[] { typeof(DiscovererEnumeratorTests).GetTypeInfo().Assembly.Location },
                () => { });

            var sources = new List <string>
            {
                typeof(DiscoveryManagerTests).GetTypeInfo().Assembly.Location
            };

            var mockLogger = new Mock <ITestDiscoveryEventsHandler2>();
            var criteria   = new DiscoveryCriteria(sources, 1, null);

            mockLogger.Setup(ml => ml.HandleDiscoveryComplete(It.IsAny <DiscoveryCompleteEventArgs>(), It.IsAny <IEnumerable <TestCase> >()))
            .Callback(
                (DiscoveryCompleteEventArgs complete,
                 IEnumerable <TestCase> tests) =>
            {
                receivedDiscoveryCompleteEventArgs = complete;
            });

            // Act.
            this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);

            // Assert
            Assert.IsNotNull(receivedDiscoveryCompleteEventArgs.Metrics);
            Assert.IsTrue(receivedDiscoveryCompleteEventArgs.Metrics.Any());
            Assert.IsTrue(receivedDiscoveryCompleteEventArgs.Metrics.ContainsKey("DummyMessage"));
        }
Пример #22
0
        public void CreateDiscoveryRequestShouldUpdateLoggerExtensionWhenDesignModeIsFalse()
        {
            var additionalExtensions = new List <string> {
                "foo.TestLogger.dll", "Joo.TestLogger.dll"
            };

            this.mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny <string>())).Returns(true);
            this.mockFileHelper.Setup(fh => fh.EnumerateFiles(It.IsAny <string>(), System.IO.SearchOption.TopDirectoryOnly, It.IsAny <string[]>())).Returns(additionalExtensions);

            this.discoveryManager.Setup(dm => dm.Initialize(false)).Verifiable();

            string settingsXml =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                <RunSettings>
                     <RunConfiguration>
                       <DesignMode>false</DesignMode>
                     </RunConfiguration>
                </RunSettings>";

            var temp = Path.GetTempPath();
            var discoveryCriteria = new DiscoveryCriteria(new List <string> {
                $@"{temp}foo.dll"
            }, 1, settingsXml);

            this.hostManager.Setup(hm => hm.GetTestSources(discoveryCriteria.Sources))
            .Returns(discoveryCriteria.Sources);

            this.testEngine.Setup(te => te.GetDiscoveryManager(It.IsAny <IRequestData>(), this.hostManager.Object, It.IsAny <DiscoveryCriteria>())).Returns(this.discoveryManager.Object);
            this.testEngine.Setup(te => te.GetExtensionManager()).Returns(this.extensionManager.Object);
            this.testEngine.Setup(te => te.GetLoggerManager(this.mockRequestData.Object)).Returns(this.loggerManager.Object);
            var tp = new TestableTestPlatform(this.testEngine.Object, this.mockFileHelper.Object, this.hostManager.Object);

            // Action
            var discoveryRequest = tp.CreateDiscoveryRequest(this.mockRequestData.Object, discoveryCriteria, new TestPlatformOptions());

            // Verify
            this.extensionManager.Verify(em => em.UseAdditionalExtensions(additionalExtensions, false));
        }
Пример #23
0
        /// <summary>
        /// Triggers the discovery for the next data object on the concurrent discoverer
        /// Each concurrent discoverer calls this method, once its completed working on previous data
        /// </summary>
        /// <param name="ProxyDiscoveryManager">Proxy discovery manager instance.</param>
        /// <returns>True, if discovery triggered</returns>
        private bool DiscoverTestsOnConcurrentManager(IProxyDiscoveryManager proxyDiscoveryManager)
        {
            DiscoveryCriteria discoveryCriteria = null;

            string nextSource = null;

            if (this.TryFetchNextSource(this.sourceEnumerator, out nextSource))
            {
                EqtTrace.Info("ProxyParallelDiscoveryManager: Triggering test discovery for next source: {0}", nextSource);
                discoveryCriteria = new DiscoveryCriteria(new List <string>()
                {
                    nextSource
                }, this.actualDiscoveryCriteria.FrequencyOfDiscoveredTestsEvent, this.actualDiscoveryCriteria.DiscoveredTestEventTimeout, this.actualDiscoveryCriteria.RunSettings);
            }

            if (discoveryCriteria != null)
            {
                proxyDiscoveryManager.DiscoverTests(discoveryCriteria, this.concurrentManagerHandlerMap[proxyDiscoveryManager]);
                return(true);
            }

            return(false);
        }
Пример #24
0
        /// <summary>
        /// The create discovery request.
        /// </summary>
        /// <param name="discoveryCriteria"> The discovery criteria. </param>
        /// <param name="protocolConfig"> Protocol related information.  </param>
        /// <returns> The <see cref="IDiscoveryRequest"/>. </returns>
        /// <exception cref="ArgumentNullException"> Throws if parameter is null. </exception>
        public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCriteria, ProtocolConfig protocolConfig)
        {
            if (discoveryCriteria == null)
            {
                throw new ArgumentNullException(nameof(discoveryCriteria));
            }

            // Update cache with Extension Folder's files
            this.AddExtensionAssemblies(discoveryCriteria.RunSettings);

            var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

            testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

            // Allow TestRuntimeProvider to update source map, this is required for remote scenarios.
            UpdateTestSources(discoveryCriteria.Sources, discoveryCriteria.AdapterSourceMap, testHostManager);

            var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria, protocolConfig);

            discoveryManager.Initialize();

            return(new DiscoveryRequest(discoveryCriteria, discoveryManager));
        }
Пример #25
0
        public void DiscoverTestsShouldLogIfTheSourceDoesNotExistIfItHasAPackage()
        {
            var criteria = new DiscoveryCriteria(new List <string> {
                "imaginary.exe"
            }, 100, null);

            var packageName = "recipe.AppxRecipe";

            var fakeDirectory = Directory.GetDirectoryRoot(typeof(DiscoveryManagerTests).GetTypeInfo().Assembly.Location);

            criteria.Package = Path.Combine(fakeDirectory, Path.Combine(packageName));
            var mockLogger = new Mock <ITestDiscoveryEventsHandler2>();

            this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);

            var errorMessage = string.Format(CultureInfo.CurrentCulture, "Could not find file {0}.", Path.Combine(fakeDirectory, "imaginary.exe"));

            mockLogger.Verify(
                l =>
                l.HandleLogMessage(
                    Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning,
                    errorMessage),
                Times.Once);
        }
        public void DiscoverTestsShouldNotUpdateTestSourcesIfSourceDoNotDifferFromTestHostManagerSource()
        {
            var actualSources = new List <string> {
                "actualSource.dll"
            };
            var inputSource = new List <string> {
                "actualSource.dll"
            };

            var localDiscoveryCriteria = new DiscoveryCriteria(inputSource, 1, string.Empty);

            this.mockTestHostManager.Setup(hm => hm.GetTestSources(localDiscoveryCriteria.Sources)).Returns(actualSources);
            this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny <TestProcessStartInfo>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(true));
            this.mockTestHostManager.Setup(th => th.GetTestPlatformExtensions(It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <string> >())).Returns(new List <string>());
            this.mockRequestSender.Setup(s => s.WaitForRequestHandlerConnection(It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(true);

            Mock <ITestDiscoveryEventsHandler2> mockTestDiscoveryEventHandler = new Mock <ITestDiscoveryEventsHandler2>();

            this.testDiscoveryManager.DiscoverTests(localDiscoveryCriteria, mockTestDiscoveryEventHandler.Object);

            Assert.IsNull(localDiscoveryCriteria.Package);
            // AdapterSourceMap should contain updated testSources.
            Assert.AreEqual(actualSources.FirstOrDefault(), localDiscoveryCriteria.AdapterSourceMap.FirstOrDefault().Value.FirstOrDefault());
        }
Пример #27
0
        public ProxyDiscoveryManagerTests()
        {
            this.mockTestHostManager   = new Mock <ITestRuntimeProvider>();
            this.mockRequestSender     = new Mock <ITestRequestSender>();
            this.mockDataSerializer    = new Mock <IDataSerializer>();
            this.mockRequestData       = new Mock <IRequestData>();
            this.mockMetricsCollection = new Mock <IMetricsCollection>();
            this.mockRequestData.Setup(rd => rd.MetricsCollection).Returns(this.mockMetricsCollection.Object);

            this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(null)).Returns(new Message());
            this.mockDataSerializer.Setup(mds => mds.DeserializeMessage(string.Empty)).Returns(new Message());

            this.testDiscoveryManager = new ProxyDiscoveryManager(
                this.mockRequestData.Object,
                this.mockRequestSender.Object,
                this.mockTestHostManager.Object,
                this.mockDataSerializer.Object,
                this.testableClientConnectionTimeout);
            this.discoveryCriteria = new DiscoveryCriteria(new[] { "test.dll" }, 1, string.Empty);

            // Default setup test host manager as shared (desktop)
            this.mockTestHostManager.SetupGet(th => th.Shared).Returns(true);
            this.mockTestHostManager.Setup(
                m => m.GetTestHostProcessStartInfo(
                    It.IsAny <IEnumerable <string> >(),
                    It.IsAny <IDictionary <string, string> >(),
                    It.IsAny <TestRunnerConnectionInfo>()))
            .Returns(new TestProcessStartInfo());
            this.mockTestHostManager.Setup(tmh => tmh.LaunchTestHostAsync(It.IsAny <TestProcessStartInfo>(), It.IsAny <CancellationToken>()))
            .Callback(
                () =>
            {
                this.mockTestHostManager.Raise(thm => thm.HostLaunched += null, new HostProviderEventArgs(string.Empty));
            })
            .Returns(Task.FromResult(true));
        }
Пример #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DiscoveryRequest"/> class.
 /// </summary>
 /// <param name="requestData">The Request Data instance providing services and data for discovery</param>
 /// <param name="criteria">Discovery criterion.</param>
 /// <param name="discoveryManager">Discovery manager instance.</param>
 internal DiscoveryRequest(IRequestData requestData, DiscoveryCriteria criteria, IProxyDiscoveryManager discoveryManager, ITestLoggerManager loggerManager)
     : this(requestData, criteria, discoveryManager, loggerManager, JsonDataSerializer.Instance)
 {
 }
Пример #29
0
        /// <summary>
        /// Discover Tests given a list of sources, run settings.
        /// </summary>
        /// <param name="discoveryPayload">Discovery payload</param>
        /// <param name="discoveryEventsRegistrar">EventHandler for discovered tests</param>
        /// <param name="protocolConfig">Protocol related information</param>
        /// <returns>True, if successful</returns>
        public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscoveryEventsRegistrar discoveryEventsRegistrar, ProtocolConfig protocolConfig)
        {
            EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests started.");

            var runsettings = discoveryPayload.RunSettings;

            if (discoveryPayload.TestPlatformOptions != null)
            {
                this.telemetryOptedIn = discoveryPayload.TestPlatformOptions.CollectMetrics;
            }

            var requestData = this.GetRequestData(protocolConfig);

            if (this.UpdateRunSettingsIfRequired(runsettings, discoveryPayload.Sources?.ToList(), out string updatedRunsettings))
            {
                runsettings = updatedRunsettings;
            }

            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);
            var batchSize        = runConfiguration.BatchSize;

            if (requestData.IsTelemetryOptedIn)
            {
                // Collect Metrics
                this.CollectMetrics(requestData, runConfiguration);

                // Collect Commands
                this.LogCommandsTelemetryPoints(requestData);
            }

            // create discovery request
            var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, runsettings);

            criteria.TestCaseFilter = this.commandLineOptions.TestCaseFilterValue;

            try
            {
                using (IDiscoveryRequest discoveryRequest = this.testPlatform.CreateDiscoveryRequest(requestData, criteria, discoveryPayload.TestPlatformOptions))
                {
                    try
                    {
                        discoveryEventsRegistrar?.RegisterDiscoveryEvents(discoveryRequest);

                        this.testPlatformEventSource.DiscoveryRequestStart();

                        discoveryRequest.DiscoverAsync();
                        discoveryRequest.WaitForCompletion();
                    }

                    finally
                    {
                        discoveryEventsRegistrar?.UnregisterDiscoveryEvents(discoveryRequest);
                    }
                }
            }
            finally
            {
                EqtTrace.Info("TestRequestManager.DiscoverTests: Discovery tests completed.");
                this.testPlatformEventSource.DiscoveryRequestStop();

                // Posts the Discovery Complete event.
                this.metricsPublisher.Result.PublishMetrics(TelemetryDataConstants.TestDiscoveryCompleteEvent, requestData.MetricsCollection.Metrics);
            }
        }
Пример #30
0
        /// <inheritdoc />
        public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 discoveryEventsHandler)
        {
            this.messageEventHandler = discoveryEventsHandler;
            this.onDisconnected      = (disconnectedEventArgs) =>
            {
                this.OnDiscoveryAbort(discoveryEventsHandler, disconnectedEventArgs.Error, true);
            };
            this.onMessageReceived = (sender, args) =>
            {
                try
                {
                    var rawMessage = args.Data;

                    // Currently each of the operations are not separate tasks since they should not each take much time. This is just a notification.
                    if (EqtTrace.IsInfoEnabled)
                    {
                        EqtTrace.Info("TestRequestSender: Received message: {0}", rawMessage);
                    }

                    // Send raw message first to unblock handlers waiting to send message to IDEs
                    discoveryEventsHandler.HandleRawMessage(rawMessage);

                    var data = this.dataSerializer.DeserializeMessage(rawMessage);
                    switch (data.MessageType)
                    {
                    case MessageType.TestCasesFound:
                        var testCases = this.dataSerializer.DeserializePayload <IEnumerable <TestCase> >(data);
                        discoveryEventsHandler.HandleDiscoveredTests(testCases);
                        break;

                    case MessageType.DiscoveryComplete:
                        var discoveryCompletePayload =
                            this.dataSerializer.DeserializePayload <DiscoveryCompletePayload>(data);

                        var discoveryCompleteEventsArgs = new DiscoveryCompleteEventArgs(discoveryCompletePayload.TotalTests, discoveryCompletePayload.IsAborted, discoveryCompletePayload.Metrics);

                        discoveryEventsHandler.HandleDiscoveryComplete(
                            discoveryCompleteEventsArgs,
                            discoveryCompletePayload.LastDiscoveredTests);

                        this.SetOperationComplete();
                        break;

                    case MessageType.TestMessage:
                        var testMessagePayload = this.dataSerializer.DeserializePayload <TestMessagePayload>(
                            data);
                        discoveryEventsHandler.HandleLogMessage(
                            testMessagePayload.MessageLevel,
                            testMessagePayload.Message);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    this.OnDiscoveryAbort(discoveryEventsHandler, ex, false);
                }
            };

            this.channel.MessageReceived += this.onMessageReceived;
            var message = this.dataSerializer.SerializePayload(
                MessageType.StartDiscovery,
                discoveryCriteria,
                this.protocolVersion);

            this.channel.Send(message);
        }