public void TestGenerateAllFiles_Static_File() { IFile file = mocks.DynamicMock <IFile>(); ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>(); using (mocks.Record()) { SetupFolder(folder, new IFolder[0], new IScript[0], new[] { file }, ""); SetupProject(); SetupLoader(); SetupStaticFile(file); SetupProvider(providerMock); SetupController(); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "file.jpg", "C:\\Temp\\file.jpg", "file.jpg", "", "Iterator"))); } GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, fileController); ProjectFileTree tree = new ProjectFileTree(); helper.GenerateAllFiles("", folder, tree, scriptObject, "C:\\Temp"); Assert.That(tree.AllNodes.Count, Is.EqualTo(1)); Assert.That(tree.AllNodes[0].Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(tree.AllNodes[0].Text, Is.EqualTo("file.jpg")); Assert.That(tree.ChildNodes[0].AssociatedFile.RelativeFilePath, Is.EqualTo("file.jpg")); BinaryFileInformation bfi = (BinaryFileInformation)tree.ChildNodes[0].AssociatedFile; Assert.That(bfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), tree.ChildNodes[0].AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); mocks.VerifyAll(); }
public void TestGenerateAllFiles_Folder_Sub_File() { IFile staticFile = mocks.DynamicMock <IFile>(); IScript scriptFile = mocks.DynamicMock <IScript>(); IFolder subFolder = mocks.DynamicMock <IFolder>(); ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>(); using (mocks.Record()) { SetupFolder(subFolder, new IFolder[0], new[] { scriptFile }, new[] { staticFile }, "folder"); SetupFolder(folder, new[] { subFolder }, new IScript[0], new IFile[0], ""); SetupProject(); SetupStaticFile(staticFile); SetupScriptFile(scriptFile); SetupProvider(providerMock); SetupController(); SetupLoader(scriptFile); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "Class.cs", "C:\\Temp\\folder\\Class.cs", "folder\\Class.cs", "Class", "Iterator"))); Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile( "file.jpg", "C:\\Temp\\folder\\file.jpg", "folder\\file.jpg", "", "Iterator"))); } GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, fileController); ProjectFileTree tree = new ProjectFileTree(); helper.GenerateAllFiles("", folder, tree, scriptObject, "C:\\Temp"); Assert.That(tree.AllNodes.Count, Is.EqualTo(3)); ProjectFileTreeNode subfolder = tree.ChildNodes[0]; Assert.That(subfolder.Status, Is.EqualTo(ProjectFileStatusEnum.Folder)); Assert.That(subfolder.Text, Is.EqualTo("folder")); Assert.That(subfolder.ChildNodes.Count, Is.EqualTo(2)); ProjectFileTreeNode childNode = subfolder.ChildNodes[0]; Assert.That(childNode.Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(childNode.Text, Is.EqualTo("Class.cs")); Assert.That(childNode.ChildNodes, Is.Empty); Assert.That(childNode.AssociatedFile.RelativeFilePath, Is.EqualTo(Path.Combine("folder", "Class.cs"))); TextFileInformation tfi = (TextFileInformation)childNode.AssociatedFile; Assert.That(tfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), childNode.AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); childNode = subfolder.ChildNodes[1]; Assert.That(childNode.Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile)); Assert.That(childNode.Text, Is.EqualTo("file.jpg")); Assert.That(childNode.ChildNodes, Is.Empty); Assert.That(childNode.AssociatedFile.RelativeFilePath, Is.EqualTo(Path.Combine("folder", "file.jpg"))); BinaryFileInformation bfi = (BinaryFileInformation)childNode.AssociatedFile; Assert.That(bfi.NewGenFile.FilePath, Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), childNode.AssociatedFile.RelativeFilePath)), "New Gen file was not assigned to"); mocks.VerifyAll(); }
/// <summary> /// The write out process involves the following steps: /// 1. Back up the files currently in the user's project directory. /// 2. Write the template files that are being used to the temporary prevgen directory. /// 3. Write the merged files to the user's project directory. /// 4. Copy those temporary prevgen files over to the user's prevgen directory. /// </summary> /// <param name="helper"></param> /// <param name="tempController"></param> /// <param name="files"></param> /// <param name="projectTree"></param> public void WriteAllFiles(TaskProgressHelper helper, IController tempController, List<IFileInformation> files, ProjectFileTree projectTree, bool overwriteExistingFiles) { controller = tempController; // Calculate which folders need backing up. List<string> directories = new List<string>(); directories.Add(""); // The root folder. foreach (ProjectFileTreeNode node in projectTree.AllNodes) { if (node.IsFolder == false) continue; string path = node.Path; if (directories.Contains(path) == false) directories.Add(path); } //BackupUtility backupUtility = new BackupUtility(); //string timeString = BackupUtility.GetTimeString(); //foreach(string dir in directories) //{ // backupUtility.CreateBackup( // Path.Combine(controller.CurrentProject.ProjectSettings.ProjectPath, dir), // tempController.CurrentProject.ProjectSettings.ProjectGuid, // Path.GetFileNameWithoutExtension(tempController.CurrentProject.ProjectSettings.TemplateFileName), // Path.Combine(controller.CurrentProject.ProjectSettings.ProjectPath, dir), // timeString); //} foreach (IFileInformation file in files) { if (file.CurrentDiffResult.DiffType == TypeOfDiff.Conflict) { throw new WriteOutException(string.Format("Cannot write out files where a conflict exists! The file {0} has a conflict.", file.RelativeFilePath)); } } foreach (IFileInformation file in files) { WriteSingleFile(file, overwriteExistingFiles); // Write the newly generated file to the temporary directory so we can copy it to the prevgen directory in the // user's project directory. We do this instead of copying the whole newgen directory so we avoid changing the // timestamps on the prevgen files. string prevgenPath = controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGeneratorOutput); file.WriteNewGenFile(prevgenPath); // TODO: Need to copy the Manifest file over from the temporary prevgen folder to the new one. //CopyAllManifestFiles(controller.GetTempFilePathForComponent(ComponentKey.SlyceMerge_PrevGen), // controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGeneratorOutput)); if (file.CodeRootMap != null) { CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor(); string manifestFilename = Path.Combine(prevgenPath, ManifestConstants.MANIFEST_FILENAME); XmlDocument doc = ManifestConstants.LoadManifestDocument(manifestFilename); processor.SaveCustomMappings(doc, file.CodeRootMap, Path.GetFileName(file.RelativeFilePath)); } } // Copy the temporary files we just created to the user's prevgen directory. CreatePrevGenFiles(); }
private Controller() { CurrentProject = new WorkbenchProject(); Interfaces.Events.DataChangedEvent += On_DataChanged; OnProjectLoaded += Project_OnProjectLoaded; projectFileTreeModel = new ProjectFileTree(); //InitializeSettings(); }
public void TestConstuction() { ProjectFileTree tree = new ProjectFileTree(); Assert.That(tree.IsTreeRoot, Is.True, "A ProjectFileTree must always be a tree root."); Assert.That(tree.ParentNode, Is.Null, "A ProjectFileTree must not have a parent node"); Assert.That(tree.ParentTree, Is.Null, "A ProjectFileTree must not have a parent tree"); Assert.That(tree.AssociatedFile, Is.Null, "A ProjectFileTree must not have an associated file"); Assert.That(tree.Status, Is.EqualTo(ProjectFileStatusEnum.Folder), "A ProjectFileTree status must be Folder."); }
public void TestAddChildNodeWithAssociatedFile() { // We don't need this to do anything except be not null. IFileInformation fileInformation = MockRepository.GenerateStub <IFileInformation>(); ProjectFileTree tree = new ProjectFileTree(); ProjectFileTreeNode child = tree.AddChildNode(fileInformation); Assert.That(tree.ChildNodes[0].AssociatedFile, Is.SameAs(fileInformation), "The child must be constructed with the supplied AssociatedFile."); Assert.That(tree.ChildNodes[0], Is.SameAs(child), "The first ChildNode must be the new child node."); Assert.That(tree.AllNodes[0], Is.SameAs(child), "The first node in the AllNodes collection must be the new child."); }
public void TestGenerateAllFiles_No_Files() { using (mocks.Record()) { SetupFolder(folder, new IFolder[0], new IScript[0], new IFile[0], ""); SetupProject(); } GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, new FileController()); ProjectFileTree tree = new ProjectFileTree(); helper.GenerateAllFiles("fasdkj", folder, tree, scriptObject, "C:\\Temp"); Assert.That(tree.AllNodes, Is.Empty); }
public void TestAddChildNodeWithNullFile() { ProjectFileTree tree = new ProjectFileTree(); ProjectFileTreeNode child = tree.AddChildNode(); Assert.That(tree.ChildNodes.Count, Is.EqualTo(1), "The child should have been added to the tree's ChildNodes"); Assert.That(tree.AllNodes.Count, Is.EqualTo(1), "The child should have been added to the tree's Nodes"); Assert.That(tree.ChildNodes[0], Is.SameAs(child), "The first ChildNode must be the new child node."); Assert.That(tree.AllNodes[0], Is.SameAs(child), "The first node in the AllNodes collection must be the new child."); Assert.That(tree.ChildNodes[0].AssociatedFile, Is.Null, "The child must be constructed with a null AssociatedFile."); Assert.That(tree.ChildNodes[0].ParentNode, Is.SameAs(tree), "The ParentNode must be the tree."); Assert.That(tree.ChildNodes[0].ParentTree, Is.SameAs(tree), "The ParentTree must be the tree."); Assert.That(tree.ChildNodes[0].Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile), "A ProjectFileTreeNode's status must be UnanalysedFile by default."); }
public void Test_LoadPrevGenFile() { TextFileInformation tfi = new TextFileInformation(); tfi.RelativeFilePath = RelativePath; ProjectFileTree tree = new ProjectFileTree(); tree.AddChildNode(tfi, RelativePath); tree.LoadPrevGenFiles(controller); // loading a non existant file will result in tfi.PrevGenFile being set to TextFile.Blank Assert.That(tfi.PrevGenFile.FilePath, Is.Null); Assert.That(tfi.PrevGenFile.HasContents, Is.False); Assert.That(tfi.PrevGenFile.IsFileOnDisk, Is.False); }
public void Folder_And_File() { AnalysisProgressHelperStub helperStub = new AnalysisProgressHelperStub(); ProjectFileTree tree = new ProjectFileTree(); TextFileInformation tfi = new TextFileInformation(); tfi.RelativeFilePath = "Class.cs"; tfi.PrevGenFile = tfi.NewGenFile = tfi.UserFile = new TextFile("public class SomeClass { }"); tree.AddChildNode("folder").AddChildNode(tfi, "Class.cs"); AnalysisHelper ah = new AnalysisHelper(); ah.StartAnalysis(helperStub, controller, tree); Assert.That(tfi.CurrentDiffResult.DiffType, Is.EqualTo(TypeOfDiff.ExactCopy)); Assert.That(helperStub.Count, Is.EqualTo(0)); Assert.That(helperStub.LastProgressObjectList.Count, Is.EqualTo(4)); AnalyseFilesProgress progress = (AnalyseFilesProgress)helperStub.LastProgressObjectList[2]; Assert.That(progress, Is.Not.Null); Assert.That(progress.NumberOfConflicts, Is.EqualTo(0)); Assert.That(progress.NumberOfResolved, Is.EqualTo(0)); Assert.That(progress.NumberOfExactCopies, Is.EqualTo(0)); Assert.That(progress.ChangedFilePath, Is.EqualTo("folder\\Class.cs")); Assert.That(progress.ChangedFileStatus, Is.EqualTo(ProjectFileStatusEnum.Busy)); progress = (AnalyseFilesProgress)helperStub.LastProgressObjectList[3]; Assert.That(progress, Is.Not.Null); Assert.That(progress.NumberOfConflicts, Is.EqualTo(0)); Assert.That(progress.NumberOfResolved, Is.EqualTo(0)); Assert.That(progress.NumberOfExactCopies, Is.EqualTo(1)); Assert.That(progress.ChangedFilePath, Is.EqualTo("folder\\Class.cs")); Assert.That(progress.ChangedFileStatus, Is.EqualTo(ProjectFileStatusEnum.AnalysedFile)); string nl = Environment.NewLine; Assert.That(tfi.CalculateMergedFile(), Is.True); Assert.That(tfi.MergedFile.HasContents, Is.True); Assert.That(tfi.MergedFile.GetContents(), Is.EqualTo(nl + "public class SomeClass" + nl + "{" + nl + nl + "}")); }
///<summary> ///</summary> public void LoadFileTreeStatus(ProjectFileTree model) { string xmlFilename = Path.Combine(GetTempFilePathForComponent(ComponentKey.Workbench_Scratch), "filetree.xml"); if (!File.Exists(xmlFilename)) { string dir = Path.GetDirectoryName(xmlFilename); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (CurrentProject != null && !string.IsNullOrEmpty(CurrentProject.AppConfigFilename)) { string path = Path.GetDirectoryName(CurrentProject.AppConfigFilename).PathSlash("filetree.xml"); if (File.Exists(path)) { File.Copy(path, xmlFilename); } } } if (File.Exists(xmlFilename)) { XmlDocument document = new XmlDocument(); document.Load(xmlFilename); try { model.LoadCheckedStatusFromXml(document); } catch (ArgumentException) { // Ignore the file - it is malformed. It will be overwritten when the user saves anyway. } } }