예제 #1
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 StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                 { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } },
                 { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                 { "AdditionalAddInPaths", new string[] { @"..\Activities.StyleCop.Tests\AddIns" } }, // the directory cannot be a sub directory of current as this is automatically scanned
              };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.AreEqual(false, results["Succeeded"]);
            Assert.AreEqual(7, results["ViolationCount"]); // 6 core violations + the extra custom one
        }
예제 #2
0
        public void Can_choose_to_not_list_a_file_added_in_the_build_log()
        {
            // arrange
            var monitor = new DebugMonitor("Adding file to check");
            Trace.Listeners.Add(monitor);

            // create the activity
            var target = new StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } },
                { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                { "ShowOutput", false }
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.AreEqual(0, monitor.Writes);
        }
예제 #3
0
        public void Check_a_file_with_no_issues_and_defaults_rules_will_not_create_a_text_logfile()
        {
            // arrange
            var fileName = "LogFile.Txt";
            System.IO.File.Delete(fileName);

            // create the activity
            var target = new StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                 { "SourceFiles", new string[] { @"TestFiles\FileWith0Errors.cs" } },
                 { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                 { "LogFile", fileName }
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.IsFalse(System.IO.File.Exists(fileName));
        }
        public void Exception_violations_found_if_required_parameters_missing()
        {
            // arrange
            var target = new StyleCop();
            var args = new Dictionary<string, object>
            {
            };
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            // trapped by exception handler
        }
예제 #5
0
        public void Check_a_single_file_with_some_rules_disabled_shows_less_violations_and_fails()
        {
            // arrange
            // create the activity
            var target = new StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                 { "SourceFiles", new string[] { @"TestFiles\FileWith7Errors.cs" } }, 
                 { "SettingsFile", @"TestFiles\SettingsDisableSA1200.StyleCop" }
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.AreEqual(false, results["Succeeded"]);
            Assert.AreEqual(3, results["ViolationCount"]);
        }
예제 #6
0
        public void Check_a_single_file_with_default_rules_shows_no_violations_and_passes()
        {
            // arrange
            // create the activity
            var target = new StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                 { "SourceFiles", new string[] { @"TestFiles\FileWith0Errors.cs" } },
                 { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.AreEqual(true, results["Succeeded"]);
            Assert.AreEqual(0, results["ViolationCount"]);
        }
예제 #7
0
        public void Check_a_directory_with_limit_on_violation_count_shows_only_first_few_violations()
        {
            // arrange
            // create the activity
            var target = new StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                { "SourceFiles", new string[] { @"TestFiles" } },
                { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                { "MaximumViolationCount", 2 },
            };

            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.AreEqual(false, results["Succeeded"]);
            Assert.AreEqual(2, results["ViolationCount"]);  // we get 10 issues, but report only 2
        }
예제 #8
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 StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                 { "SourceFiles", new string[] { @"TestFiles" } },
                 { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                 { "LogFile", fileName }
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.IsTrue(System.IO.File.Exists(fileName));
            Assert.AreEqual(10, System.IO.File.ReadAllLines(fileName).Length);
        }
예제 #9
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 StyleCop();

            // create a parameter set
            Dictionary<string, object> args = new Dictionary<string, object>
            {
                { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } },
                { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
                { "XmlOutputFile", resultsFile },
            };

            // Create a WorkflowInvoker and add the IBuildDetail Extension
            WorkflowInvoker invoker = new WorkflowInvoker(target);

            // act
            var results = invoker.Invoke(args);

            // assert
            Assert.IsTrue(System.IO.File.Exists(resultsFile));
            var document = new XPathDocument(resultsFile);
            var nav = document.CreateNavigator();
            Assert.AreEqual(6d, nav.Evaluate("count(/StyleCopViolations/Violation)"));
        }