public void ShouldAddFileInCorrectSubfolder()
        {
            MockLogger      mockLogger    = new MockLogger();
            MockProject     sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     targetProject = new MockProject();
            MockProjectItem sourceFolder  = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("MyFile.txt"));

            MockProjectItem targetFolder = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            targetProject.ProjectItems.AddProjectItem(targetFolder);

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            string fileToAdd = @"c:\mockPath1\MyFolder\MyFile.txt";

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsTrue(targetFolder.ProjectItems.AddFromFileCalled);
            Assert.AreEqual(1, targetFolder.ProjectItems.Count);
            StringAssert.EndsWith(targetFolder.ProjectItems.Item(0).Name, "MyFile.txt");
            Assert.AreEqual(1, mockLogger.MessageLog.Count);
            StringAssert.Contains(mockLogger.MessageLog[0], "added");
            StringAssert.Contains(mockLogger.MessageLog[0], @"MyFolder\MyFile.txt");
        }
        public void ShouldAddFileThatIsLinkInCorrectSubfolder()
        {
            string          fileToAdd     = @"c:\alternativeExternalPath\file.txt";
            MockLogger      mockLogger    = new MockLogger();
            MockProject     sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     targetProject = new MockProject();
            MockProjectItem sourceFolder  = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            MockProjectItem linkedSourceFile = new MockProjectItem("file.txt");

            linkedSourceFile.MockProperties.PropertiesList.Add(new MockProperty("FullPath", fileToAdd));
            sourceFolder.ProjectItems.AddProjectItem(linkedSourceFile);

            MockProjectItem targetFolder = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            targetProject.ProjectItems.AddProjectItem(targetFolder);

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsTrue(targetFolder.ProjectItems.AddFromFileCalled);
            Assert.AreEqual(1, targetFolder.ProjectItems.Count);
            StringAssert.EndsWith(targetFolder.ProjectItems.Item(0).Name, "file.txt");
        }
        public void ShouldCreateFolderStructureWhenAddingLinkedFile()
        {
            MockLogger      mockLogger    = new MockLogger();
            MockProject     sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     targetProject = new MockProject();
            MockProjectItem sourceFolder  = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("MyFile.txt"));

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            string fileToAdd = @"c:\mockPath1\MyFolder\MyFile.txt";

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsNotNull(targetProject.ProjectItems.Item(0));
            Assert.AreEqual(targetProject.ProjectItems.Item(0).Name, "MyFolder");
            Assert.IsNotNull(targetProject.ProjectItems.Item(0).ProjectItems);
            Assert.AreEqual(1, targetProject.ProjectItems.Item(0).ProjectItems.Count);
            StringAssert.EndsWith(targetProject.ProjectItems.Item(0).ProjectItems.Item(0).Name, "MyFile.txt");
            Assert.IsTrue(mockLogger.MessageLog.Count > 1);
            string loggedMessage = mockLogger.MessageLog.FirstOrDefault(x => x.IndexOf("folder", StringComparison.OrdinalIgnoreCase) >= 0);

            Assert.IsNotNull(loggedMessage);
            StringAssert.Contains(loggedMessage, "created");
            Assert.AreEqual(-1, loggedMessage.IndexOf("MyFile.txt"));
        }
        public void ShouldAddMultipleItemsToTarget()
        {
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject targetProject = new MockProject();

            sourceProject.ProjectItems.AddProjectItem(new MockProjectItem("ABC.txt"));
            sourceProject.ProjectItems.AddProjectItem(new MockProjectItem("123.txt"));

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, new MockProjectItemsFilter());
            string fileToAdd1 = Path.Combine(@"c:\mockPath1", @"ABC.txt");
            string fileToAdd2 = Path.Combine(@"c:\mockPath1", @"123.txt");

            syncher.FileAddedToSource(fileToAdd1);
            syncher.FileAddedToSource(fileToAdd2);

            Assert.IsTrue(targetProject.ProjectItems.AddFromFileCalled);
            Assert.AreEqual(2, targetProject.ProjectItems.Count);
            StringAssert.EndsWith(targetProject.ProjectItems.Item(0).Name, "ABC.txt");
            StringAssert.EndsWith(targetProject.ProjectItems.Item(1).Name, "123.txt");
        }
        public void ShouldAddItemToTargetWhenAddingLinkedFileToSourceProject()
        {
            string          fileToAdd        = @"c:\alternativeExternalPath\file.txt";
            MockProject     sourceProject    = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject     targetProject    = new MockProject();
            MockLogger      mockLogger       = new MockLogger();
            MockProjectItem linkedSourceFile = new MockProjectItem("file.txt");

            linkedSourceFile.MockProperties.PropertiesList.Add(new MockProperty("FullPath", fileToAdd));
            sourceProject.ProjectItems.AddProjectItem(linkedSourceFile);

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsTrue(targetProject.ProjectItems.AddFromFileCalled);
            Assert.AreEqual(1, targetProject.ProjectItems.Count);
            StringAssert.EndsWith(targetProject.ProjectItems.Item(0).Name, "file.txt");
        }
        public void ShouldFilterAddedFileOnSource()
        {
            string      fileToAdd     = Path.Combine(@"c:\mockPath1", @"ABC.xaml");
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");

            sourceProject.ProjectItems.AddProjectItem(new MockProjectItem("ABC.xaml"));
            MockProject            targetProject          = new MockProject();
            MockProjectItemsFilter mockProjectItemsFilter = new MockProjectItemsFilter {
                IsSynchronizableReturnValue = false
            };
            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, null, mockProjectItemsFilter);

            Assert.IsFalse(mockProjectItemsFilter.IsSynchronizableCalled);

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsFalse(targetProject.ProjectItems.AddFromFileCalled);
            Assert.IsTrue(mockProjectItemsFilter.IsSynchronizableCalled);
        }
        public void ShouldAddItemToTargetWhenAddingToSourceProject()
        {
            MockProject sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject targetProject = new MockProject();
            MockLogger  mockLogger    = new MockLogger();

            sourceProject.ProjectItems.AddProjectItem(new MockProjectItem("ABC.txt"));

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            string fileToAdd = Path.Combine(@"c:\mockPath1", @"ABC.txt");

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsTrue(targetProject.ProjectItems.AddFromFileCalled);
            Assert.AreEqual(1, targetProject.ProjectItems.Count);
            StringAssert.EndsWith(targetProject.ProjectItems.Item(0).Name, "ABC.txt");
            Assert.AreEqual(1, mockLogger.MessageLog.Count);
            StringAssert.Contains(mockLogger.MessageLog[0], "added");
            StringAssert.Contains(mockLogger.MessageLog[0], "ABC.txt");
            StringAssert.Contains(mockLogger.MessageLog[0], targetProject.Name);
        }
        public void ShouldUseRelativePathWhenEvaluatingFilter()
        {
            MockProject            sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            MockProject            targetProject = new MockProject();
            MockLogger             mockLogger    = new MockLogger();
            MockProjectItemsFilter mockFilter    = new MockProjectItemsFilter();
            MockProjectItem        sourceFolder  = new MockProjectItem("MyFolder")
            {
                Kind = Constants.vsProjectItemKindPhysicalFolder
            };

            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("ABC.txt"));

            ProjectItemsSynchronizer syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, mockFilter);
            string fileToAdd = @"c:\mockPath1\MyFolder\ABC.txt";

            syncher.FileAddedToSource(fileToAdd);

            Assert.IsTrue(mockFilter.IsSynchronizableCalled);
            Assert.AreEqual(@"MyFolder\ABC.txt", mockFilter.IsSynchronizableArgument);
        }