Пример #1
0
        /// <summary>
        /// Handles the event raised when the Validate button is clicked
        /// </summary>
        /// <param name="sender">Object raising the event</param>
        /// <param name="e">Event-specific parameters</param>
        private void btnValidate_Click(object sender, EventArgs e)
        {
            FileHistoryItem item    = cboXsdFile.SelectedItem as FileHistoryItem;
            string          xsdPath = cboXsdFile.Text;

            if (item != null)
            {
                xsdPath = item.FilePath;
            }

            // Check that the file exists
            if (!FileHelper.Instance.FileExists(xsdPath))
            {
                MessageBox.Show(this, string.Format("The file '{0}' does not exist, or the path is invalid", xsdPath), "File does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ConfigPersistenceHelper.Instance.Settings.XsdFiles.AddItem(xsdPath);
            txtValidationEvents.Clear();
            XsdValidationResult result = XsdValidationHelper.Instance.ValidateInstance(xsdPath, _doc);

            txtValidationEvents.Text = result.Results.ToString();
            switch (result.State)
            {
            case ValidationState.Success:
            {
                txtValidationEvents.ForeColor = Color.Black;
                break;
            }

            case ValidationState.OtherError:
            {
                txtValidationEvents.ForeColor = Color.Red;
                break;
            }

            case ValidationState.ValidationError:
            {
                txtValidationEvents.ForeColor = Color.Green;
                break;
            }

            case ValidationState.Warning:
            {
                txtValidationEvents.ForeColor = Color.Brown;
                break;
            }
            }

            // Refresh the combo box
            string currentPath = cboXsdFile.Text;

            LoadXSDComboBox();
            cboXsdFile.Text = currentPath;
        }
Пример #2
0
        public static void Main(string[] args)
        {
            if ((args.Length < 2) || (args.Length > 3))
            {
                PrintUsage();
                Environment.ExitCode = 1;
                return;
            }
            else
            {
                // Get the parameters
                string action     = args[0];
                string inputFile  = args[1];
                string secondFile = null;
                if (args.Length == 3)
                {
                    secondFile = args[2];
                }

                // Check the action is specified correctly
                if ((!action.StartsWith("-")) || (!action.Contains(":")))
                {
                    PrintUsage();
                    Environment.ExitCode = 1;
                    return;
                }

                // Split the action into component parts
                string[] actionArray = action.Split(':');
                if (actionArray.Length != 2)
                {
                    PrintUsage();
                    Environment.ExitCode = 1;
                    return;
                }

                // Check the action is supported
                if ((string.Compare(actionArray[1], "TestCase", true) != 0) &&
                    (string.Compare(actionArray[1], "XsdValidate", true) != 0))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unknown action specified: " + actionArray[1]);
                    Console.ResetColor();
                    PrintUsage();
                    Environment.ExitCode = 1;
                    return;
                }

                // Validate input file name
                if (!FileHelper.Instance.FileExists(inputFile))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(string.Format("The Xml file '{0}' does not exist.", inputFile));
                    Console.WriteLine("Please specify a file that exists.");
                    Console.ResetColor();
                    Environment.ExitCode = 1;
                    return;
                }

                // Check if we're generating a Test Case or Validating Xsd
                if (string.Compare(actionArray[1], "TestCase", true) == 0)
                {
                    try
                    {
                        Console.Write("Generating BizUnit TestCase...");
                        // Check if we need to convert the input file name from
                        // a short name to a long name
                        if (inputFile.Contains("~"))
                        {
                            FileInfo fi = new FileInfo(inputFile);
                            inputFile = fi.FullName;
                        }
                        // Check if we need to generate the output file name
                        if (string.IsNullOrEmpty(secondFile))
                        {
                            FileInfo fi = new FileInfo(inputFile);
                            secondFile = fi.DirectoryName + "\\TestCaseFor_" + fi.Name;
                        }
                        BizUnitHelper.Instance.GenerateTestCaseAndSave(inputFile, secondFile);
                        Console.WriteLine("Done.");
                        Console.WriteLine("Successfully Generated BizUnit TestCase to file:");
                        Console.WriteLine(secondFile);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed.");
                        Console.WriteLine("An error occurred generating the BizUnit Test Case:");
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Environment.ExitCode = 1;
                        return;
                    }
                }
                else if (string.Compare(actionArray[1], "XsdValidate", true) == 0)
                {
                    // Validate xsd file name
                    if (!FileHelper.Instance.FileExists(secondFile))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(string.Format("The Xsd file '{0}' does not exist.", secondFile));
                        Console.WriteLine("Please specify a file that exists.");
                        Console.ResetColor();
                        Environment.ExitCode = 1;
                        return;
                    }

                    try
                    {
                        Console.Write("Validating Xml against Xsd...");
                        XsdValidationResult result = XsdValidationHelper.Instance.ValidateInstance(secondFile, inputFile);
                        Console.WriteLine("Done.");
                        switch (result.State)
                        {
                        case ValidationState.OtherError:
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            break;
                        }

                        case ValidationState.ValidationError:
                        {
                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            break;
                        }

                        case ValidationState.Warning:
                        {
                            Console.ForegroundColor = ConsoleColor.DarkYellow;
                            break;
                        }
                        }
                        Console.WriteLine(result.Results.ToString());
                        Console.ResetColor();
                        if ((result.State == ValidationState.OtherError) || (result.State == ValidationState.ValidationError))
                        {
                            Environment.ExitCode = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed.");
                        Console.WriteLine("An error occurred during the validation procedure");
                        Console.WriteLine(ex.Message);
                        Console.ResetColor();
                        Environment.ExitCode = 1;
                        return;
                    }
                }
            }
        }