Пример #1
0
 public void AddProjectItem(MockProjectItem projectItem)
 {
     if (projectItem.Collection != null)
     {
         throw new InvalidOperationException("Invalid use of the mock object");
     }
     projectItem.Collection = this;
     _projectItems.Add(projectItem);
 }
Пример #2
0
 public ProjectItem Item(object index)
 {
     if (index is int)
     {
         return(_projectItems[(int)index]);
     }
     if (index is string)
     {
         MockProjectItem item = new MockProjectItem("Stub mock created dynamically by calling Item(string)");
         AddProjectItem(item);
         return(item);
     }
     return(null);
 }
Пример #3
0
        public ProjectItem AddFolder(string name, string kind)
        {
            AddFolderCalled = true;
            if (ThrowOnAddFolder)
            {
                throw new COMException("Folder Exists in File System (from MockProjectItems)", ErrorCode);
            }

            MockProjectItem projectItem = new MockProjectItem(name)
            {
                Kind = kind
            };

            AddProjectItem(projectItem);
            return(projectItem);
        }
        public void RemoveDirectoryWithEmptySubFolderShouldDeleteWholeFolderStructure()
        {
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var folder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            var subFolder = new MockProjectItem("EmptySubFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            folder.ProjectItems.AddProjectItem(subFolder);
            targetProject.ProjectItems.AddProjectItem(folder);

            string sourceFolder = Path.Combine(@"c:\mockPath1", @"MyFolder");
            var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, new MockProjectItemsFilter());
            Assert.AreEqual(1, targetProject.ProjectItems.Count);

            syncher.DirectoryRemovedFromSource(sourceFolder);

            Assert.IsTrue(folder.DeleteCalled);
        }
        public void ShouldAddFileInCorrectSubfolder()
        {
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var sourceFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("MyFile.txt"));

            var targetFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            targetProject.ProjectItems.AddProjectItem(targetFolder);

            var 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 ShouldUseRelativePathWhenEvaluatingFilter()
        {
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var mockLogger = new MockLogger();
            var mockFilter = new MockProjectItemsFilter();
            var sourceFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("ABC.txt"));

            var 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);
        }
        public void ShouldRenameLinkedFile()
        {
            string oldSourceFile = Path.Combine(@"c:\mockPath1", @"MyOldFilename.cs");
            string newSourceFile = Path.Combine(@"c:\mockPath1", @"MyNewFilename.cs");

            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            sourceProject.ProjectItems.AddProjectItem(new MockProjectItem("MyNewFilename.cs"));
            var targetFile = new MockProjectItem(oldSourceFile, true);
            targetProject.ProjectItems.AddProjectItem(targetFile);

            var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, new MockLogger(), null, new MockProjectItemsFilter());
            Assert.AreEqual(1, targetProject.ProjectItems.Count);

            syncher.FileRenamedInSource(oldSourceFile, newSourceFile);

            Assert.IsTrue(targetFile.DeleteCalled);
            Assert.IsTrue(targetProject.ProjectItems.AddFromFileCalled);
            Assert.IsNotNull(targetProject.ProjectItems.FirstOrDefault(x => x.Name.EndsWith("MyNewFilename.cs")));
        }
        public void ShouldRemoveLinkedFolderWhenDeletingFolderFromSource()
        {
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var folder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            targetProject.ProjectItems.AddProjectItem(folder);

            string sourceFolder = Path.Combine(@"c:\mockPath1", @"MyFolder");
            var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            Assert.AreEqual(1, targetProject.ProjectItems.Count);

            syncher.DirectoryRemovedFromSource(sourceFolder);

            Assert.IsTrue(folder.DeleteCalled);
            Assert.AreEqual(1, mockLogger.MessageLog.Count);
            StringAssert.Contains(mockLogger.MessageLog[0], "removed");
            StringAssert.Contains(mockLogger.MessageLog[0], @"MyFolder");
            StringAssert.Contains(mockLogger.MessageLog[0], targetProject.Name);
        }
        public void ShouldRemoveLinkedFileWhenDeletingFromSource()
        {
            string sourceFile = @"c:\mockPath1\MyClass.cs";
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var targetFile = new MockProjectItem(sourceFile, true);
            targetProject.ProjectItems.AddProjectItem(targetFile);

            var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            Assert.AreEqual(1, targetProject.ProjectItems.Count);

            syncher.FileRemovedFromSource(sourceFile);

            Assert.IsTrue(targetFile.DeleteCalled);
            Assert.AreEqual(1, mockLogger.MessageLog.Count);
            StringAssert.Contains(mockLogger.MessageLog[0], "removed");
            StringAssert.Contains(mockLogger.MessageLog[0], @"MyClass.cs");
            StringAssert.Contains(mockLogger.MessageLog[0], targetProject.Name);
        }
        public void ShouldRemoveLinkedFileInSubFolderWhenDeletingFromSource()
        {
            string sourceFile = @"c:\mockPath1\SubFolder\MyClass.cs";
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var subFolder = new MockProjectItem("SubFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            var targetFile = new MockProjectItem(sourceFile, true);
            subFolder.ProjectItems.AddProjectItem(targetFile);
            targetProject.ProjectItems.AddProjectItem(subFolder);

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

            syncher.FileRemovedFromSource(sourceFile);

            Assert.IsTrue(targetFile.DeleteCalled);
        }
        public void ShouldNotRemoveFileIfTargetFileIsNotALink()
        {
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var targetFile = new MockProjectItem("MyClass.cs") { Kind = Constants.vsProjectItemKindPhysicalFile };
            targetProject.ProjectItems.AddProjectItem(targetFile);

            string sourceFile = Path.Combine(@"c:\mockPath1", @"MyClass.cs");
            var syncher = new ProjectItemsSynchronizer(sourceProject, targetProject, mockLogger, null, new MockProjectItemsFilter());
            Assert.AreEqual(1, targetProject.ProjectItems.Count);

            syncher.FileRemovedFromSource(sourceFile);

            Assert.IsFalse(targetFile.DeleteCalled);
            Assert.AreEqual(1, mockLogger.MessageLog.Count);
            StringAssert.Contains(mockLogger.MessageLog[0], "not linked");
            StringAssert.Contains(mockLogger.MessageLog[0], @"MyClass.cs");
            StringAssert.Contains(mockLogger.MessageLog[0], targetProject.Name);
        }
        public void ShouldCreateFolderStructureWhenAddingLinkedFile()
        {
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var sourceFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            sourceFolder.ProjectItems.AddProjectItem(new MockProjectItem("MyFile.txt"));

            var 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 ShouldCallRemoveAndAddDirectoryWhenDirectoryIsRenamedInSource()
        {
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var folder = new MockProjectItem("oldFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            targetProject.ProjectItems.AddProjectItem(folder);

            string oldFolderName = Path.Combine(@"c:\mockPath1", @"oldFolder");
            string newFolderName = @"c:\mockPath1\newFolder\";

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

            syncher.DirectoryRenamedInSource(oldFolderName, newFolderName);

            Assert.IsTrue(folder.DeleteCalled);
            Assert.IsTrue(targetProject.ProjectItems.AddFolderCalled);
        }
        public void ShouldAddItemToTargetWhenAddingLinkedFileToSourceProject()
        {
            string fileToAdd = @"c:\alternativeExternalPath\file.txt";
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var mockLogger = new MockLogger();
            var linkedSourceFile = new MockProjectItem("file.txt");
            linkedSourceFile.MockProperties.PropertiesList.Add(new MockProperty("FullPath", fileToAdd));
            sourceProject.ProjectItems.AddProjectItem(linkedSourceFile);

            var 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 ShouldAddFileThatIsLinkInCorrectSubfolder()
        {
            string fileToAdd = @"c:\alternativeExternalPath\file.txt";
            var mockLogger = new MockLogger();
            var sourceProject = new MockProject(@"c:\mockPath1\project1.csproj");
            var targetProject = new MockProject();
            var sourceFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            sourceProject.ProjectItems.AddProjectItem(sourceFolder);
            var linkedSourceFile = new MockProjectItem("file.txt");
            linkedSourceFile.MockProperties.PropertiesList.Add(new MockProperty("FullPath", fileToAdd));
            sourceFolder.ProjectItems.AddProjectItem(linkedSourceFile);

            var targetFolder = new MockProjectItem("MyFolder") { Kind = Constants.vsProjectItemKindPhysicalFolder };
            targetProject.ProjectItems.AddProjectItem(targetFolder);

            var 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");
        }