Beispiel #1
0
        private void OnProjectItemChanged(object sender, TestFileChangedEventArgs e)
        {
            if (String.IsNullOrEmpty(e.File))
            {
                return;
            }

            if (IsSettingsFile(e.File))
            {
                switch (e.ChangedReason)
                {
                case TestFileChangedReason.None:
                    break;

                case TestFileChangedReason.Renamed:
                    _testFilesUpdateWatcher.RemoveWatch(e.OldFile);
                    _testFilesUpdateWatcher.AddWatch(e.File);
                    break;

                case TestFileChangedReason.Added:
                    _testFilesUpdateWatcher.AddWatch(e.File);
                    break;

                case TestFileChangedReason.Changed:
                    _testFilesUpdateWatcher.AddWatch(e.File);
                    break;

                case TestFileChangedReason.Removed:
                    _testFilesUpdateWatcher.RemoveWatch(e.File);
                    break;
                }

                _isRefresh = true;
                NotifyContainerChanged();
                return;
            }

            // VS uses temp files we need to ignore
            if (!IsTestFile(e.File))
            {
                return;
            }

            // bschnurr todo: this is only looking at opened files
            IVsProject vsProject = e.Project;

            if (vsProject == null)
            {
                var rdt = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable));
                vsProject = VsProjectExtensions.PathToProject(e.File, rdt);
            }

            if (vsProject == null)
            {
                return;
            }

            string projectHome = vsProject.GetProjectHome();

            if (projectHome != null &&
                _projectMap.TryGetValue(projectHome, out ProjectInfo projectInfo))
            {
                var sources = new List <string>()
                {
                    e.File
                };

                switch (e.ChangedReason)
                {
                case TestFileChangedReason.Added:
                    UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: true);
                    break;

                case TestFileChangedReason.Changed:
                    //Need to increment version number so Test Explorer notices a change
                    UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: true);
                    break;

                case TestFileChangedReason.Removed:
                    UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: false);
                    break;

                case TestFileChangedReason.Renamed:
                    UpdateSolutionTestContainersAndFileWatchers(new List <string>()
                    {
                        e.OldFile
                    }, projectInfo, isAdd: false);
                    UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: true);
                    break;

                default:
                    //In changed case file watcher observed a file changed event
                    //In this case we just have to fire TestContainerChnaged event
                    break;
                }
                NotifyContainerChanged();
            }
        }