Example #1
0
        // TODO: We should add support for test class source code coming from a TextReader/IEnumerable<string>
        // TODO: The test method generation should be aware of the destination type so that it can know how to correctly
        // reference the class under test (i.e. prefix with Parent or include a namespace reference)
        /// <summary>
        /// Generates a test for the provided <paramref name="methodToTest"/> and inserts it near the end of the
        /// <paramref name="testClassSourceCode"/>.
        /// </summary>
        ///
        /// <param name="testClassSourceCode">
        /// The source code to the compilation unit containing the class for testing the class under test.
        /// </param>
        ///
        /// <param name="methodToTest">
        /// A method of the class under test.
        /// </param>
        ///
        /// <returns>
        /// The source code to the compilation unit with the new test method stub added to it.
        /// </returns>
        public static string InsertTestFor(this string testClassSourceCode, ParametrizedNode methodToTest)
        {
            string sourceCodeToInsert = methodToTest.GenerateTest();
            var    cu         = Parser.ParseCompilationUnit(testClassSourceCode);
            int    lineNumber = cu.DetermineMethodInsertionLine();

            string result = testClassSourceCode.InsertLines(sourceCodeToInsert, lineNumber);

            return(result);
        }