コード例 #1
0
        public void Can_set_the_name_of_the_name_of_output_XML_file()
        {
            // arrange
            var resultsFile = "out.xml";

            System.IO.File.Delete(resultsFile);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                XmlOutputFile        = resultsFile
            };

            // act
            target.Scan();

            // assert
            Assert.IsTrue(System.IO.File.Exists(resultsFile));
            var document = new XPathDocument(resultsFile);
            var nav      = document.CreateNavigator();

            Assert.AreEqual(7d, nav.Evaluate("count(/StyleCopViolations/Violation)"));
        }
コード例 #2
0
        public void Setting_the_cache_option_causes_the_results_to_be_cached_in_the_default_directory()
        {
            // arrange
            var resultsFile = "StyleCop.Cache";

            System.IO.File.Delete(resultsFile);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                CacheResults         = true,
            };

            // act
            target.Scan();

            // assert
            Assert.IsTrue(System.IO.File.Exists(resultsFile));
            var document = new XPathDocument(resultsFile);
            var nav      = document.CreateNavigator();

            Assert.AreEqual(7d, nav.Evaluate("count(/stylecopresultscache/sourcecode/violations/violation)"));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: thomasddn/StyleCopCmdLine
        static void Main(string[] args)
        {
            var options = new Options();

            try
            {
                if (CommandLine.Parser.Default.ParseArguments(args, options))
                {
                    // Values are available here
                    if (options.Verbose)
                    {
                        Console.WriteLine(options.GetUsage());

                        Console.WriteLine("SourceFiles: {0}", options.SourceFiles);
                        Console.WriteLine("SettingsFile: {0}", options.SettingsFile);
                        Console.WriteLine("MaximumViolationCount: {0}", options.MaximumViolationCount);
                        Console.WriteLine("ShowOutput: {0}", options.ShowOutput);
                        Console.WriteLine("CacheResults: {0}", options.CacheResults);
                        Console.WriteLine("ForceFullAnalysis: {0}", options.ForceFullAnalysis);
                        Console.WriteLine("XmlOutputFile: {0}", options.XmlOutputFile);
                        Console.WriteLine("LogFile: {0}", options.LogFile);
                        Console.WriteLine("TreatViolationsErrorsAsWarnings: {0}", options.TreatViolationsErrorsAsWarnings);
                        Console.WriteLine("AdditionalAddInPaths: {0}", options.AdditionalAddInPaths);


                        Console.WriteLine(Environment.NewLine);
                    }

                    var scanner = new StyleCopWrapper.Wrapper()
                    {
                        MaximumViolationCount = options.MaximumViolationCount,
                        ShowOutput            = options.ShowOutput,
                        CacheResults          = options.CacheResults,
                        ForceFullAnalysis     = options.ForceFullAnalysis,
                        XmlOutputFile         = options.XmlOutputFile,
                        LogFile                         = options.LogFile,
                        SourceFiles                     = options.SourceFiles,
                        SettingsFile                    = options.SettingsFile,
                        AdditionalAddInPaths            = options.AdditionalAddInPaths,
                        TreatViolationsErrorsAsWarnings = options.TreatViolationsErrorsAsWarnings
                    };

                    scanner.Scan();

                    Console.WriteLine("Succeeded [{0}]", scanner.Succeeded);
                    Console.WriteLine("Violation count [{0}]", scanner.ViolationCount);
                }
            }
            catch (CommandLine.ParserException ex)
            {
                Console.WriteLine("StyleCopCmdLine: Parameter error");
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
            }
        }
コード例 #4
0
        public void Exception_violations_found_if_required_parameters_missing()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper();

            // act
            target.Scan();

            // assert
            // trapped by exception handler
        }
コード例 #5
0
        public void Check_a_file_with_spelling_mistake_finds_error()
        {
            // arrange
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWithSA1650Errors.cs" },
                SettingsFile         = @"TestFiles\SettingsOnlySA1650.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" }
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(false, target.Succeeded);
            Assert.AreEqual(1, target.ViolationCount);
        }
コード例 #6
0
        public void Check_a_directory_with_defaults_rules_shows_violations_and_fails()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" }
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(false, target.Succeeded);
            Assert.AreEqual(20, target.ViolationCount);
        }
コード例 #7
0
        public void Check_a_single_file_with_some_rules_disabled_shows_less_violations_and_fails()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile         = @"TestFiles\SettingsDisableSA1200.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" }
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(false, target.Succeeded);
            Assert.AreEqual(3, target.ViolationCount);
        }
コード例 #8
0
        public void Check_a_single_file_with_default_rules_shows_no_violations_and_passes()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith0Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" }
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(true, target.Succeeded);
            Assert.AreEqual(0, target.ViolationCount);
        }
コード例 #9
0
        public void Check_a_directory_with_limit_on_violation_count_shows_only_first_few_violations()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles           = new string[] { @"TestFiles" },
                SettingsFile          = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths  = new string[] { @"\bin\Debug" },
                MaximumViolationCount = 2
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(false, target.Succeeded);
            Assert.AreEqual(2, target.ViolationCount);
        }
コード例 #10
0
        public void Check_a_maxviolationscount_used_when_violations_are_warnings()
        {
            // arrange
            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles                     = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile                    = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths            = new string[] { @"\bin\Debug" },
                MaximumViolationCount           = 3,
                TreatViolationsErrorsAsWarnings = true
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(true, target.Succeeded);
            Assert.AreEqual(3, target.ViolationCount);
        }
コード例 #11
0
        public void Extra_rules_can_loaded_from_a_directory_that_is_not_a_sub_directory_of_current_location()
        {
            // arrange
            var resultsFile = "StyleCop.Cache";

            System.IO.File.Delete(resultsFile);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug", @"..\..\..\MyCustomRules\bin\Debug" }, // the directory cannot be a sub directory of current as this is automatically scanned
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(false, target.Succeeded);
            Assert.AreEqual(8, target.ViolationCount);// 7 core violations + the extra custom one
        }
コード例 #12
0
        public void Not_setting_the_cache_option_causes_the_results_to_not_be_cached_in_the_default_directory()
        {
            // arrange
            var resultsFile = "StyleCop.Cache";

            System.IO.File.Delete(resultsFile);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith7Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                CacheResults         = false,
            };

            // act
            target.Scan();

            // assert
            Assert.IsFalse(System.IO.File.Exists(resultsFile));
        }
コード例 #13
0
        public void Can_choose_to_not_list_a_directory_of_files_added_in_the_build_log()
        {
            // arrange
            var monitor = new DebugMonitor("Adding file to check");

            Trace.Listeners.Add(monitor);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                ShowOutput           = false
            };

            // act
            target.Scan();

            // assert
            Assert.AreEqual(0, monitor.Writes);
        }
コード例 #14
0
        public void Check_a_file_with_no_issues_and_defaults_rules_will_create_a_text_logfile()
        {
            // arrange
            var fileName = "LogFile.Txt";

            System.IO.File.Delete(fileName);

            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles\FileWith0Errors.cs" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                LogFile = fileName
            };

            // act
            target.Scan();

            // assert
            Assert.IsTrue(System.IO.File.Exists(fileName));
        }
コード例 #15
0
        public void Check_a_directory_with_defaults_rules_will_creating_a_text_logfile_showing_violations()
        {
            // arrange
            var fileName = "LogFile.Txt";

            System.IO.File.Delete(fileName);


            // create the activity
            var target = new StyleCopWrapper.Wrapper()
            {
                SourceFiles          = new string[] { @"TestFiles" },
                SettingsFile         = @"TestFiles\AllSettingsEnabled.StyleCop",
                AdditionalAddInPaths = new string[] { @"\bin\Debug" },
                LogFile = fileName
            };

            // act
            target.Scan();

            // assert
            Assert.IsTrue(System.IO.File.Exists(fileName));
            Assert.AreEqual(20, System.IO.File.ReadAllLines(fileName).Length);
        }