Ejemplo n.º 1
0
        public static RenderRespnose Render(RenderContext Context, JsTestOption option)
        {
            string root = option.GetDiskRoot(Context);

            string         relativeurl = RenderEngine.ParseRelativeUrl(Context.Request.RawRelativeUrl, option);
            RenderRespnose response    = new RenderRespnose();

            var command = JsTestHelper.ParseCommand(relativeurl);

            if (command.IsJs)
            {
                RenderJs(Context, option, root, response, command);
            }
            else
            {
                response.ContentType = "text/html";

                if (command.Command == JsTestCommand.JsCommand.view)
                {
                    RenderTestView(Context, option, response, command);
                }
                else if (command.Command == JsTestCommand.JsCommand.run)
                {
                    RenderTestRun(Context, option, response, command);
                }
            }
            return(response);
        }
Ejemplo n.º 2
0
        public static HashSet <string> ListTestFolders(RenderContext context, JsTestOption options)
        {
            HashSet <string> result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            var root = options.GetDiskRoot(context);

            if (!string.IsNullOrEmpty(options.TestFolder))
            {
                var allsubs = System.IO.Directory.GetDirectories(root, options.TestFolder, System.IO.SearchOption.AllDirectories);

                foreach (var item in allsubs)
                {
                    System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(item);

                    string fullname = info.FullName;
                    fullname = fullname.Substring(root.Length);
                    fullname = fullname.Replace("\\", "/");

                    var path = options.FolderPath(context);

                    if (!string.IsNullOrEmpty(path) && fullname.ToLower().StartsWith(path))
                    {
                        fullname = fullname.Substring(path.Length + 1);
                    }
                    result.Add(fullname);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static HashSet <JsFilePath> ListFolderFiles(RenderContext context, JsTestOption option, string Folder)
        {
            HashSet <JsFilePath> result = new HashSet <JsFilePath>();

            var root = option.GetDiskRoot(context);

            var path = option.FolderPath(context);

            if (!string.IsNullOrEmpty(path))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, path);
            }

            if (!string.IsNullOrEmpty(Folder))
            {
                var fullfolder = Lib.Helper.IOHelper.CombinePath(root, Folder);

                if (System.IO.Directory.Exists(fullfolder))
                {
                    var allfiles = System.IO.Directory.GetFiles(fullfolder, "*.js", System.IO.SearchOption.AllDirectories);

                    foreach (var item in allfiles)
                    {
                        System.IO.FileInfo info = new System.IO.FileInfo(item);

                        if (!option.AssertJs.Contains(info.Name))
                        {
                            var jsPath = new JsFilePath();
                            if (!string.IsNullOrEmpty(Folder))
                            {
                                var index = info.FullName.IndexOf(Folder.Replace("/", "\\"), StringComparison.OrdinalIgnoreCase);
                                if (index > -1)
                                {
                                    var relativePath = info.FullName.Substring(index);

                                    jsPath.Folder = System.IO.Path.GetDirectoryName(relativePath);
                                    jsPath.file   = System.IO.Path.GetFileName(relativePath);
                                }
                                else
                                {
                                    jsPath.Folder = Folder;
                                    jsPath.file   = info.Name;
                                }
                            }
                            else
                            {
                                jsPath.file = info.Name;
                            }
                            result.Add(jsPath);
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static HashSet <string> GetReferenceJs(RenderContext context, JsTestOption option, string folder)
        {
            if (string.IsNullOrWhiteSpace(folder) || folder == "\\" || folder == "/")
            {
                return(GetReferenceJs(context, option));
            }

            HashSet <string> result = new HashSet <string>();

            string root = option.GetDiskRoot(context);

            System.IO.DirectoryInfo basedir = new System.IO.DirectoryInfo(root);

            var prepath = option.FolderPath(context);

            if (!string.IsNullOrEmpty(prepath))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, prepath);
            }

            System.IO.DirectoryInfo rootdir = new System.IO.DirectoryInfo(root);

            folder = Lib.Helper.IOHelper.CombinePath(root, folder);

            var currentdir = new System.IO.DirectoryInfo(folder);

            while (currentdir.Exists && currentdir.FullName.Length > rootdir.FullName.Length)
            {
                var file = Lib.Helper.IOHelper.CombinePath(currentdir.FullName, option.JsReferenceFileName);
                if (System.IO.File.Exists(file))
                {
                    var alllines = System.IO.File.ReadAllLines(file);
                    foreach (var line in alllines)
                    {
                        if (line != null)
                        {
                            var lineresult = FindRelativeFileName(basedir, line, currentdir);

                            if (!string.IsNullOrEmpty(lineresult))
                            {
                                result.Add(lineresult);
                            }
                        }
                    }
                }

                currentdir = currentdir.Parent;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static HashSet <string> ListFileFunctions(RenderContext context, JsTestOption option, string folder, string file)
        {
            var root = option.GetDiskRoot(context);

            string prepath = option.FolderPath(context);

            if (!string.IsNullOrEmpty(prepath))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, prepath);
            }

            if (!string.IsNullOrEmpty(folder))
            {
                var fullfolder = Lib.Helper.IOHelper.CombinePath(root, folder);
                var fullfile   = Lib.Helper.IOHelper.CombinePath(fullfolder, file);

                var alltext = System.IO.File.ReadAllText(fullfile);
                var block   = GetBlockJs(option, alltext);
                return(Lib.Helper.JintHelper.ListFunctionNames(block));
            }
            return(new HashSet <string>());
        }