public void RenameFolder() { EngineState s = EngineTests.CreateEngineState(); string originScriptPath = Path.Combine(StringEscaper.Preprocess(s, "%TestBench%"), "EncodedFile", "ExtractFileTests.script"); // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local void Template(string oldFolderName, string newFolderName, bool result) { string destDir = FileHelper.GetTempDir(); string destScript = Path.Combine(destDir, "RenameFolderTest.script"); try { File.Copy(originScriptPath, destScript, true); Script sc = s.Project.LoadScriptRuntime(destScript, new LoadScriptRuntimeOptions()); Dictionary <string, string> fileDict = null; if (result) { fileDict = sc.Sections[oldFolderName].IniDict; } string errMsg; (sc, errMsg) = EncodedFile.RenameFolder(sc, oldFolderName, newFolderName); if (errMsg != null) { Assert.IsFalse(result); return; } Assert.IsTrue(result); Assert.IsFalse(sc.Sections.ContainsKey(oldFolderName)); Assert.IsTrue(sc.Sections.ContainsKey(newFolderName)); Assert.IsFalse(IniReadWriter.ContainsSection(destScript, oldFolderName)); Assert.IsTrue(IniReadWriter.ContainsSection(destScript, newFolderName)); string[] folders = sc.Sections[EncodedFolders].Lines; Assert.IsFalse(folders.Contains(oldFolderName, StringComparer.OrdinalIgnoreCase)); Assert.IsTrue(folders.Contains(newFolderName, StringComparer.OrdinalIgnoreCase)); foreach (string fileName in fileDict.Keys) { Assert.IsFalse(sc.Sections.ContainsKey(GetSectionName(oldFolderName, fileName))); Assert.IsTrue(sc.Sections.ContainsKey(GetSectionName(newFolderName, fileName))); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } } Template("FolderExample", "RenamedExample", true); Template("BannerImage", "BannerRenamed", true); Template(AuthorEncoded, "Hello", false); Template(InterfaceEncoded, "World", false); Template("FolderExample", AuthorEncoded, false); Template("BannerImage", InterfaceEncoded, false); Template("ShouldFail", "ShouldNotRename", false); }