Exemple #1
0
        public void ScanStopsWhenBuildBegins()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            accessor.IsListeningToBuildEvents = true;

            string firstFile  = Utilities.CreateBigFile();
            string secondFile = Utilities.CreateTempTxtFile("bar bar bar floop doop bar");
            string termTable  = Utilities.CreateTermTable(new string[] { "foo", "bar" });

            Microsoft.Build.Evaluation.Project project = Utilities.SetupMSBuildProject(new string[] { firstFile, secondFile }, new string[] { termTable });
            MockIVsProject vsProject = Utilities.RegisterProjectWithMocks(project, _serviceProvider);

            // Start a background scan.
            CodeSweep.VSPackage.IBackgroundScanner_Accessor scannerAccessor = CodeSweep.VSPackage.Factory_Accessor.GetBackgroundScanner();

            scannerAccessor.Start(new IVsProject[] { vsProject });

            // Fire the build begin event.
            MockDTE         dte         = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as MockDTE;
            MockBuildEvents buildEvents = dte.Events.BuildEvents as MockBuildEvents;

            buildEvents.FireOnBuildBegin(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);

            try
            {
                Assert.IsFalse(scannerAccessor.IsRunning, "Background scan did not stop when build began.");
            }
            finally
            {
                buildEvents.FireOnBuildDone(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);
                accessor.IsListeningToBuildEvents = false;
            }
        }
        public void MyTestCleanup()
        {
            Utilities.CleanUpTempFiles();
            Utilities.RemoveCommandHandlers(_serviceProvider);

            MockDTE dte = _serviceProvider.GetService(typeof(DTE)) as MockDTE;

            foreach (EnvDTE.Project project in dte.Solution.Projects)
            {
                MockDTEGlobals globals = project.Globals as MockDTEGlobals;
                globals.ClearAll();
            }
        }
Exemple #3
0
        public void TestBuildBegin()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            accessor.IsListeningToBuildEvents = true;

            // Listen for task list refresh events.
            List <int>   resultCounts = new List <int>();
            MockTaskList taskList     = _serviceProvider.GetService(typeof(SVsTaskList)) as MockTaskList;

            taskList.OnRefreshTasks += delegate(object sender, MockTaskList.RefreshTasksArgs args)
            {
                resultCounts.Add(Utilities.TasksOfProvider(args.Provider).Count);
            };

            // Create multiple projects with ScannerTask tasks.
            string scanFile  = Utilities.CreateTempTxtFile("foo abc foo def foo");
            string termTable = Utilities.CreateTermTable(new string[] { "foo", "bar" });

            Microsoft.Build.Evaluation.Project project1 = Utilities.SetupMSBuildProject(new string[] { scanFile }, new string[] { termTable });
            Microsoft.Build.Evaluation.Project project2 = Utilities.SetupMSBuildProject(new string[] { scanFile }, new string[] { termTable });

            Utilities.RegisterProjectWithMocks(project1, _serviceProvider);
            Utilities.RegisterProjectWithMocks(project2, _serviceProvider);

            // Fire the build begin event.
            MockDTE         dte         = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as MockDTE;
            MockBuildEvents buildEvents = dte.Events.BuildEvents as MockBuildEvents;

            buildEvents.FireOnBuildBegin(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);

            try
            {
                Assert.IsNotNull(ProjectCollection.GlobalProjectCollection.HostServices.GetHostObject(project1.FullPath, "AfterBuild", "ScannerTask"), "Host object for task in first project not set.");
                Assert.IsNotNull(ProjectCollection.GlobalProjectCollection.HostServices.GetHostObject(project2.FullPath, "AfterBuild", "ScannerTask"), "Host object for task in second project not set.");

                Assert.AreEqual(1, resultCounts.Count, "Task list recieved wrong number of refresh requests.");
                Assert.AreEqual(0, resultCounts[0], "Task list was not cleared.");
            }
            finally
            {
                buildEvents.FireOnBuildDone(vsBuildScope.vsBuildScopeProject, vsBuildAction.vsBuildActionBuild);
            }
        }
        public void TermTables()
        {
            MockSolution   solution  = _serviceProvider.GetService(typeof(SVsSolution)) as MockSolution;
            MockIVsProject vsProject = new MockIVsProject("c:\\temp.proj");

            solution.AddProject(vsProject);

            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(0, accessor.TermTableFiles.Count, "TermTableFiles not initially empty.");

            accessor.CreateDefaultConfiguration();

            Assert.AreEqual(1, accessor.TermTableFiles.Count, "TermTableFiles wrong size after CreateDefaultConfiguration.");

            MockDTE        dte     = _serviceProvider.GetService(typeof(DTE)) as MockDTE;
            MockDTEGlobals globals = dte.Solution.Projects.Item(0).Globals as MockDTEGlobals;

            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor2 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(1, accessor2.TermTableFiles.Count, "CreateDefaultConfiguration changes did not persist.");

            accessor.TermTableFiles.Remove(Utilities.ListFromEnum(accessor.TermTableFiles)[0]);
            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor3 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(0, accessor3.TermTableFiles.Count, "Deletion did not persist.");

            accessor.TermTableFiles.Add("c:\\foo");
            accessor.TermTableFiles.Add("c:\\bar");
            globals.ClearNonPersistedVariables();

            // Create a new proj config store to see if the change was persisted.
            CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor accessor4 = new CodeSweep.VSPackage.NonMSBuildProjectConfigStore_Accessor(vsProject, _serviceProvider);

            Assert.AreEqual(2, accessor4.TermTableFiles.Count, "Additions did not persist.");
        }
Exemple #5
0
        public void IsListeningToBuildEventsTest()
        {
            CodeSweep.VSPackage.BuildManager_Accessor accessor = new CodeSweep.VSPackage.BuildManager_Accessor(_serviceProvider);

            MockDTE         dte         = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as MockDTE;
            MockBuildEvents buildEvents = dte.Events.BuildEvents as MockBuildEvents;

            Assert.IsFalse(accessor.IsListeningToBuildEvents, "IsListeningToBuildEvents should be false by default.");

            int expectedSubscriberCount = buildEvents.OnBuildBeginSubscriberCount + 1;

            accessor.IsListeningToBuildEvents = true;
            Assert.IsTrue(accessor.IsListeningToBuildEvents, "IsListeningToBuildEvents could not be set to true.");
            Assert.AreEqual(expectedSubscriberCount, buildEvents.OnBuildBeginSubscriberCount, "Build manager did not subscribe to OnBuildBegin when IsListeningToBuildEvents set to true.");

            accessor.IsListeningToBuildEvents = false;
            expectedSubscriberCount--;
            Assert.IsFalse(accessor.IsListeningToBuildEvents, "IsListeningToBuildEvents could not be set to false.");
            Assert.AreEqual(expectedSubscriberCount, buildEvents.OnBuildBeginSubscriberCount, "Build manager did not unsubscribe from OnBuildBegin when IsListeningToBuildEvents set to false.");
        }
Exemple #6
0
 public MockServiceProvider()
 {
     _menuService = new OleMenuCommandService(this);
     _dte         = new MockDTE(this);
 }