public void ShouldAddNewItemsToSync()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var project1VsHierarchy = new MockVsHierarchy();
            var 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 ShouldCreateSyncherWhenLoadingLinkedSourceProjectAfterTargetProject()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var sourceHierarchy = new MockVsHierarchy();
            var targetHierarchy = new MockVsHierarchy();
            targetHierarchy.GetPropertyProjectValue.Globals.Dictionary["ProjectLinkReference"] = sourceHierarchy.GetPropertyProjectIdGuidValue.ToString();

            tracker.OnAfterOpenProject(targetHierarchy, 0);

            Assert.IsFalse(tracker.ProjectsAreLinked(sourceHierarchy, targetHierarchy));

            solution.Hierarchies.Add(sourceHierarchy);
            tracker.OnAfterOpenProject(sourceHierarchy, 0);

            Assert.IsTrue(tracker.ProjectsAreLinked(sourceHierarchy, targetHierarchy));
        }
        public void ShouldTrackMultipleProjects()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var project1VsHierarchy = new MockVsHierarchy();
            var project2VsHierarchy = new MockVsHierarchy();
            var 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()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var sourceVsHierarchy = new MockVsHierarchy();
            var targetVsHierarchy = new MockVsHierarchy();
            solution.Hierarchies.Add(sourceVsHierarchy);
            solution.Hierarchies.Add(targetVsHierarchy);
            tracker.AddProjectLink(sourceVsHierarchy, targetVsHierarchy);
            targetVsHierarchy.GetPropertyProjectValue.Globals.set_VariablePersistsCalled = false;

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

            Assert.AreEqual(0, tracker.GetProjectLinks().Count());
            Assert.IsTrue(targetVsHierarchy.GetPropertyProjectValue.Globals.set_VariablePersistsCalled);
            Assert.IsFalse(targetVsHierarchy.GetPropertyProjectValue.Globals.set_VariablePersistsArgumentValue);
        }
        public void ShouldNotRestartTrackingIfSourceAndTargetProjectsAreClosedAndSourceGetsReopened()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var sourceHierarchy = new MockVsHierarchy();
            var targetHierarchy = new MockVsHierarchy();
            targetHierarchy.GetPropertyProjectValue.Globals.Dictionary["ProjectLinkReference"] = sourceHierarchy.GetPropertyProjectIdGuidValue.ToString();
            solution.Hierarchies.Add(sourceHierarchy);
            tracker.OnAfterOpenProject(sourceHierarchy, 0);
            tracker.OnAfterOpenProject(targetHierarchy, 0);

            tracker.OnBeforeCloseProject(sourceHierarchy, 0);
            tracker.OnBeforeCloseProject(targetHierarchy, 0);
            tracker.OnAfterOpenProject(sourceHierarchy, 0);

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

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

            tracker.AddProjectLink(project1VsHierarchy, project2VsHierarchy);

            var projectLinks = tracker.GetProjectLinks();

            Assert.AreEqual(1, projectLinks.Count());
            var projectLink = projectLinks.ElementAt(0);
            Assert.AreEqual(project1VsHierarchy.GetPropertyProjectIdGuidValue, projectLink.SourceProjectId);
            Assert.AreEqual(project2VsHierarchy.GetPropertyProjectIdGuidValue, projectLink.TargetProjectId);
        }
        public void ShouldNotLinkTwiceTheSameTarget()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);
            var project1VsHierarchy = new MockVsHierarchy();
            var project2VsHierarchy = new MockVsHierarchy();
            var project3VsHierarchy = new MockVsHierarchy();
            solution.Hierarchies.Add(project1VsHierarchy);
            solution.Hierarchies.Add(project2VsHierarchy);
            solution.Hierarchies.Add(project3VsHierarchy);

            tracker.AddProjectLink(project1VsHierarchy, project3VsHierarchy);
            tracker.AddProjectLink(project2VsHierarchy, project3VsHierarchy);
        }
        public void ShouldGetEmptyLinkedProjectList()
        {
            var solution = new MockIVsSolution();
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), solution);

            var projectLinks = tracker.GetProjectLinks();

            Assert.IsNotNull(projectLinks);
            Assert.AreEqual(0, projectLinks.Count());
        }
        public void ShouldDispatchRenameFilesToSyncher()
        {
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            var project1 = new MockVsHierarchy();
            var 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 ShouldDispatchRemoveToSyncher()
        {
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            var project1 = new MockVsHierarchy();
            var project2 = new MockVsHierarchy();

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

            tracker.AddProjectSyncer(syncher);

            tracker.OnAfterRemoveFiles(1, 1, new[] { project1 }, new[] { 0 }, new[] { "File1.txt" },
                                      new[] { VSREMOVEFILEFLAGS.VSREMOVEFILEFLAGS_NoFlags });

            Assert.IsTrue(syncher.FilesRemovedFromSourceCalled);
        }
        public void ShouldDispatchOnlyToMatchingSynchers()
        {
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            var project1 = new MockVsHierarchy();
            var project2 = new MockVsHierarchy();
            var project3 = new MockVsHierarchy();

            MockProjectItemsSyncer syncherMatching = new MockProjectItemsSyncer(project1.GetPropertyProjectValue, project2.GetPropertyProjectValue);
            MockProjectItemsSyncer syncherNonMatching = new MockProjectItemsSyncer(project3.GetPropertyProjectValue, project2.GetPropertyProjectValue);

            tracker.AddProjectSyncer(syncherMatching);
            tracker.AddProjectSyncer(syncherNonMatching);

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

            Assert.IsTrue(syncherMatching.FilesAddedToSourceCalled);
            Assert.IsFalse(syncherNonMatching.FilesAddedToSourceCalled);
        }
        public void ShouldDispatchAddDirectoriesToSyncher()
        {
            TestableProjectLinkTracker tracker = new TestableProjectLinkTracker(new MockDocumentTracker(), new MockIVsSolution());
            var project1 = new MockVsHierarchy();
            var project2 = new MockVsHierarchy();

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

            tracker.AddProjectSyncer(syncher);

            tracker.OnAfterAddDirectoriesEx(1, 1, new[] { project1 }, new[] { 0 }, new[] { "Myfolder" },
                                      new[] { VSADDDIRECTORYFLAGS.VSADDDIRECTORYFLAGS_NoFlags });

            Assert.IsTrue(syncher.DirectoriesAddedToSourceCalled);
        }