Beispiel #1
0
        public override void SetUp()
        {
            base.SetUp();

            _ruleFactoryProvider      = Mocker.StrictMock <IStatementRuleFactoryProvider>();
            _blockRuleFactoryProvider = Mocker.StrictMock <IBlockRuleFactoryProvider>();
            _lineRuleFactoryProvider  = Mocker.StrictMock <ILineRuleFactoryProvider>();
            _provider = new CalidusRuleProvider(_ruleFactoryProvider, _blockRuleFactoryProvider, _lineRuleFactoryProvider);
        }
Beispiel #2
0
        public void GetBlockRulesShouldCallBlockRuleFactoryProvider()
        {
            IStatementRuleFactoryProvider    ruleFactoryProvider      = Mocker.StrictMock <IStatementRuleFactoryProvider>();
            IBlockRuleFactoryProvider        blockRuleFactoryProvider = Mocker.StrictMock <IBlockRuleFactoryProvider>();
            ILineRuleFactoryProvider         lineRuleFactoryProvider  = Mocker.StrictMock <ILineRuleFactoryProvider>();
            ICalidusRuleConfigurationFactory configFactory            = Mocker.DynamicMock <ICalidusRuleConfigurationFactory>();

            Expect.Call(blockRuleFactoryProvider.GetBlockRuleFactories()).Return(new List <IBlockRuleFactory>()).Repeat.Once();

            Mocker.ReplayAll();

            CalidusRuleProvider provider = new CalidusRuleProvider(ruleFactoryProvider, blockRuleFactoryProvider, lineRuleFactoryProvider);

            provider.GetBlockRules(configFactory);

            Mocker.VerifyAll();
        }
Beispiel #3
0
        /// <summary>
        /// Starts the runner
        /// </summary>
        /// <param name="configFactory">The configuration factory</param>
        /// <param name="project">The project to run against</param>
        public void Run(ICalidusRuleConfigurationFactory configFactory, ICalidusProject project)
        {
            //raise started
            if (Started != null)
            {
                Started(this, new EventArgs());
            }

            IList <RuleViolation> violations = new List <RuleViolation>();

            CalidusTokenParser     parser          = new CalidusTokenParser();
            CalidusStatementParser statementParser = new CalidusStatementParser();
            CalidusBlockParser     blockParser     = new CalidusBlockParser();
            CalidusLineParser      lineParser      = new CalidusLineParser();

            CalidusRuleProvider ruleProvider = new CalidusRuleProvider();

            IEnumerable <String> filesToCheck = project.GetSourceFilesToValidate();

            int currentFile = 0;
            int totalFiles  = filesToCheck.Count();

            foreach (String aFile in filesToCheck)
            {
                currentFile++;
                IEnumerable <TokenBase>     parsedTokens     = parser.Parse(File.ReadAllText(aFile));
                IEnumerable <StatementBase> parsedStatements = statementParser.Parse(parsedTokens);
                IEnumerable <BlockBase>     parsedBlocks     = blockParser.Parse(parsedStatements);
                IEnumerable <LineBase>      parsedLines      = lineParser.Parse(parsedTokens);

                IList <RuleViolation> currentFileViolations = new List <RuleViolation>();

                foreach (StatementRuleBase aStatementRule in ruleProvider.GetStatementRules(configFactory))
                {
                    foreach (StatementBase aStatement in parsedStatements)
                    {
                        if (aStatementRule.Validates(aStatement))
                        {
                            if (aStatementRule.IsValidFor(aStatement) == false)
                            {
                                currentFileViolations.Add(new RuleViolation(aFile, aStatementRule, aStatement));
                            }
                        }
                    }
                }

                foreach (BlockRuleBase aBlockRule in ruleProvider.GetBlockRules(configFactory))
                {
                    foreach (BlockBase aBlock in parsedBlocks)
                    {
                        if (aBlockRule.Validates(aBlock))
                        {
                            if (aBlockRule.IsValidFor(aBlock) == false)
                            {
                                currentFileViolations.Add(new RuleViolation(aFile, aBlockRule, aBlock.Statements.ElementAt(0)));
                            }
                        }
                    }
                }

                foreach (LineRuleBase aLineRule in ruleProvider.GetLineRules(configFactory))
                {
                    foreach (LineBase aLine in parsedLines)
                    {
                        if (aLineRule.Validates(aLine))
                        {
                            if (aLineRule.IsValidFor(aLine) == false)
                            {
                                currentFileViolations.Add(new RuleViolation(aFile, aLineRule, aLine.Tokens));
                            }
                        }
                    }
                }

                //raise file completed
                FileCompletedEventArgs args = new FileCompletedEventArgs(aFile, currentFile, totalFiles, currentFileViolations);
                if (FileCompleted != null)
                {
                    FileCompleted(this, args);
                }

                //add violations to whole list
                foreach (RuleViolation aViolation in currentFileViolations)
                {
                    violations.Add(aViolation);
                }
            }
            //raise completed
            if (Completed != null)
            {
                Completed(this, new RuleRunnerEventArgs(violations));
            }
        }