public void RuleConfigurationControllerShouldGetAndDisplayRuleConfigurationOnRuleSelectionChanged() { IRule rule = Mocker.DynamicMock <IRule>(); IRuleConfiguration ruleConfig = Mocker.DynamicMock <IRuleConfiguration>(); Expect.Call(_configFactory.GetRuleConfigurationFor(rule.GetType())).Return(ruleConfig).Repeat.Once(); Expect.Call(() => _view.DisplayRuleConfiguration(ruleConfig)).Repeat.Once(); Mocker.ReplayAll(); RuleConfigurationController controller = new RuleConfigurationController(_view, _provider, _configFactory); _view.RuleTreeView.Raise(x => x.RuleSelectionChanged += null, this, new RuleEventArgs(rule)); Mocker.VerifyAll(); }
private void RuleTreeView_RuleSelectionChanged(object sender, RuleEventArgs e) { if (e.SelectedRule != null) { IRuleConfiguration config = _configFactory.GetRuleConfigurationFor(e.SelectedRule.GetType()); _view.DisplayRuleConfiguration(config); CurrentConfiguration = config; } else { _view.ClearRuleConfiguration(); CurrentConfiguration = null; } HasChanges = false; }
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); }