コード例 #1
0
        public void CancelTestDiscovery(RunnerInfo runnerInfo)
        {
            // Setup
            var testAssemblies = new List <string>
            {
                this.GetAssetFullPath("DiscoveryTestProject.dll"),
                this.GetAssetFullPath("SimpleTestProject.dll"),
                this.GetAssetFullPath("SimpleTestProject2.dll")
            };

            SetTestEnvironment(this.testEnvironment, runnerInfo);
            this.Setup();

            var discoveredTests = new List <TestCase>();
            var discoveryEvents = new Mock <ITestDiscoveryEventsHandler>();

            discoveryEvents.Setup((events) => events.HandleDiscoveredTests(It.IsAny <IEnumerable <TestCase> >())).Callback
                ((IEnumerable <TestCase> testcases) => { discoveredTests.AddRange(testcases); });

            // Act
            var discoveryTask = Task.Run(() =>
            {
                this.vstestConsoleWrapper.DiscoverTests(testAssemblies, this.GetDefaultRunSettings(), discoveryEvents.Object);
            });

            Task.Delay(2000).Wait();
            vstestConsoleWrapper.CancelDiscovery();
            discoveryTask.Wait();

            // Assert.
            int discoveredSources = discoveredTests.Select((testcase) => testcase.Source).Distinct().Count();

            Assert.AreNotEqual(testAssemblies.Count, discoveredSources, "All test assemblies discovered");
        }