Пример #1
0
        private void OnTestcaseSelected(string name)
        {
            // Create the path if it does not exist
            if (!Directory.Exists(ResultOutputPath))
            {
                Directory.CreateDirectory(ResultOutputPath);
            }

            XElement Result;

            // The All testcases feature needs to be handled a little differently.
            if (name == "all")
            {
                // Running testcases can be a processor intensive job, so it is best done concurrently such that the
                // user can still interact with the ui.
                Task.Run(async() =>
                {
                    // Run the testcases.
                    Result = await TestHandler.ExecuteAll();

                    // Add AllTestcases.xml on to the end of the path and use XElement to save the output xml file to the path.
                    Result.Save(ResultOutputPath + "AllTestcases.xml");

                    // Tell the user where the testcases were written to and set the message box title to whether the testcases passed or not
                    // (The value of result will be Passed or Failed).
                    MessageBox.Show("Results written to " + ResultOutputPath + "AllTestcases.xml", Result.Attribute("result").Value);
                });
            }
            else
            {
                // See above
                Task.Run(async() =>
                {
                    // Execute the testcase by the given name.
                    Result = await TestHandler.ExecuteTestcase(name);

                    // Add the testcase name + Testcase.xml on to the end of the path and use XElement to save the output xml file to the path.
                    Result.Save(ResultOutputPath + name + "Testcase.xml");

                    // Set the message box title to the result of the testcase("Passed" or "Failed") and give them the option to see the exact result of the
                    // testcase in a window rather than having to open up the file themselves.
                    if (MessageBox.Show($"Click Yes to see full results", name + " " + Result.Attribute("result").Value.ToString().ToLower(), MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        MessageBox.Show(Result.ToString());
                    }
                });
            }
        }