public void RenameFile() { EngineState s = EngineTests.CreateEngineState(); string originScriptPath = Path.Combine(StringEscaper.Preprocess(s, "%TestBench%"), "EncodedFile", "ExtractFileTests.script"); // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local void Template(string folderName, string oldFileName, string newFileName, bool result) { string destDir = FileHelper.GetTempDir(); string destScript = Path.Combine(destDir, "RenameFileTest.script"); try { File.Copy(originScriptPath, destScript, true); Script sc = s.Project.LoadScriptRuntime(destScript, new LoadScriptRuntimeOptions()); string errMsg; (sc, errMsg) = EncodedFile.RenameFile(sc, folderName, oldFileName, newFileName); if (errMsg != null) { Assert.IsFalse(result); return; } Assert.IsTrue(result); Assert.IsFalse(sc.Sections.ContainsKey(GetSectionName(folderName, oldFileName))); Assert.IsTrue(sc.Sections.ContainsKey(GetSectionName(folderName, newFileName))); Dictionary <string, string> fileDict = sc.Sections[folderName].IniDict; Assert.IsFalse(fileDict.ContainsKey(oldFileName)); Assert.IsTrue(fileDict.ContainsKey(newFileName)); } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } } Template("FolderExample", "Type1.jpg", "JPEG.jpg", true); Template("FolderExample", "Type2.7z", "LZMA2.7z", true); Template("FolderExample", "Type3.pdf", "Postscript.pdf", true); Template(AuthorEncoded, "Logo.jpg", "L.jpg", true); Template(InterfaceEncoded, "PEBakeryAlphaMemory.jpg", "P.jpg", true); Template("BannerImage", "Should.fail", "Should.fail.2", false); Template("ShouldFail", "Should.fail", "Should.fail.2", false); }