Ejemplo n.º 1
0
        protected override string FormatFrameworkArgument(TestFixturOption runOption)
        {
            if (runOption.Project == null)
            {
                throw new ArgumentNullException("testFixturOption.Project can not be null");
            }

            string outPutXml = "OpenCoverOutput.xml";

            #region example in plain test
            //OpenCover.Console.exe -register:user -target:nunit-console-x86.exe -targetargs:"/noshadow Test.dll" -filter:+[*]* -output:coverage.xml
            #endregion

            //We are better off with a StringBuilder here but since this is not an operation often performed we can get away with it
            string tvArguments = string.Empty;

            tvArguments += " -register:user ";

            tvArguments += "-target:\"" + System.IO.Path.Combine(this.testFramework.ConsoleDirectory, this.testFramework.ConsoleName);

            Project project = runOption.Project;

            string projectPath = ProjectExaminar.GetProjectPath(project);

            string tvOutputReportFullName = projectPath + "\\" + outPutXml;

            if (System.IO.File.Exists(tvOutputReportFullName))
            {
                System.IO.File.Delete(tvOutputReportFullName);
            }

            if (!UTGHelper.IO.CreateFile(tvOutputReportFullName))
            {
                return(string.Empty);
            }

            tvArguments += "\" -output:\"";

            tvArguments += ToShortPathName(tvOutputReportFullName);

            tvArguments += "\" -targetargs:\"/noshadow ";

            tvArguments += GetProjectOutputPath(runOption);

            //Just to get this working we are not filtering however recode this so that we filter based on the runOption
            tvArguments += "\" -filter:+[*]*";

            return(tvArguments);
        }
        protected string GetProjectOutputPath(TestFixturOption testFixtureOptions)
        {
            //Need to get output path and output filename here
            Properties properties = testFixtureOptions.Project.ConfigurationManager.ActiveConfiguration.Properties;

            foreach (Property property in properties)
            {
                if (property.Name.Equals("OutputPath"))
                {
                    string pName = property.Name;
                    string value = property.Value as string;

                    if (value != null)
                    {
                        return(ToShortPathName(ProjectExaminar.GetProjectPath(testFixtureOptions.Project)) + "\\" + value + testFixtureOptions.Project.Name + ".dll");
                    }
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 3
0
        public override bool Examine(TestFixturOption testFixturOption, DTE2 applicationObject)
        {
            if (testFixturOption.Project == null)
            {
                throw new ArgumentNullException("testFixturOption.Project can not be null");
            }

            if (applicationObject == null)
            {
                throw new ArgumentNullException("applicationObject can not be null");
            }

            try
            {
                string outPutXml = "OpenCoverOutput.xml";

                if (this.binariesDirectory == null || this.binariesDirectory == string.Empty)
                {
                    BrowseForCoverLibraries tvLocateNUnitBinaries = new BrowseForCoverLibraries(UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_COVER_INSTALL_FOLDER, this);

                    tvLocateNUnitBinaries.Show();

                    return(false);
                }

                Project project = testFixturOption.Project;

                string projectPath = ProjectExaminar.GetProjectPath(project);

                if (CoverageExaminationStarted != null)
                {
                    CoverageExaminationStarted();
                }

                string tvArgument = FormatFrameworkArgument(testFixturOption);

                System.Diagnostics.ProcessStartInfo psi =
                    new System.Diagnostics.ProcessStartInfo(System.IO.Path.Combine(this.ConsoleDirectory, this.ConsoleName), tvArgument);

                psi.UseShellExecute = false;

                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

                psi.RedirectStandardOutput = true;

                psi.CreateNoWindow = true; //this is the one that works

                System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

                System.IO.StreamReader myOutput = process.StandardOutput;

                string output = string.Empty;

                if (!process.WaitForExit(exitWaitPeriod))
                {
                    return(false);
                }

                output += myOutput.ReadToEnd();

                bool success = ShowReport(projectPath, outPutXml);

                if (success)
                {
                    if (CoverageExaminationEnded != null)
                    {
                        CoverageExaminationEnded(project, "Changed text to something else here...");
                    }
                }

                //consider moving to http://reportgenerator.codeplex.com/ instead....

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return(false);
        }
Ejemplo n.º 4
0
        protected override string FormatFrameworkArgument(TestFixturOption runOption)
        {
            #region example in plain test
            //PartCover.exe
            //--target="C:\Program Files\NUnit 2.4.6\bin\nunit-console.exe"
            //--target-args="C:\Temp\MyClassLibrary\MyClassLibrary.nunit\MyClassLibrary.nunit.csproj"
            //--include=[MyClassLibrary]*
            #endregion

            //fix was found http://www.pinvoke.net/default.aspx/kernel32.GetShortPathName
            string tvArguments = string.Empty;

            tvArguments += "--target=\"" + System.IO.Path.Combine(this.CommandsDirectory, this.ConsoleName);

            string tvOutputReportFullName = ProjectExaminar.GetProjectPath(runOption.Project) + "\\PartCoverOutput.xml";

            if (System.IO.File.Exists(tvOutputReportFullName))
            {
                System.IO.File.Delete(tvOutputReportFullName);
            }

            if (!UTGHelper.IO.CreateFile(tvOutputReportFullName))
            {
                return(string.Empty);
            }

            tvArguments += "\" --output=\"";

            tvArguments += ToShortPathName(tvOutputReportFullName);

            tvArguments += "\" --target-args=\"";

            //Next line can be iffy when doing this runOption.Project.Name + ".csproj"
            tvArguments += ToShortPathName(ProjectExaminar.GetProjectPath(runOption.Project)) + "\\" + runOption.Project.Name + ".csproj";

            if (runOption.CClass == null)
            {
                tvArguments += "\" --include=[";
                tvArguments += ProjectExaminar.GetProjectNamespaceName(ProjectExaminar.GetUnitTestProjectsOriginalProject(
                                                                           runOption.Project.Name, (DTE2)runOption.Project.DTE, testFramework.TestProjectPostFix));
                tvArguments += "]";
                tvArguments += "*";
            }
            else
            {
                tvArguments += "\"";

                string tvClassName      = ProjectItemExaminor.GetUnitTestClassOriginalClassName(runOption.CClass.Name, testFramework.TestClassFixturePostFix);
                string tvClassNamespace = ProjectItemExaminor.GetUnitTestClassOriginalClassNamespace(runOption.CClass.Namespace.FullName);

                Project project = ProjectExaminar.GetUnitTestProjectsOriginalProject(runOption.Project.Name, (DTE2)runOption.Project.DTE, testFramework.TestProjectPostFix);

                if (project == null)
                {
                    throw new Exception(string.Format("Unable to locate Unit Test Project for the Project {0}.", runOption.Project.Name));
                }

                tvArguments += " --include=[";
                tvArguments += ProjectExaminar.GetProjectNamespaceName(project);
                tvArguments += "]";
                tvArguments += tvClassNamespace;
                tvArguments += ".";
                tvArguments += tvClassName;
                tvArguments += "* ";
            }

            return(tvArguments);
        }
Ejemplo n.º 5
0
        public override bool Examine(TestFixturOption testFixturOption, DTE2 applicationObject)
        {
            if (testFixturOption.Project == null)
            {
                throw new ArgumentNullException("testFixturOption.Project can not be null");
            }

            if (applicationObject == null)
            {
                throw new ArgumentNullException("applicationObject can not be null");
            }

            try
            {
                if (this.binariesDirectory == null || this.binariesDirectory == string.Empty)
                {
                    BrowseForCoverLibraries tvLocateNUnitBinaries = new BrowseForCoverLibraries(UTGHelper.CommonErrors.ERR_UNABLE_TO_LOCATE_COVER_INSTALL_FOLDER, this);

                    tvLocateNUnitBinaries.Show();

                    return(false);
                }

                Project project = testFixturOption.Project;

                if (CoverageExaminationStarted != null)
                {
                    CoverageExaminationStarted();
                }

                string tvArgument = FormatFrameworkArgument(testFixturOption);

                System.Diagnostics.ProcessStartInfo psi =
                    new System.Diagnostics.ProcessStartInfo(System.IO.Path.Combine(this.BinariesDirectory, this.CommandName), tvArgument);

                psi.UseShellExecute = false;

                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

                psi.RedirectStandardOutput = true;

                psi.CreateNoWindow = true; //this is the one that works

                System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);

                System.IO.StreamReader myOutput = process.StandardOutput;

                string output = string.Empty;

                if (!process.WaitForExit(exitWaitPeriod))
                {
                    return(false);
                }

                output += myOutput.ReadToEnd();

                UTGCoverage.CoverageReport report = new UTGCoverage.CoverageReport();

                System.IO.StreamReader reader = new System.IO.StreamReader(ProjectExaminar.GetProjectPath(testFixturOption.Project) + "\\PartCoverOutput.xml");

                UTGCoverage.ReportProvider.ReadReport(report, reader);

                reader.Close();

                System.Windows.Forms.TreeView trview = UTGCoverage.ReportProvider.ShowReport(report, UTGHelper.PartCoverUserControle.treeView1);

                UTGHelper.PartCoverUserControle.treeView1.Refresh();

                if (CoverageExaminationEnded != null)
                {
                    CoverageExaminationEnded(testFixturOption.Project, string.Format("{0} at {1}.", "PartCoverOutput.xml", ProjectExaminar.GetProjectPath(testFixturOption.Project)));
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return(false);
        }