コード例 #1
0
        public void ReportBuilderTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            Assert.IsNotNull(rb != null);
        }
コード例 #2
0
        public void WithProcessorSymbols()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithProcessorSymbols(
                new[]
            {
                "DEBUG",
                "CODE_ANALYSIS",
            });
            var sf = GetPrivateProperty <IList <string> >(
                rb,
                "ProcessorSymbols");

            Assert.AreEqual(
                2,
                sf.Count);
            Assert.AreEqual(
                "DEBUG",
                sf[0]);
            Assert.AreEqual(
                "CODE_ANALYSIS",
                sf[1]);
        }
コード例 #3
0
        public void WithDirectoriesTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithDirectories(
                new[]
            {
                @"c:\windows",
                @"c:\program files"
            });
            var sf = GetPrivateProperty <IList <string> >(
                rb,
                "Directories");

            Assert.AreEqual(
                2,
                sf.Count);
            Assert.AreEqual(
                @"c:\windows",
                sf[0]);
            Assert.AreEqual(
                @"c:\program files",
                sf[1]);
        }
コード例 #4
0
        public void AddProjectFileTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();
            var sf  = GetTestSolutionPath() +
                      @"\StyleCopTestProject\StyleCopTestProject.csproj";

            var t  = rb.GetType();
            var mi = t.GetMethod(
                "AddProjectFile",
                BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);

            // Invoke the method.
            mi.Invoke(
                rb,
                new[] { sf, null });

            Assert.AreEqual(
                1,
                scr.Solutions.Rows.Count);
            Assert.AreEqual(
                1,
                scr.Projects.Rows.Count);
            Assert.AreEqual(
                3,
                scr.SourceCodeFiles.Rows.Count);
        }
コード例 #5
0
        public void AddProjectFileTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();
            var sf  = System.String.Join(Path.DirectorySeparatorChar.ToString(),
                                         new string[] { GetTestSolutionPath(), "StyleCopTestProject", "StyleCopTestProject.csproj" });

            var t  = rb.GetType();
            var mi = t.GetMethod(
                "AddProjectFile",
                BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);

            // Invoke the method.
            mi.Invoke(
                rb,
                new[] { sf, null });

            Assert.AreEqual(
                1,
                scr.Solutions.Rows.Count);
            Assert.AreEqual(
                1,
                scr.Projects.Rows.Count);
            Assert.AreEqual(
                3,
                scr.SourceCodeFiles.Rows.Count);
        }
コード例 #6
0
        public void WithTransformFileTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithTransformFile("c:\\StyleCopReport.xsl");
            var sf = GetPrivateProperty <string>(
                rb,
                "TransformFile");

            Assert.AreEqual(
                @"c:\StyleCopReport.xsl",
                sf);
        }
コード例 #7
0
        public void WithStyleCopSettingsFileTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithStyleCopSettingsFile("c:\\scs.settings");
            var sf = GetPrivateProperty <string>(
                rb,
                "StyleCopSettingsFile");

            Assert.AreEqual(
                @"c:\scs.settings",
                sf);
        }
コード例 #8
0
        public void WithRecursionTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithRecursion();
            var sf = GetPrivateProperty <bool>(
                rb,
                "RecursionEnabled");

            Assert.AreEqual(
                true,
                sf);
        }
コード例 #9
0
        public void WithProjectFilesTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithProjectFiles(
                new[]
            {
                @"c:\foo.txt"
            });
            var sf = GetPrivateProperty <IList <string> >(
                rb,
                "ProjectFiles");

            Assert.AreEqual(
                1,
                sf.Count);
            Assert.AreEqual(
                @"c:\foo.txt",
                sf[0]);
        }
コード例 #10
0
        public void WithIgnorePatternsTest()
        {
            var scr = new StyleCopReport();
            var rb  = scr.ReportBuilder();

            rb.WithIgnorePatterns(
                new[]
            {
                @"AssemblyInfo.cs"
            });
            var sf = GetPrivateProperty <IList <string> >(
                rb,
                "IgnorePatterns");

            Assert.AreEqual(
                1,
                sf.Count);
            Assert.AreEqual(
                @"AssemblyInfo.cs",
                sf[0]);
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the ReportBuilder class.
 /// </summary>
 /// <param name="report">
 /// The StyleCopReport to build.
 /// </param>
 internal ReportBuilder(StyleCopReport report)
 {
     this.Report = report;
 }
コード例 #12
0
        /// <summary>
        /// Adds a Visual Studio CSharp project file and
        /// adds its source files to the list of files to be 
        /// checked by StyleCop.
        /// </summary>
        /// <param name="projectFilePath">
        /// The fully-qualified path to the project file.
        /// </param>
        /// <param name="solutionsRow">
        /// The solutions row this project belongs to. Specify
        /// null if this project is not a member of a solution.
        /// </param>
        private void AddProjectFile(
            string projectFilePath,
            StyleCopReport.SolutionsRow solutionsRow)
        {
            // Get the project's name.
            var pname = Path.GetFileNameWithoutExtension(projectFilePath);

            if (solutionsRow == null)
            {
                solutionsRow = this.Report.Solutions.AddSolutionsRow(
                    projectFilePath,
                    "Project - " + pname);
            }

            // Add a new project row.
            var pr = this.Report.Projects.AddProjectsRow(
                projectFilePath,
                pname,
                solutionsRow);

            var pf = XDocument.Load(projectFilePath);

            // ReSharper disable PossibleNullReferenceException

            // Get the source files that are not auto-generated.
            var cnodes =
                pf.Root.Descendants().Where(
                    d => d.Name.LocalName == "Compile" &&
                         d.Attribute(XName.Get("Include")).Value.EndsWith(
                             "cs",
                             StringComparison.CurrentCultureIgnoreCase) &&
                         d.Elements().SingleOrDefault(
                             c =>
                             c.Name.LocalName == "AutoGen" &&
                             c.Value == "True") ==
                         null);

            // Add the source files.
            foreach (var n in cnodes)
            {
                var fpath =
                    Path.GetFullPath(Path.GetDirectoryName(projectFilePath))
                    +  Path.DirectorySeparatorChar.ToString() + n.Attribute(XName.Get("Include")).Value;

                this.AddFile(
                    fpath,
                    solutionsRow,
                    pr);
            }

            // ReSharper restore PossibleNullReferenceException
        }
コード例 #13
0
        /// <summary>
        /// Add the given file to the list of files to
        /// be checked by StyleCop.
        /// </summary>
        /// <param name="filePath">
        /// The fully-qualified path of the file to add.
        /// </param>
        /// <param name="solutionsRow">
        /// The solutions row for this file.
        /// </param>
        /// <param name="projectsRow">
        /// The projects row for this file.
        /// </param>
        private void AddFile(
            string filePath,
            StyleCopReport.SolutionsRow solutionsRow,
            StyleCopReport.ProjectsRow projectsRow)
        {
            if (this.IgnorePatterns != null)
            {
                // Check to see if this file should be ignored.
                if (this.IgnorePatterns.FirstOrDefault(
                        fp => Regex.IsMatch(
                                  Path.GetFileName(filePath),
                                  fp)) != null)
                {
                    return;
                }
            }

            var sr = solutionsRow ??
                     this.Report.Solutions.SingleOrDefault(
                         r => r.Name == "Files") ??
                     this.Report.Solutions.AddSolutionsRow(
                         "Files",
                         "Files");

            var pr = projectsRow ??
                     this.Report.Projects.SingleOrDefault(
                         r => r.Name == "Files") ??
                     this.Report.Projects.AddProjectsRow(
                         "Files",
                         "Files",
                         sr);

            var ext = Path.GetExtension(
                filePath).Replace(
                ".",
                string.Empty)
                .ToUpper(CultureInfo.CurrentCulture);

            this.Report.SourceCodeFiles.AddSourceCodeFilesRow(
                filePath,
                File.GetLastWriteTimeUtc(filePath),
                ext,
                Path.GetFileName(filePath),
                pr);
        }
コード例 #14
0
 public void ReportBuilderTest()
 {
     var scr = new StyleCopReport();
     var rb = scr.ReportBuilder();
     Assert.IsNotNull(rb != null);
 }
コード例 #15
0
 /// <summary>
 /// Creates a ReportBuilder to assist with building this StyleCopReport.
 /// </summary>
 /// <param name="report">
 /// The StyleCopReport object.
 /// </param>
 /// <returns>
 /// A new ReportBuilder object.
 /// </returns>
 public static ReportBuilder ReportBuilder(
     this StyleCopReport report)
 {
     return(new ReportBuilder(report));
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the ReportBuilder class.
 /// </summary>
 /// <param name="report">
 /// The StyleCopReport to build.
 /// </param>
 internal ReportBuilder(StyleCopReport report)
 {
     this.Report = report;
 }