/// <summary>
        /// Create commands to run MsTest.exe
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <param name="testAssemblyConfig">The test assembly config.</param>
        /// <returns></returns>
        private static string GetMsTestCommandArgs(SessionInfo sessionInfo, TestAssemblyConfig testAssemblyConfig)
        {
            StringBuilder mstestArgsBuilder = new StringBuilder();

            string testAssemblyPath = testAssemblyConfig.AssemblyPath;

            mstestArgsBuilder.AppendFormat("/testcontainer:\"{0}\" ", testAssemblyPath);

            mstestArgsBuilder.AppendFormat("/testsettings:\"{0}\" ", sessionInfo.Configuration.TestSettingsPath);
            foreach (string testToRun in sessionInfo.CommandLineArguments.TestsToRun)
            {
                mstestArgsBuilder.AppendFormat("/test:\"{0}\" ", testToRun);
            }

            if (sessionInfo.TestCodeContext != null)
            {
                if (sessionInfo.TestCodeContext.IsValid)
                {
                    mstestArgsBuilder.AppendFormat("/test:\"{0}\" ", sessionInfo.TestCodeContext.ToString());
                }
                else
                {
                    throw new InvalidOperationException("The test context is invalid.");
                }
            }

            if (!string.IsNullOrEmpty(sessionInfo.CommandLineArguments.Category))
            {
                mstestArgsBuilder.AppendFormat("/category:\"{0}\" ", sessionInfo.CommandLineArguments.Category);
            }

            if (sessionInfo.NoResults)
            {
                mstestArgsBuilder.AppendFormat("/noresults ");
            }
            else
            {
                string mstestResultsFile = Path.Combine(sessionInfo.ResultsDirectory, string.Format(OpenCoverMsTestResultsFileName, Path.GetFileNameWithoutExtension(testAssemblyConfig.AssemblyPath)));
                mstestArgsBuilder.AppendFormat("/resultsfile:\"{0}\" ", mstestResultsFile);
            }

            foreach (string detail in sessionInfo.Details)
            {
                mstestArgsBuilder.AppendFormat("/detail:\"{0}\" ", detail);
            }

            mstestArgsBuilder = mstestArgsBuilder.Replace("\"", "\\\"");

            return(mstestArgsBuilder.ToString());
        }
        /// <summary>
        /// Includes the test assembly.
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <param name="testAssemblyConfig">The test assembly config.</param>
        /// <returns></returns>
        private static bool IncludeTestAssembly(SessionInfo sessionInfo, TestAssemblyConfig testAssemblyConfig)
        {
            bool includeTestAssembly = true;

            if (sessionInfo.CommandLineArguments.TestAssemblies.Count > 0)
            {
                string fileName = Path.GetFileName(testAssemblyConfig.AssemblyPath).ToUpper();

                int count = (from fn in sessionInfo.CommandLineArguments.TestAssemblies
                             where Path.GetFileName(fn).ToUpper() == fileName
                             select fn).Count();
                if (count == 0)
                {
                    includeTestAssembly = false;
                }
            }

            return(includeTestAssembly);
        }
        /// <summary>
        /// Gets the N unit test args.
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <param name="testAssemblyConfig">The test assembly config.</param>
        /// <returns></returns>
        private static string GetNUnitTestArgs(SessionInfo sessionInfo, TestAssemblyConfig testAssemblyConfig)
        {
            StringBuilder nunitArgsBuilder = new StringBuilder();

            string testAssemblyPath = testAssemblyConfig.AssemblyPath;

            nunitArgsBuilder.AppendFormat("\"{0}\" ", testAssemblyPath);

            StringBuilder nunitTestBuilder = new StringBuilder();

            bool firstTest = true;

            foreach (string testToRun in sessionInfo.CommandLineArguments.TestsToRun)
            {
                if (!firstTest)
                {
                    nunitTestBuilder.Append(",");
                }
                nunitTestBuilder.AppendFormat("{0}", testToRun);
                firstTest = false;
            }

            if (sessionInfo.TestCodeContext != null)
            {
                if (sessionInfo.TestCodeContext.IsValid)
                {
                    if (!firstTest)
                    {
                        nunitTestBuilder.Append(",");
                    }
                    nunitTestBuilder.AppendFormat("{0}", sessionInfo.TestCodeContext.ToString());
                }
                else
                {
                    throw new InvalidOperationException("The test context is invalid.");
                }
            }

            if (nunitTestBuilder.Length > 0)
            {
                nunitArgsBuilder.AppendFormat("/run:\"{0}\" ", nunitTestBuilder.ToString());
            }

            if (!string.IsNullOrEmpty(sessionInfo.CommandLineArguments.Category))
            {
                nunitArgsBuilder.AppendFormat("/include:\"{0}\" ", sessionInfo.CommandLineArguments.Category);
            }

            if (sessionInfo.NoResults)
            {
                nunitArgsBuilder.AppendFormat("/noresult ");
            }
            else
            {
                string nunitResultsFile = Path.Combine(sessionInfo.ResultsDirectory, string.Format(OpenCoverNunitTestResultsFileName, Path.GetFileNameWithoutExtension(testAssemblyConfig.AssemblyPath)));
                nunitArgsBuilder.AppendFormat("/result:\"{0}\" ", nunitResultsFile);
            }

            nunitArgsBuilder = nunitArgsBuilder.Replace("\"", "\\\"");

            return(nunitArgsBuilder.ToString());
        }