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 void RenderTestView(RenderContext Context, JsTestOption option, RenderRespnose response, JsTestCommand command)
        {
            if (string.IsNullOrEmpty(command.Folder) || command.Folder == "\\" || command.Folder == "/")
            {
                // find the start html.
                var    starthtml = JsTestHelper.GetStartHtml(Context, option);
                string url       = GenerateUrl(option, JsTestCommand.JsCommand.run, null, null);

                var    folders = JsTestHelper.ListTestFolders(Context, option);
                var    count   = JsTestHelper.CountTest(Context, option, folders.ToList());
                string html    = "<h3><a href='" + url + "'>run all tests</a>  (" + count.ToString() + " tests)</h3>\r\n";

                html += "<ul>";
                foreach (var item in folders)
                {
                    var files     = JsTestHelper.ListAllTestFiles(Context, option, item);
                    int testcount = JsTestHelper.CountTest(Context, option, item);

                    if (testcount > 0)
                    {
                        html += "<li>";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, item, null);
                        html += "<a href='" + url + "'>run</a> || ";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.view, item, null);
                        html += "<a href='" + url + "'>view</a> || ";

                        html += files.Count.ToString() + " files || ";
                        html += testcount.ToString() + " tests || Folder: ";
                        html += item;
                        html += "</li>";
                    }
                }
                html += "</ul>";

                string output = starthtml.Replace(JsTestHelper.PlaceHolder, html);

                string info = JsTestHelper.GetInfoHtml(Context, option);

                output = output.Replace("<div id=\"information\"></div>", info);

                response.Body = output;
            }

            else
            {
                if (string.IsNullOrEmpty(command.File))
                {
                    // view folder...
                    var starthtml = JsTestHelper.GetStartHtml(Context, option);

                    var files = JsTestHelper.ListFolderFiles(Context, option, command.Folder);

                    var count = JsTestHelper.CountTest(Context, option, command.Folder);

                    string url  = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, null);
                    string html = "<h3><a href='" + url + "'>run all tests</a>  (" + count.ToString() + " tests)</h3>\r\n";

                    html += "<ul>";

                    foreach (var item in files)
                    {
                        var functions = JsTestHelper.ListFileFunctions(Context, option, item.Folder, item.file);

                        html += "<li>";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, item.Folder, item.file);
                        html += "<a href='" + url + "'>run</a> || ";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.view, item.Folder, item.file);
                        html += "<a href='" + url + "'>view</a>  || ";

                        html += functions.Count.ToString() + " tests || File: " + System.IO.Path.Combine(item.Folder, item.file);

                        html += "</li>";
                    }
                    html += "</ul>";


                    response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
                }
                else
                {
                    //view file.
                    var    starthtml = JsTestHelper.GetStartHtml(Context, option);
                    string url       = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, command.File);

                    var functions = JsTestHelper.ListFileFunctions(Context, option, command.Folder, command.File);

                    string html = "<h3><a href='" + url + "'>run all tests</a>  (" + functions.Count.ToString() + " tests)</h3>\r\n";

                    html += "<ul>";

                    foreach (var item in functions)
                    {
                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, command.File, item);
                        html += "<li><a href='" + url + "'>run</a> || Test: " + item + "</li>";
                    }
                    html         += "</ul>";
                    response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
                }
            }
        }
Ejemplo n.º 3
0
        private static void RenderTestRun(RenderContext Context, JsTestOption option, RenderRespnose response, JsTestCommand command)
        {
            var    starthtml = JsTestHelper.GetStartHtml(Context, option);
            string html      = "<div>";

            html += "\r\n<script src='/_admin/kbtest/expect.js'></script>";
            html += "\r\n<script src='/_admin/kbtest/mock.js'></script>";

            var references = JsTestHelper.GetReferenceJs(Context, option, command.Folder);

            foreach (var item in references)
            {
                html += "\r\n<script src='" + item + "'></script>";
            }

            if (string.IsNullOrEmpty(command.Folder) || command.Folder == "\\" || command.Folder == "/")
            {
                // run all.
                var allfiles = JsTestHelper.ListAllTestFiles(Context, option, null);
                foreach (var file in allfiles)
                {
                    string fileurl = GeneratejsFile(option, file, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }

            else if (string.IsNullOrEmpty(command.File))
            {
                // run folder.
                var allfiles = JsTestHelper.ListAllTestFiles(Context, option, command.Folder);
                foreach (var file in allfiles)
                {
                    string fileurl = GeneratejsFile(option, file, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }
            else
            {
                if (string.IsNullOrEmpty(command.Function))
                {
                    // run file.
                    string filename = Lib.Helper.IOHelper.CombinePath(command.Folder, command.File);

                    string fileurl = GeneratejsFile(option, filename, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
                else
                {
                    // run function.
                    string filename = Lib.Helper.IOHelper.CombinePath(command.Folder, command.File);

                    html += "<div><h4>You are running one unit test, open console to view any errors</h4></div>";

                    string fileurl = GeneratejsFile(option, filename, JsTestCommand.JsCommand.run, command.Function);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }

            html         += "</div>";
            response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
        }