예제 #1
0
        public void RuleTreeControllerShouldDisplayRulesAlphabeticallyFromRuleProvider()
        {
            IRule ruleAlpha = Mocker.DynamicMock <IRule>();
            IRule ruleBravo = Mocker.DynamicMock <IRule>();

            IList <IRule> rules = new List <IRule>();

            rules.Add(ruleBravo);
            rules.Add(ruleAlpha);

            IList <IRule> rulesSorted = new List <IRule>();

            rulesSorted.Add(rules[1]);
            rulesSorted.Add(rules[0]);

            TreeViewImp                      view          = new TreeViewImp(rulesSorted);
            ICalidusRuleProvider             ruleProvider  = Mocker.DynamicMock <ICalidusRuleProvider>();
            ICalidusRuleConfigurationFactory configFactory = Mocker.DynamicMock <ICalidusRuleConfigurationFactory>();

            Expect.Call(ruleAlpha.Category).Return("Alpha").Repeat.Any();
            Expect.Call(ruleBravo.Category).Return("Bravo").Repeat.Any();

            Expect.Call(ruleProvider.GetRules(configFactory)).Return(rules).Repeat.Once();
            Expect.Call(() => view.DisplayRules(rulesSorted)).Repeat.Once();

            Mocker.ReplayAll();

            RuleTreeController controller = new RuleTreeController(view, ruleProvider, configFactory);

            Mocker.VerifyAll();
        }
예제 #2
0
        public RuleConfigurationWindow(ICalidusProjectModel project, ICalidusProjectManager manager)
        {
            InitializeComponent();
            _provider             = new CalidusRuleProvider();
            _configurationFactory = new CalidusRuleConfigurationFactory(project, manager);

            RuleConfigurationController controller = new RuleConfigurationController(ruleConfigurationView, _provider, _configurationFactory);
        }
예제 #3
0
        public override void SetUp()
        {
            base.SetUp();

            _view          = Mocker.DynamicMock <IRuleRunnerView>();
            _runner        = Mocker.DynamicMock <IRuleRunner>();
            _projectModel  = Mocker.DynamicMock <ICalidusProjectModel>();
            _configFactory = Mocker.DynamicMock <ICalidusRuleConfigurationFactory>();
        }
예제 #4
0
        /// <summary>
        /// Create a new instance of this class
        /// </summary>
        /// <param name="view">The view to use</param>
        /// <param name="ruleProvider">The rule provider to use</param>
        /// <param name="configFactory">The configuration factory</param>
        public RuleTreeController(IRuleTreeView view, ICalidusRuleProvider ruleProvider, ICalidusRuleConfigurationFactory configFactory)
        {
            _view          = view;
            _ruleProvider  = ruleProvider;
            _configFactory = configFactory;

            IEnumerable <IRule> rules = _ruleProvider.GetRules(_configFactory);

            _view.DisplayRules(rules.OrderBy(p => p.Category));
        }
예제 #5
0
        public override void SetUp()
        {
            base.SetUp();

            _ruleTreeView  = Mocker.DynamicMock <IRuleTreeView>();
            _view          = Mocker.DynamicMock <IRuleConfigurationView>();
            _provider      = Mocker.DynamicMock <ICalidusRuleProvider>();
            _configFactory = Mocker.DynamicMock <ICalidusRuleConfigurationFactory>();

            Expect.Call(_view.RuleTreeView).Return(_ruleTreeView).Repeat.Any();
        }
예제 #6
0
        /// <summary>
        /// Create a new instance of this class
        /// </summary>
        /// <param name="view">The view to use</param>
        /// <param name="runner">The runner to use</param>
        /// <param name="project">The projectmodel to use</param>
        public RuleRunnerController(IRuleRunnerView view, IRuleRunner runner, ICalidusProjectModel project, ICalidusRuleConfigurationFactory configFactory)
        {
            _view = view;
            _view.RuleRunnerStart += new EventHandler <EventArgs>(_view_RuleRunnerStart);

            _runner = runner;
            _runner.FileCompleted += new EventHandler <FileCompletedEventArgs>(_runner_FileCompleted);

            _project = project;

            _configFactory = configFactory;
        }
예제 #7
0
        public void FactoryShouldThrowExceptionForUnCreateableRules()
        {
            RuleFactory factory = new RuleFactory(GetType().Assembly.GetTypes(), null, null);
            ICalidusRuleConfigurationFactory configFactory = Mocker.DynamicMock <ICalidusRuleConfigurationFactory>();

            Assert.Throws <CalidusException>(delegate
            {
                factory.GetStatementRules(configFactory);
            },
                                             "Found rule UnCreatableRule, but an instance could not be created because the rule configuration does not match the constructor and no default no-args constructor was found"
                                             );
        }
예제 #8
0
        /// <summary>
        /// Gets a list of all block rules with settings for the specified project
        /// </summary>
        /// <param name="configFactory">The configuration factory to use</param>
        /// <returns>The rules</returns>
        public IEnumerable <BlockRuleBase> GetBlockRules(ICalidusRuleConfigurationFactory configFactory)
        {
            List <BlockRuleBase> blockRules = new List <BlockRuleBase>();

            foreach (IBlockRuleFactory aFactory in _blockRuleProvider.GetBlockRuleFactories())
            {
                foreach (BlockRuleBase aBlockRule in aFactory.GetBlockRules(configFactory))
                {
                    blockRules.Add(aBlockRule);
                }
            }

            return(blockRules);
        }
예제 #9
0
        /// <summary>
        /// Gets a  list of all statement rules with settings for the specified project
        /// </summary>
        /// <param name="configFactory">The configuration factory to use</param>
        /// <returns>The rules</returns>
        public IEnumerable <StatementRuleBase> GetStatementRules(ICalidusRuleConfigurationFactory configFactory)
        {
            IList <StatementRuleBase> statementRules = new List <StatementRuleBase>();

            foreach (IStatementRuleFactory aFactory in _statementRuleProvider.GetStatementRuleFactories())
            {
                foreach (StatementRuleBase aStatementRule in aFactory.GetStatementRules(configFactory))
                {
                    statementRules.Add(aStatementRule);
                }
            }

            return(statementRules);
        }
예제 #10
0
        /// <summary>
        /// Gets a list of all line rules with settings for the specified project
        /// </summary>
        /// <param name="configFactory">The configuration factory to use</param>
        /// <returns>The rules</returns>
        public IEnumerable <LineRuleBase> GetLineRules(ICalidusRuleConfigurationFactory configFactory)
        {
            List <LineRuleBase> lineRules = new List <LineRuleBase>();

            foreach (ILineRuleFactory aFactory in _lineRuleProvider.GetLineRuleFactories())
            {
                foreach (LineRuleBase aLineRule in aFactory.GetLineRules(configFactory))
                {
                    lineRules.Add(aLineRule);
                }
            }

            return(lineRules);
        }
예제 #11
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();
        }
예제 #12
0
        private IEnumerable <TType> GetRules <TType>(ICalidusRuleConfigurationFactory configFactory)
            where TType : IRule
        {
            List <TType> result = new List <TType>();

            foreach (Type aType in _parsed)
            {
                TType ruleInstance = default(TType);

                //make sure to ignore the interface itself
                if (typeof(TType).IsAssignableFrom(aType))
                {
                    try
                    {
                        //not in default, try for a no-args constructor
                        if (aType.GetConstructor(new Type[] { }) != null)
                        {
                            ruleInstance = _instanceCreator.CreateInstanceOf <TType>(aType);
                        }
                        //try the factory
                        else
                        {
                            ruleInstance = _instanceCreator.CreateInstanceOf <TType>(aType, configFactory.GetRuleConfigurationFor(aType).ArgumentArray);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ruleInstance == null)
                        {
                            throw new CalidusException(String.Format(_exMsg, aType.Name), ex);
                        }
                    }

                    if (ruleInstance == null)
                    {
                        throw new CalidusException(String.Format(_exMsg, aType.Name));
                    }

                    result.Add(ruleInstance);
                }
            }

            return(result);
        }
예제 #13
0
        /// <summary>
        /// Creates a new instance of this class
        /// </summary>
        /// <param name="view">The view to use</param>
        /// <param name="provider">The rule provider to use</param>
        /// <param name="configFactory">The configuration factory to use</param>
        public RuleConfigurationController(IRuleConfigurationView view, ICalidusRuleProvider provider, ICalidusRuleConfigurationFactory configFactory)
        {
            HasChanges = false;

            _configFactory = configFactory;

            _provider = provider;

            _view = view;
            _view.RuleTreeView.BeforeRuleSelectionChanged += new EventHandler <RuleChangeCancelEventArgs>(RuleTreeView_BeforeRuleSelectionChanged);
            _view.RuleTreeView.RuleSelectionChanged       += new EventHandler <RuleEventArgs>(RuleTreeView_RuleSelectionChanged);
            _view.SelectedRuleParameterChanged            += new EventHandler <RuleConfigurationParameterEventArgs>(_view_SelectedRuleParameterChanged);
            _view.RuleParameterSettingsChanged            += new EventHandler <EventArgs>(_view_RuleParameterSettingsChanged);
            _view.Save    += new EventHandler <RuleConfigurationChangeCommandEventArgs>(_view_Save);
            _view.Closing += new EventHandler <RuleChangeCancelEventArgs>(_view_Closing);

            IEnumerable <IRule> rules = _provider.GetRules(_configFactory);

            _view.DisplayRules(rules);
        }
예제 #14
0
        /// <summary>
        /// Gets a list of all the rules with settings for the specified project
        /// </summary>
        /// <param name="configFactory">The configuration factory to use</param>
        /// <returns>The rules</returns>
        public IEnumerable <IRule> GetRules(ICalidusRuleConfigurationFactory configFactory)
        {
            IList <IRule> rules = new List <IRule>();

            foreach (StatementRuleBase aRule in GetStatementRules(configFactory))
            {
                rules.Add(aRule);
            }

            foreach (BlockRuleBase aRule in GetBlockRules(configFactory))
            {
                rules.Add(aRule);
            }

            foreach (LineRuleBase aRule in GetLineRules(configFactory))
            {
                rules.Add(aRule);
            }

            return(rules);
        }
예제 #15
0
 /// <summary>
 /// Gets the list of line rules for the project
 /// </summary>
 /// <param name="configFactory">The configuration factory to use</param>
 /// <returns>The list of line rules</returns>
 public IEnumerable <LineRuleBase> GetLineRules(ICalidusRuleConfigurationFactory configFactory)
 {
     return(GetRules <LineRuleBase>(configFactory));
 }
예제 #16
0
 /// <summary>
 /// Gets the list of block rules in the specified project
 /// </summary>
 /// <param name="configFactory">The configuration factory to use</param>
 /// <returns>The rules</returns>
 public IEnumerable <BlockRuleBase> GetBlockRules(ICalidusRuleConfigurationFactory configFactory)
 {
     return(_factory.GetBlockRules(configFactory));
 }
예제 #17
0
파일: RuleRunner.cs 프로젝트: jdt/calidus
        /// <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));
            }
        }
예제 #18
0
 /// <summary>
 /// Gets the list of statement rules for the project
 /// </summary>
 /// <param name="configFactory">The configuration factory to use</param>
 /// <returns>The statement rules</returns>
 public IEnumerable <StatementRuleBase> GetStatementRules(ICalidusRuleConfigurationFactory configFactory)
 {
     return(GetRules <StatementRuleBase>(configFactory));
 }
예제 #19
0
 /// <summary>
 /// Create a new instance of this class
 /// </summary>
 /// <param name="view">The view to use</param>
 /// <param name="ruleProvider">The rule provider to use</param>
 /// <param name="configFactory">The configuration factory to use</param>
 public CheckableRuleTreeController(ICheckableRuleTreeView view, ICalidusRuleProvider ruleProvider, ICalidusRuleConfigurationFactory configFactory)
     : base(view, ruleProvider, configFactory)
 {
 }