Ejemplo n.º 1
0
        public void RulesetWriterShouldFailToTwiceSeveralTimesIdenticalCheckId()
        {
            var ids = new List <string>
            {
                "CA1000",
                "CA1000",
                "CA1001",
                "CA1002",
                "CA1002",
                "CA1002"
            };

            try
            {
                RulesetWriter.ToString(ids);
            }
            catch (ArgumentException e)
            {
                if ("The following CheckId should not appear multiple times: CA1000, CA1002".Equals(e.Message))
                {
                    return;
                }
            }

            Assert.Fail();
        }
        public void RulesetWriterToString()
        {
            List <string> ids = new List <string>();

            ids.Add("CA1000");
            ids.Add("MyCustomCheckId");

            string actual = RulesetWriter.ToString(ids);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            expected.AppendLine("<RuleSet Name=\"SonarQube\" Description=\"Rule set generated by SonarQube\" ToolsVersion=\"12.0\">");
            expected.AppendLine("  <Rules AnalyzerId=\"Microsoft.Analyzers.ManagedCodeAnalysis\" RuleNamespace=\"Microsoft.Rules.Managed\">");
            expected.AppendLine("    <Rule Id=\"CA1000\" Action=\"Warning\" />");
            expected.AppendLine("    <Rule Id=\"MyCustomCheckId\" Action=\"Warning\" />");
            expected.AppendLine("  </Rules>");
            expected.AppendLine("</RuleSet>");

            Assert.AreEqual(expected.ToString(), actual);
        }
Ejemplo n.º 3
0
        public void RulesetWriterToString()
        {
            var ids = new List <string>
            {
                "CA1000",
                "MyCustomCheckId"
            };

            var actual = RulesetWriter.ToString(ids);

            var expected = new StringBuilder();

            expected.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            expected.AppendLine("<RuleSet Name=\"SonarQube\" Description=\"Rule set generated by SonarQube\" ToolsVersion=\"12.0\">");
            expected.AppendLine("  <Rules AnalyzerId=\"Microsoft.Analyzers.ManagedCodeAnalysis\" RuleNamespace=\"Microsoft.Rules.Managed\">");
            expected.AppendLine("    <Rule Id=\"CA1000\" Action=\"Warning\" />");
            expected.AppendLine("    <Rule Id=\"MyCustomCheckId\" Action=\"Warning\" />");
            expected.AppendLine("  </Rules>");
            expected.AppendLine("</RuleSet>");

            actual.Should().Be(expected.ToString());
        }