public int Execute(IEnumerable <string> args)
        {
            List <string> unhandledArguments = options.Parse(args);

            if (unhandledArguments.Count > 0)
            {
                throw new ArgumentException("There are some unsupported options.");
            }

            if (String.IsNullOrEmpty(businessActionsXmlFileName))
            {
                throw new ArgumentException("Missing business actions XML file name.");
            }

            if (String.IsNullOrEmpty(testSuiteSchemaNamespace))
            {
                throw new ArgumentException("Missing XML namespace for the new test suite schema.");
            }

            // set output file name
            testSuiteSchemaFileName = Path.Combine(outputDir, Path.GetFileName(Path.ChangeExtension(businessActionsXmlFileName, "xsd")));

            // create instance of class XmlValidationHelper
            XmlValidationHelper helper = new XmlValidationHelper();

            // validating XML with schema file
            // xml document must have at least one action element

            helper.ValidateXmlDocument(
                businessActionsXmlFileName,
                Path.Combine(ConsoleApp.AccipioDirectoryPath, AccipioActionsXsdFileName));

            // parse XML file
            BusinessActionsRepository businessActionsRepository = ParseXmlToObject(businessActionsXmlFileName);

            // generating XSD schema file with business actions validation parameters
            XmlDocument xmlSchemaDocument = GenerateXsdSchema(businessActionsRepository);

            // write xsd schema to file
            AccipioHelper.EnsureDirectoryPathExists(testSuiteSchemaFileName, true);
            using (Stream xsdSchemaDocument = File.Open(testSuiteSchemaFileName, FileMode.Create))
            {
                xmlSchemaDocument.Save(xsdSchemaDocument);
            }

            System.Console.WriteLine(string.Format(
                                         CultureInfo.InvariantCulture,
                                         "XSD schema file '{0}' was created",
                                         Path.GetFullPath(testSuiteSchemaFileName)));

            return(0);
        }
Exemple #2
0
        public int Execute(IEnumerable <string> args)
        {
            List <string> unhandledArguments = options.Parse(args);

            if (unhandledArguments.Count > 0)
            {
                throw new ArgumentException("There are some unsupported options.");
            }

            if (String.IsNullOrEmpty(businessActionsXmlFileName))
            {
                throw new ArgumentException("Missing business actions XML file name.");
            }

            if (String.IsNullOrEmpty(testSuiteXsdFileName))
            {
                throw new ArgumentException("Missing test suites XSD file name.");
            }

            if (String.IsNullOrEmpty(templateFileName))
            {
                throw new ArgumentException("Missing template file name.");
            }

            if (String.IsNullOrEmpty(templateFileExtension))
            {
                throw new ArgumentException("Missing template file extension.");
            }

            // parse business actions
            using (Stream xmlStream = File.OpenRead(businessActionsXmlFileName))
            {
                IBusinessActionXmlParser businessActionXmlParser = new BusinessActionsXmlParser(xmlStream);
                businessActionsRepository = businessActionXmlParser.Parse();
            }

            XmlValidationHelper xmlValidationHelper = new XmlValidationHelper();

            foreach (string testSuiteFileName in testSuitesFileNames)
            {
                // validate xml with xsd schema
                xmlValidationHelper.ValidateXmlDocument(testSuiteFileName, testSuiteXsdFileName);

                using (XmlTestSuiteParser testSuiteParser = new XmlTestSuiteParser(testSuiteFileName, businessActionsRepository))
                {
                    TestSuite parsedTestSuite = testSuiteParser.Parse();
                    parsedTestSuite.BusinessActionsRepository = businessActionsRepository;

                    // generate c# code
                    string codeFileName = Path.Combine(
                        outputDir,
                        Path.GetFileName(Path.ChangeExtension(testSuiteFileName, templateFileExtension)));
                    System.Console.WriteLine("Creating '{0}'", codeFileName);

                    ITestCodeGenerator codeGenerator = new TemplatedTestCodeGenerator(templateFileName, codeFileName);
                    codeGenerator.Generate(parsedTestSuite);
                }
            }

            return(0);
        }