public void AddFolder() { void Template(string folderName, bool overwrite, bool result) { EngineState s = EngineTests.CreateEngineState(); string pbOriginScript = Path.Combine("%TestBench%", "EncodedFile", "Blank.script"); string originScript = StringEscaper.Preprocess(s, pbOriginScript); string destDir = FileHelper.GetTempDir(); string destScript = Path.Combine(destDir, "AddFolderTest.script"); try { File.Copy(originScript, destScript, true); Script sc = s.Project.LoadScriptRuntime(destScript, new LoadScriptRuntimeOptions()); try { sc = EncodedFile.AddFolder(sc, folderName, overwrite); } catch (Exception e) { switch (e) { case InvalidOperationException _: Assert.IsFalse(result); return; case ArgumentException _: Assert.IsFalse(result); return; } } Assert.AreEqual(sc.Sections.ContainsKey(folderName), result); Assert.AreEqual(IniReadWriter.ContainsSection(destScript, folderName), result); if (!folderName.Equals(AuthorEncoded, StringComparison.OrdinalIgnoreCase) && !folderName.Equals(InterfaceEncoded, StringComparison.OrdinalIgnoreCase)) { string[] folders = sc.Sections[EncodedFolders].Lines; Assert.AreEqual(folders.Contains(folderName, StringComparer.OrdinalIgnoreCase), result); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } } Template("UnitTestEncode", false, true); Template("DummySection", false, false); Template("DummySection", true, true); Template("AuthorEncoded", false, false); Template("AuthorEncoded", true, true); Template("InterfaceEncoded", false, true); Template("InterfaceEncoded", true, true); Template("Wrong[String]", false, false); Template("Tab\tChar", false, false); Template("New\r\nLine", false, false); Template("Invalid?", false, false); Template("Invalid:", false, false); }