public void TestMethodExtractorDirectory(string directoryName)
        {
            var baseDir   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var targetDir = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\testdata\", directoryName));

            var methodList = MethodExtractor.ExtractAllMethodsFromDirectory(targetDir).ToList();

            Assert.That(methodList is List <MethodDefinition>);
            Assert.IsNotEmpty(methodList);

            // Generate report on methods extracted
            foreach (var m in methodList)
            {
                var methodName  = m.GetFullName();
                var methodDef   = m.ToString();
                var parentClass = m.GetAncestors <TypeDefinition>();

                Console.WriteLine(String.Format("{0}\t{1}\t{2}", parentClass, methodName, methodDef));
            }
        }
Beispiel #2
0
        public void TestPipelineWithSourceDirectory(string directoryName)
        {
            var currentDirectory = Path.GetFullPath(Assembly.GetExecutingAssembly().Location);
            var sourceDirectory  = Path.GetFullPath(Path.Combine(currentDirectory,
                                                                 @"..\..\..\..\testData\", directoryName));

            var srcmlMethods = MethodExtractor.ExtractAllMethodsFromDirectory(sourceDirectory);

            foreach (var methodDef in srcmlMethods)
            {
                // Print Class and Method Name
                Console.WriteLine("*************************\n\n{0}\n*************************",
                                  methodDef.GetFullName());

                // Extract SUnit Statements from MethodDefinition
                var statements = SUnitExtractor.ExtractAll(methodDef).ToList();

                // verify the statements selected
                //Assert.IsNotEmpty(statements, "statements selected from method definition");

                /*
                 * foreach (var s in statements)
                 * {
                 *  Console.WriteLine(statements.ToString());
                 * }
                 */

                // Translate Statements into SUnits
                List <SUnit> sunits = statements.ConvertAll(
                    new Converter <Statement, SUnit>(SUnitTranslator.Translate));

                // verify sunits have been translated
                Assert.That(sunits.TrueForAll(s => s.action != null), "All SUnits initialized.");

                /*
                 * foreach (var s in sunits)
                 * {
                 *  Console.WriteLine(s);
                 * }
                 */


                // Generate text from SUnits
                List <string> sentences = sunits.ConvertAll(
                    new Converter <SUnit, string>(TextGenerator.GenerateText));

                // verify string generated

                /*
                 * Assert.That(sentences.TrueForAll(s => s.Length > 0));
                 * foreach (var s in sentences)
                 * {
                 *  Console.WriteLine(s);
                 * }
                 */


                // Collect text and summarize
                var methodDocument = String.Join <string>("\n", sentences);

                // Actually, lets skip the summary for now
                Console.WriteLine(methodDocument);

                /*
                 * var summary = Summarizer.Summarize(methodDocument);
                 *
                 * // verify summary
                 * Assert.That(!summary.Equals(""));
                 * Console.WriteLine(summary);
                 */
            }
        }