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); }
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)")); }
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 StyleCop(); // create a parameter set Dictionary<string, object> args = new Dictionary<string, object> { { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } }, { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" }, { "CacheResults", false }, }; // 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(resultsFile)); }
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 StyleCop(); // create a parameter set Dictionary<string, object> args = new Dictionary<string, object> { { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } }, { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" }, { "CacheResults", true }, }; // 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(/stylecopresultscache/sourcecode/violations/violation)")); }
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); }
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 }
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 StyleCop(); // create a parameter set Dictionary <string, object> args = new Dictionary <string, object> { { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } }, { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" }, { "CacheResults", false }, }; // 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(resultsFile)); }
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 StyleCop(); // create a parameter set Dictionary <string, object> args = new Dictionary <string, object> { { "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } }, { "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" }, { "CacheResults", true }, }; // 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(/stylecopresultscache/sourcecode/violations/violation)")); }
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 }
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 }
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"]); }
public void Check_a_directory_with_defaults_rules_shows_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" } }, { "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(false, results["Succeeded"]); Assert.AreEqual(10, results["ViolationCount"]); }
/// <summary> /// Prints each violation (to console) that the StyleCop processor encounters /// </summary> /// <param name='sender'> /// The event sender. /// </param> /// <param name='e'> /// The violation to print. /// </param> private static void ViolationEncountered(object sender, StyleCop.ViolationEventArgs e) { HadViolation(sender, e); Console.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "File: {0}", e.SourceCode.Path)); Console.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Line: {0} -> {1}", e.LineNumber, e.Message)); Console.WriteLine(); }
/// <summary> /// Prints the output of the StyleCop processor to the console. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The output message to print.</param> private static void OutputGenerated( object sender, StyleCop.OutputEventArgs e) { Console.WriteLine(e.Output); }
/// <summary> /// Indicates for execution if violations were encountered /// </summary> /// <param name='sender'> /// The event sender. /// </param> /// <param name='e'> /// The violation /// </param> private static void HadViolation(object sender, StyleCop.ViolationEventArgs e) { violationCount++; }
/// <summary> /// Prints each violation (to console) that the StyleCop processor encounters /// </summary> /// <param name='sender'> /// The event sender. /// </param> /// <param name='e'> /// The violation to print. /// </param> private static void ViolationEncountered(object sender, StyleCop.ViolationEventArgs e) { Console.WriteLine(string.Format("File: {0}", e.SourceCode.Path)); Console.WriteLine(string.Format("Line: {0} -> {1}", e.LineNumber, e.Message)); Console.WriteLine(); }
/// <summary> /// Checks the Xml header block for consistency with the element it belongs to. /// </summary> /// <param name="element">The element to parse.</param> /// <param name="settings">The analyzer settings.</param> private void CheckEnumHeaders(StyleCop.CSharp.CodeModel.Enum element, AnalyzerSettings settings) { Param.AssertNotNull(element, "element"); Param.Ignore(settings); foreach (EnumItem item in element.Items) { ElementHeader header = item.Header; if (header == null || header.IsEmpty) { if ((!settings.IgnorePrivates || element.AccessModifierType != AccessModifierType.Private) && (!settings.IgnoreInternals || element.AccessModifierType != AccessModifierType.Internal)) { this.AddViolation(item, Rules.EnumerationItemsMustBeDocumented); } } else { this.ParseHeader(item, header, item.LineNumber, false); } } }