public void ShouldReturnProjectGuid() { var mockHierarchy = new MockVsHierarchy(); mockHierarchy.GetPropertyProjectIdGuidValue = Guid.NewGuid(); Guid result = VisualStudioExtensibilityExtensions.GetProjectGuid(mockHierarchy); Assert.IsTrue(mockHierarchy.GetPropertyCalled); Assert.AreEqual(VSConstants.VSITEMID_ROOT, mockHierarchy.GetPropertyArgumentItemId); Assert.AreEqual<int>((int)__VSHPROPID.VSHPROPID_ProjectIDGuid, mockHierarchy.GetPropertyArgumentPropId); Assert.AreEqual(result, result); }
public void AddProjectLinkAddsPersistInfoToTargetProject() { var solution = new MockIVsSolution(); ProjectLinkTracker tracker = new ProjectLinkTracker(new MockDocumentTracker(), solution, null); var sourceHierarchy = new MockVsHierarchy(); var targetHierarchy = new MockVsHierarchy(); tracker.AddProjectLink(sourceHierarchy, targetHierarchy); Assert.IsTrue(targetHierarchy.GetPropertyProjectValue.Globals.Dictionary.ContainsKey("ProjectLinkReference")); Assert.AreEqual(sourceHierarchy.GetPropertyProjectIdGuidValue.ToString(), targetHierarchy.GetPropertyProjectValue.Globals.Dictionary["ProjectLinkReference"]); Assert.IsTrue(targetHierarchy.GetPropertyProjectValue.Globals.set_VariablePersistsCalled); }
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 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 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 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 ShouldRestoreLinksOnServiceInitialization() { var solution = new MockIVsSolution(); var sourceHierarchy = new MockVsHierarchy(); var targetHierarchy = new MockVsHierarchy(); targetHierarchy.GetPropertyProjectValue.Globals.Dictionary["ProjectLinkReference"] = sourceHierarchy.GetPropertyProjectIdGuidValue.ToString(); solution.Hierarchies.Add(sourceHierarchy); solution.Hierarchies.Add(targetHierarchy); var dteSolution = new MockSolution(); dteSolution.Projects.List.Add(sourceHierarchy.GetPropertyProjectValue); dteSolution.Projects.List.Add(targetHierarchy.GetPropertyProjectValue); ProjectLinkTracker tracker = new ProjectLinkTracker(new MockDocumentTracker(), solution, new MockLogger(), dteSolution); var links = tracker.GetProjectLinks().ToList(); Assert.AreEqual(1, links.Count); Assert.AreEqual(sourceHierarchy.GetPropertyProjectIdGuidValue, links[0].SourceProjectId); Assert.AreEqual(targetHierarchy.GetPropertyProjectIdGuidValue, links[0].TargetProjectId); }
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 ShouldIncludeSubDirectoryInTargetWhenItsPresentInFileSystem() { var mockSolution = new MockIVsSolution(); var mockTargetVsHierarchy = new MockVsHierarchy(); var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj"); var targetProject = new MockProject(@"c:\mockPath2\project1.csproj"); mockTargetVsHierarchy.GetPropertyProjectValue = targetProject; mockSolution.Hierarchies.Add(mockTargetVsHierarchy); targetProject.ProjectItems.AddFolder("Folder1", Constants.vsProjectItemKindPhysicalFolder); MockProjectItem folder1 = targetProject.ProjectItems.Item(0) as MockProjectItem; folder1.ProjectItems.ThrowOnAddFolder = true; var mockHierarchyHelper = new MockHierarchyHelper(); var mockLogger = new MockLogger(); var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, mockSolution, mockHierarchyHelper, new MockProjectItemsFilter()); string directoryToAdd = @"c:\mockPath1\Folder1\Folder2\"; syncher.DirectoryAddedToSource(directoryToAdd); Assert.IsTrue(mockTargetVsHierarchy.AddItemCalled); Assert.AreEqual(VSConstants.VSITEMID_ROOT, mockTargetVsHierarchy.AddItemArgumentItemidLoc); Assert.AreEqual(string.Empty, mockTargetVsHierarchy.AddItemArgumentItemName); Assert.AreEqual<uint>(1, mockTargetVsHierarchy.AddItemArgumentFilesToOpen); Assert.AreEqual(@"c:\mockPath2\Folder1\Folder2", mockTargetVsHierarchy.AddItemArgumentArrayFilesToOpen[0]); Assert.AreEqual(1, mockLogger.MessageLog.Count); StringAssert.Contains(mockLogger.MessageLog[0], "already exists"); StringAssert.Contains(mockLogger.MessageLog[0], "included"); StringAssert.Contains(mockLogger.MessageLog[0], @"Folder2"); StringAssert.Contains(mockLogger.MessageLog[0], targetProject.Name); }
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 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); }
public void ShouldThrowIfCOMExceptionErrorCodeIsNotTheExpected() { var mockSolution = new MockIVsSolution(); var mockTargetVsHierarchy = new MockVsHierarchy(); mockSolution.Hierarchies.Add(mockTargetVsHierarchy); var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj"); var targetProject = new MockProject(@"c:\mockPath2\project1.csproj"); targetProject.ProjectItems.ThrowOnAddFolder = true; targetProject.ProjectItems.ErrorCode = VSConstants.S_FALSE; var mockHierarchyHelper = new MockHierarchyHelper(); var mockLogger = new MockLogger(); var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, mockSolution, mockHierarchyHelper, new MockProjectItemsFilter()); string directoryToAdd = @"c:\mockPath1\MyFolder\"; syncher.DirectoryAddedToSource(directoryToAdd); }
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 ShouldIncludeDirectoryInTargetWhenItsPresentInFileSystem() { var mockSolution = new MockIVsSolution(); var mockTargetVsHierarchy = new MockVsHierarchy(); var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj"); var targetProject = new MockProject(@"c:\mockPath2\project1.csproj"); mockTargetVsHierarchy.GetPropertyProjectValue = targetProject; mockSolution.Hierarchies.Add(mockTargetVsHierarchy); var mockHierarchyHelper = new MockHierarchyHelper(); var mockLogger = new MockLogger(); var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, mockSolution, mockHierarchyHelper, new MockProjectItemsFilter()); string directoryToAdd = @"c:\mockPath1\MyFolder\"; targetProject.ProjectItems.ThrowOnAddFolder = true; syncher.DirectoryAddedToSource(directoryToAdd); Assert.IsTrue(mockTargetVsHierarchy.AddItemCalled); Assert.AreEqual(VSConstants.VSITEMID_ROOT, mockTargetVsHierarchy.AddItemArgumentItemidLoc); Assert.AreEqual(string.Empty, mockTargetVsHierarchy.AddItemArgumentItemName); Assert.AreEqual<uint>(1, mockTargetVsHierarchy.AddItemArgumentFilesToOpen); Assert.AreEqual(@"c:\mockPath2\MyFolder", mockTargetVsHierarchy.AddItemArgumentArrayFilesToOpen[0]); }