コード例 #1
0
        public void DeleteFile()
        {
            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 fileName, bool result)
            {
                string destDir    = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                string destScript = Path.Combine(destDir, "DeleteFileTest.script");

                Directory.CreateDirectory(destDir);
                try
                {
                    File.Copy(originScriptPath, destScript, true);

                    Script sc = s.Project.LoadScriptRuntime(destScript, new LoadScriptRuntimeOptions());

                    string errMsg;
                    (sc, errMsg) = EncodedFile.DeleteFile(sc, folderName, fileName);
                    if (errMsg != null)
                    {
                        Assert.IsFalse(result);
                        return;
                    }

                    Assert.IsTrue(result);

                    Assert.IsFalse(sc.Sections.ContainsKey(GetSectionName(folderName, fileName)));

                    Dictionary <string, string> fileDict = sc.Sections[folderName].IniDict;
                    Assert.IsFalse(fileDict.ContainsKey(fileName));
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            Template("FolderExample", "Type1.jpg", true);
            Template("FolderExample", "Type2.7z", true);
            Template("FolderExample", "Type3.pdf", true);
            Template(AuthorEncoded, "Logo.jpg", true);
            Template(InterfaceEncoded, "PEBakeryAlphaMemory.jpg", true);

            Template("BannerImage", "Should.fail", false);
            Template("ShouldFail", "Should.fail", false);
        }