public void ShouldGetEmptyLinkedProjectList()
        {
            MockIVsSolution            solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker  = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);

            IEnumerable <ProjectLink> projectLinks = tracker.GetProjectLinks();

            Assert.IsNotNull(projectLinks);
            Assert.AreEqual(0, projectLinks.Count());
        }
        public void ShouldThrowIfAddingSameLink()
        {
            MockIVsSolution            solution            = new MockIVsSolution();
            TestableProjectLinkTracker tracker             = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            project1VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project2VsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy, project2VsHierarchy);
            tracker.AddProjectLink(project1VsHierarchy, project2VsHierarchy);
        }
        public void ShouldAddNewItemsToSync()
        {
            MockIVsSolution            solution            = new MockIVsSolution();
            TestableProjectLinkTracker tracker             = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            project1VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project2VsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy.GetPropertyProjectIdGuidValue, project2VsHierarchy.GetPropertyProjectIdGuidValue);

            Assert.IsTrue(tracker.ProjectsAreLinked(project1VsHierarchy, project2VsHierarchy));
            Assert.IsFalse(tracker.ProjectsAreLinked(project2VsHierarchy, project1VsHierarchy));
        }
        public void ShouldNotLinkIfTargetIsAlreadyASource()
        {
            MockIVsSolution            solution            = new MockIVsSolution();
            TestableProjectLinkTracker tracker             = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            project1VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project2VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project3VsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);
            solution.Hierarchies.Add(project3VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy, project3VsHierarchy);
            tracker.AddProjectLink(project2VsHierarchy, project1VsHierarchy);
        }
        public void ShouldDispatchRemoveDirectoriesToSyncher()
        {
            TestableProjectLinkTracker tracker  = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            MockVsHierarchy            project1 = new MockVsHierarchy();
            MockVsHierarchy            project2 = new MockVsHierarchy();

            MockProjectItemsSyncer syncher = new MockProjectItemsSyncer(project1.GetPropertyProjectValue, project2.GetPropertyProjectValue);

            tracker.AddProjectSyncer(syncher);

            tracker.OnAfterRemoveDirectories(1, 1, new[] { project1 }, new[] { 0 }, new[] { "Myfolder" },
                                             new[] { VSREMOVEDIRECTORYFLAGS.VSREMOVEDIRECTORYFLAGS_NoFlags });

            Assert.IsTrue(syncher.DirectoriesRemovedFromSourceCalled);
        }
        public void ShouldDispatchAddToSyncher()
        {
            TestableProjectLinkTracker tracker  = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            MockVsHierarchy            project1 = new MockVsHierarchy();
            MockVsHierarchy            project2 = new MockVsHierarchy();

            MockProjectItemsSyncer syncher = new MockProjectItemsSyncer(project1.GetPropertyProjectValue, project2.GetPropertyProjectValue);

            tracker.AddProjectSyncer(syncher);

            tracker.OnAfterAddFilesEx(1, 1, new[] { project1 }, new[] { 0 }, new[] { "File1.txt" },
                                      new[] { VSADDFILEFLAGS.VSADDFILEFLAGS_NoFlags });

            Assert.IsTrue(syncher.FilesAddedToSourceCalled);
        }
        public void ShouldDispatchRenameFilesToSyncher()
        {
            TestableProjectLinkTracker tracker  = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            MockVsHierarchy            project1 = new MockVsHierarchy();
            MockVsHierarchy            project2 = new MockVsHierarchy();

            MockProjectItemsSyncer syncher = new MockProjectItemsSyncer(project1.GetPropertyProjectValue, project2.GetPropertyProjectValue);

            tracker.AddProjectSyncer(syncher);

            tracker.OnAfterRenameFiles(1, 2, new[] { project1 }, new[] { 0 }, new[] { "oldFileName", "oldDirectoryName" },
                                       new[] { "newFileName", "newDirectoryName" },
                                       new[] { VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_NoFlags, VSRENAMEFILEFLAGS.VSRENAMEFILEFLAGS_Directory });

            Assert.IsTrue(syncher.FilesRenamedInSourceCalled);
        }
        public void ShouldTrackMultipleProjects()
        {
            MockIVsSolution            solution            = new MockIVsSolution();
            TestableProjectLinkTracker tracker             = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            project1VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project2VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project3VsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);
            solution.Hierarchies.Add(project3VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy, project2VsHierarchy);
            tracker.AddProjectLink(project1VsHierarchy, project3VsHierarchy);

            Assert.IsTrue(tracker.ProjectsAreLinked(project1VsHierarchy, project2VsHierarchy));
            Assert.IsTrue(tracker.ProjectsAreLinked(project1VsHierarchy, project3VsHierarchy));
        }
        public void ShouldUnlinkProjects()
        {
            MockIVsSolution            solution          = new MockIVsSolution();
            TestableProjectLinkTracker tracker           = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            sourceVsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            targetVsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(sourceVsHierarchy);
            solution.Hierarchies.Add(targetVsHierarchy);
            tracker.AddProjectLink(sourceVsHierarchy, targetVsHierarchy);
            targetVsHierarchy.GetPropertyProjectValue.Globals.SetVariablePersistsCalled = false;

            tracker.UnlinkProjects(sourceVsHierarchy.GetPropertyProjectIdGuidValue, targetVsHierarchy.GetPropertyProjectIdGuidValue);

            Assert.AreEqual(0, tracker.GetProjectLinks().Count());
            Assert.IsTrue(targetVsHierarchy.GetPropertyProjectValue.Globals.SetVariablePersistsCalled);
            Assert.IsFalse(targetVsHierarchy.GetPropertyProjectValue.Globals.SetVariablePersistsArgumentValue);
        }
        public void ShouldStopTrackingIfSourceProjectIsClosed()
        {
            MockIVsSolution            solution        = new MockIVsSolution();
            TestableProjectLinkTracker tracker         = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            sourceHierarchy = new MockVsHierarchy();
            MockVsHierarchy            targetHierarchy = new MockVsHierarchy();

            targetHierarchy.GetPropertyProjectValue.Globals.Dictionary["ProjectLinkReference"] =
                sourceHierarchy.GetPropertyProjectIdGuidValue.ToString();
            solution.Hierarchies.Add(sourceHierarchy);
            tracker.OnAfterOpenProject(sourceHierarchy, 0);
            tracker.OnAfterOpenProject(targetHierarchy, 0);
            Assert.IsTrue(tracker.ProjectsAreLinked(sourceHierarchy, targetHierarchy));

            tracker.OnBeforeCloseProject(sourceHierarchy, 0);

            Assert.IsFalse(tracker.ProjectsAreLinked(sourceHierarchy, targetHierarchy));
        }
        public void ShouldGetLinkedProject()
        {
            MockIVsSolution            solution            = new MockIVsSolution();
            TestableProjectLinkTracker tracker             = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            MockVsHierarchy            project1VsHierarchy = new MockVsHierarchy();
            MockVsHierarchy            project2VsHierarchy = new MockVsHierarchy();

            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy, project2VsHierarchy);

            IEnumerable <ProjectLink> projectLinks = tracker.GetProjectLinks();

            Assert.AreEqual(1, projectLinks.Count());
            ProjectLink projectLink = projectLinks.ElementAt(0);

            Assert.AreEqual(project1VsHierarchy.GetPropertyProjectIdGuidValue, projectLink.SourceProjectId);
            Assert.AreEqual(project2VsHierarchy.GetPropertyProjectIdGuidValue, projectLink.TargetProjectId);
        }