Ejemplo n.º 1
0
        private static List <object[]> TestCase_RuleTest()
        {
            var expectedValidationResult = new StyleCopViolations()
            {
            };

            return(new List <object[]>()
            {
                EA1301.GetTestResources(),
                EA6400.GetTestResources()
            });
        }
Ejemplo n.º 2
0
        public static object[] GetTestResources()
        {
            string checkId = "EA1301";
            var    expectedValidationResult = new StyleCopViolations()
            {
                ViolationItems = new List <StyleCopViolations.Violation>()
                {
                    new StyleCopViolations.Violation()
                    {
                        LineNumber    = "7",
                        RuleNamespace = typeof(ExtendedNamingRules).FullName,
                        Rule          = Rules.PrivateFieldNamesMustStartWithUnderscore.ToString(),
                        RuleId        = checkId
                    }
                }
            };

            return(new object[] { checkId, expectedValidationResult });
        }
Ejemplo n.º 3
0
        public void RuleTest(string checkId, StyleCopViolations expectedValidationResult)
        {
            // arrange
            Directory.CreateDirectory(Locations.ValidationResultDirectory);
            string validationResultPath = Path.Combine(Locations.ValidationResultDirectory, $"{checkId}.xml");

            string ruleSettingPath = Path.Combine(Locations.TestDataDirectory, checkId, $"{checkId}.StyleCop");
            string codePath        = Path.Combine(Locations.TestDataDirectory, checkId, $"{checkId}.cs");

            CodeProject project = new CodeProject(
                checkId.GetHashCode(),
                Locations.BaseDirectory,
                new Configuration(null),
                0);

            StyleCopConsole console = new StyleCopConsole(
                ruleSettingPath,
                false,
                validationResultPath,
                Locations.AddInDirectory,
                false,
                Locations.BaseDirectory);

            console.Core.Environment.AddSourceCode(project, codePath, null);

            // act
            console.Start(new CodeProject[] { project }, true);

            StyleCopViolations actualValidationResult;

            using (Stream s = new FileStream(validationResultPath, FileMode.Open))
            {
                var serializer = new XmlSerializer(typeof(StyleCopViolations));
                actualValidationResult = (StyleCopViolations)serializer.Deserialize(s);
            }

            // assert
            bool testDataExist = File.Exists(ruleSettingPath) && File.Exists(codePath);

            testDataExist.Should().BeTrue();
            actualValidationResult.ViolationItems.Should().BeEquivalentTo(expectedValidationResult.ViolationItems);
        }
Ejemplo n.º 4
0
        public static object[] GetTestResources()
        {
            string        checkId     = "EA6400";
            List <string> lineNumbers = new List <string> {
                "16", "18", "20"
            };

            var violationItems = lineNumbers.Select(ln =>
                                                    new StyleCopViolations.Violation
            {
                LineNumber    = ln,
                RuleNamespace = typeof(ExtendedMaintainabilityRules).FullName,
                Rule          = Rules.ConstantMustRestrictedInAssembly.ToString(),
                RuleId        = checkId
            }
                                                    ).ToList();

            var expectedValidationResult = new StyleCopViolations()
            {
                ViolationItems = violationItems
            };

            return(new object[] { checkId, expectedValidationResult });
        }