public ProjectController(IProjectTreeModel projectTreeModel, IEventAggregator eventAggregator, IFileSystem fileSystem,
                                 IFileWatcher fileWatcher, IUnhandledExceptionPolicy unhandledExceptionPolicy, ITestProjectManager testProjectManager)
        {
            this.projectTreeModel         = projectTreeModel;
            this.eventAggregator          = eventAggregator;
            this.fileSystem               = fileSystem;
            this.fileWatcher              = fileWatcher;
            this.unhandledExceptionPolicy = unhandledExceptionPolicy;
            this.testProjectManager       = testProjectManager;

            TestFilters = new Observable <IList <FilterInfo> >(new List <FilterInfo>());
            TestFilters.PropertyChanged += (s, e) =>
            {
                if (updating)
                {
                    return;
                }

                projectTreeModel.TestProject.ClearTestFilters();
                GenericCollectionUtils.ForEach(TestFilters.Value, x =>
                                               projectTreeModel.TestProject.AddTestFilter(x));
            };

            fileWatcher.FileChangedEvent += delegate(string fullPath)
            {
                string fileName = Path.GetFileName(fullPath);
                EventHandlerPolicy.SafeInvoke(FileChanged, this, new FileChangedEventArgs(fileName));
            };
        }
 public void SetUp()
 {
     projectTreeModel = MockRepository.GenerateStub<IProjectTreeModel>();
     fileSystem = MockRepository.GenerateStub<IFileSystem>();
     fileWatcher = MockRepository.GenerateStub<IFileWatcher>();
     unhandledExceptionPolicy = MockRepository.GenerateStub<IUnhandledExceptionPolicy>();
     eventAggregator = MockRepository.GenerateStub<IEventAggregator>();
     testProjectManager = MockRepository.GenerateStub<ITestProjectManager>();
     
     projectController = new ProjectController(projectTreeModel, eventAggregator, fileSystem, fileWatcher, 
         unhandledExceptionPolicy, testProjectManager);
 }
        public void SetUp()
        {
            projectTreeModel         = MockRepository.GenerateStub <IProjectTreeModel>();
            fileSystem               = MockRepository.GenerateStub <IFileSystem>();
            fileWatcher              = MockRepository.GenerateStub <IFileWatcher>();
            unhandledExceptionPolicy = MockRepository.GenerateStub <IUnhandledExceptionPolicy>();
            eventAggregator          = MockRepository.GenerateStub <IEventAggregator>();
            testProjectManager       = MockRepository.GenerateStub <ITestProjectManager>();

            projectController = new ProjectController(projectTreeModel, eventAggregator, fileSystem, fileWatcher,
                                                      unhandledExceptionPolicy, testProjectManager);
        }
Exemple #4
0
        /// <summary>
        /// Processes test file patterns and generates a consolidated test project.
        /// </summary>
        private TestProject ConsolidateTestProject(ITestProjectManager testProjectManager, ref bool canceled)
        {
            TestProject consolidatedTestProject = null;

            RunWithProgress(delegate(IProgressMonitor progressMonitor)
            {
                List <string> allFilePatterns = new List <string>(filePatterns);
                GenericCollectionUtils.ConvertAndAddAll(testProject.TestPackage.Files, allFilePatterns, x => x.ToString());

                TestProject overlayTestProject = testProject.Copy();
                overlayTestProject.TestPackage.ClearFiles();
                TestProject baseTestProject = null;

                bool haveProject = false;
                using (progressMonitor.BeginTask("Verifying test files.", Math.Max(allFilePatterns.Count, 1)))
                {
                    foreach (string filePattern in allFilePatterns)
                    {
                        IList <FileInfo> files = ExpandFilePattern(filePattern);
                        if (files == null)
                        {
                            return;
                        }

                        foreach (FileInfo file in files)
                        {
                            bool isProject = file.Extension == TestProject.Extension;
                            if (isProject && overlayTestProject.TestPackage.Files.Count != 0 || haveProject)
                            {
                                logger.Log(LogSeverity.Error, "At most one test project can be specified at a time and it cannot be combined with other test files.");
                                return;
                            }

                            if (isProject)
                            {
                                haveProject = true;

                                try
                                {
                                    baseTestProject = testProjectManager.LoadProject(file);
                                }
                                catch (Exception ex)
                                {
                                    logger.Log(LogSeverity.Error, string.Format("Could not load test project '{0}'.", file.FullName), ex);
                                }
                            }
                            else
                            {
                                overlayTestProject.TestPackage.AddFile(file);
                            }
                        }

                        progressMonitor.Worked(1);
                    }

                    if (baseTestProject != null)
                    {
                        baseTestProject.ApplyOverlay(overlayTestProject);
                        consolidatedTestProject = baseTestProject;
                    }
                    else
                    {
                        consolidatedTestProject = overlayTestProject;
                    }
                }
            }, ref canceled);

            return(consolidatedTestProject);
        }
Exemple #5
0
        private TestLauncherResult RunWithRuntime()
        {
            bool wasCanceled = false;

            ITestProjectManager testProjectManager = RuntimeAccessor.ServiceLocator.Resolve <ITestProjectManager>();

            TestProject consolidatedTestProject = ConsolidateTestProject(testProjectManager, ref wasCanceled);

            if (wasCanceled)
            {
                return(CreateResult(ResultCode.Canceled, testProject));
            }
            if (consolidatedTestProject == null)
            {
                return(CreateResult(ResultCode.InvalidArguments, testProject));
            }

            if (consolidatedTestProject.TestPackage.Files.Count == 0)
            {
                logger.Log(LogSeverity.Warning, "No test files to execute!");
                return(CreateResult(ResultCode.NoTests, consolidatedTestProject));
            }

            IReportManager reportManager = RuntimeAccessor.ServiceLocator.Resolve <IReportManager>();

            if (!ValidateReportFormats(reportManager, consolidatedTestProject))
            {
                return(CreateResult(ResultCode.InvalidArguments, consolidatedTestProject));
            }

            ITestRunnerManager testRunnerManager = RuntimeAccessor.ServiceLocator.Resolve <ITestRunnerManager>();
            ITestRunnerFactory testRunnerFactory = testRunnerManager.GetFactory(consolidatedTestProject.TestRunnerFactoryName);

            if (testRunnerFactory == null)
            {
                logger.Log(LogSeverity.Error, String.Format("Unrecognized test runner factory name: '{0}'.", consolidatedTestProject.TestRunnerFactoryName));
                return(CreateResult(ResultCode.InvalidArguments, consolidatedTestProject));
            }

            ITestRunner runner = testRunnerFactory.CreateTestRunner();
            var         result = new TestLauncherResult(new Report {
                TestPackage = new TestPackageData(TestProject.TestPackage)
            });

            try
            {
                DoRegisterExtensions(runner, consolidatedTestProject);
                DoInitialize(runner, ref wasCanceled);

                if (!wasCanceled)
                {
                    result = RunWithInitializedRunner(runner, consolidatedTestProject, reportManager);
                }
            }
            finally
            {
                DoDispose(runner, ref wasCanceled);
            }

            if (wasCanceled)
            {
                result.SetResultCode(ResultCode.Canceled);
            }

            return(result);
        }