public void ShouldIncludeDirectoryInTargetWhenItsPresentInFileSystem()
        {
            MockIVsSolution mockSolution          = new MockIVsSolution();
            MockVsHierarchy mockTargetVsHierarchy = new MockVsHierarchy();
            MockProject     sourceProject         = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     targetProject         = new MockProject(@"c:\mockPath2\project1.csproj");

            mockTargetVsHierarchy.GetPropertyProjectValue = targetProject;
            mockSolution.Hierarchies.Add(mockTargetVsHierarchy);
            MockHierarchyHelper      mockHierarchyHelper = new MockHierarchyHelper();
            MockLogger               mockLogger          = new MockLogger();
            ProjectItemsSynchronizer 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]);
        }
        public void ShouldIncludeSubDirectoryInTargetWhenItsPresentInFileSystem()
        {
            MockIVsSolution mockSolution          = new MockIVsSolution();
            MockVsHierarchy mockTargetVsHierarchy = new MockVsHierarchy();
            MockProject     sourceProject         = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     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;

            MockHierarchyHelper      mockHierarchyHelper = new MockHierarchyHelper();
            MockLogger               mockLogger          = new MockLogger();
            ProjectItemsSynchronizer 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 ShouldAddDirectoryToTargetWhenAddingToSourceProject()
        {
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject targetProject = new MockProject();

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, new MockProjectItemsFilter());
            string directoryToAdd            = @"c:\mockPath1\MyFolder\";

            syncher.DirectoryAddedToSource(directoryToAdd);

            Assert.IsTrue(targetProject.ProjectItems.AddFolderCalled);
            Assert.AreEqual(1, targetProject.ProjectItems.Count);
            StringAssert.EndsWith(targetProject.ProjectItems.Item(0).Name, "MyFolder");
        }
        public void ShouldFilterAddedDirectoryOnSource()
        {
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject targetProject = new MockProject();

            MockProjectItemsFilter mockProjectItemsFilter = new MockProjectItemsFilter {
                IsSynchronizableReturnValue = false
            };
            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, null, mockProjectItemsFilter);
            string directoryToAdd            = Path.Combine(@"c:\mockPath1", "MyFolder");

            syncher.DirectoryAddedToSource(directoryToAdd);

            Assert.IsFalse(targetProject.ProjectItems.AddFolderCalled);
            Assert.IsTrue(mockProjectItemsFilter.IsSynchronizableCalled);
        }
        public void ShouldThrowIfComExceptionErrorCodeIsNotTheExpected()
        {
            MockIVsSolution mockSolution          = new MockIVsSolution();
            MockVsHierarchy mockTargetVsHierarchy = new MockVsHierarchy();

            mockSolution.Hierarchies.Add(mockTargetVsHierarchy);
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject targetProject = new MockProject(@"c:\mockPath2\project1.csproj");

            targetProject.ProjectItems.ThrowOnAddFolder = true;
            targetProject.ProjectItems.ErrorCode        = VSConstants.S_FALSE;

            MockHierarchyHelper      mockHierarchyHelper = new MockHierarchyHelper();
            MockLogger               mockLogger          = new MockLogger();
            ProjectItemsSynchronizer syncher             = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, mockSolution, mockHierarchyHelper,
                                                                                        new MockProjectItemsFilter());
            string directoryToAdd = @"c:\mockPath1\MyFolder\";

            syncher.DirectoryAddedToSource(directoryToAdd);
        }