public void TestGetRuleByName() { RuleCollection rc = new RuleCollection((IRandom)m_Random.MockInstance); Rule rule1 = new Rule(); rule1.Name = "r"; rule1.Probability = 1.0; rc.Add(rule1); m_Random.ExpectAndReturn("NextDouble", 0.0); Assert.AreSame(rule1, rc.GetRuleByName("r")); Rule rule2 = new Rule(); rule2.Name = "r"; rule2.Probability = 1.0; rc.Add(rule2); m_Random.ExpectAndReturn("NextDouble", 0.2); Assert.AreSame(rule1, rc.GetRuleByName("r"), "rule 1 expected"); m_Random.ExpectAndReturn("NextDouble", 0.6); Assert.AreSame(rule2, rc.GetRuleByName("r"), "rule 2 expected"); m_Random.Verify(); }
public void ThereCanOnlybeOneInstanceOfARuleInACollection() { RuleCollection ruleList = new RuleCollection(); SingleRule testRule = new SingleRule(7, SpawnOrSurviveRule.SpawnRule); SingleRule testRule2 = new SingleRule(7, SpawnOrSurviveRule.SpawnRule); ruleList.Add(testRule); ruleList.Add(testRule2); Assert.AreEqual(1, ruleList.Count); }
public void ValidateContraintNoopTest() { UnityContainer container = new UnityContainer(); container.RegisterType <IEngine <TestModel>, Engine <TestModel> >(); IRuleCollection <TestModel> coll = new RuleCollection <TestModel>(); container.RegisterType <IResultsFormatter, NoopFormatter>(); coll.Add(new Add()); coll.Add(new Subtract()); container.RegisterInstance(coll); var engine = container.Resolve <IEngine <TestModel> >(); engine.ValidateContraints(null); }
private void RuleRibbonToggleButton_PressedButtonChanged(object sender, EventArgs e) { if (!(sender is RibbonToggleButton pressedRule)) { return; } string ruleName = pressedRule.Text; bool pressed = pressedRule.Pressed; IRule newRule = _rules.Where(x => x.Name == ruleName).FirstOrDefault(); newRule.AppliesTo.Add(new FieldRange(new string[] { "Product", "Country", "Color", "Discount" })); RuleCollection appliedRules = _rulesManager.Rules; IRule existingRule = appliedRules.Where(x => x.Name == ruleName).FirstOrDefault(); if (!pressed && appliedRules.Contains(existingRule)) { appliedRules.Remove(existingRule); } if (pressed && existingRule is null) { appliedRules.Add(newRule); } }
protected override RuleCollection ParseRules(IEnumerable <TransportRule> adTransportRules, RuleHealthMonitor ruleHealthMonitor) { RuleCollection ruleCollection = base.ParseRules(adTransportRules, ruleHealthMonitor); RuleCollection ruleCollection2 = new RuleCollection(ruleCollection.Name); foreach (Rule rule in ruleCollection) { PolicyTipRule policyTipRule = (PolicyTipRule)rule; foreach (Microsoft.Exchange.MessagingPolicies.Rules.Action action in policyTipRule.Actions) { if (action is SenderNotify) { if (policyTipRule.ForkConditions != null && policyTipRule.ForkConditions.Count > 0) { AndCondition andCondition = new AndCondition(); foreach (Condition item in policyTipRule.ForkConditions) { andCondition.SubConditions.Add(item); } andCondition.SubConditions.Add(policyTipRule.Condition); policyTipRule.Condition = andCondition; policyTipRule.ForkConditions = null; } ruleCollection2.Add(policyTipRule); break; } } } return(ruleCollection2); }
public void RuleConstructorTest() { Dictionary <char, string> jokers = new Dictionary <char, string>(); RuleCollection collection = new RuleCollection(); collection.Add(new Rule("ate", "ejt", jokers, collection)); }
public void IfAnInvalidRuleIsAppliedStateWillNotProgress() { RuleCollection testRuleCollection = new RuleCollection(); testRuleCollection.Add(new SingleRule(0, SpawnOrSurviveRule.SpawnRule)); testRuleCollection.Add(new SingleRule(4, SpawnOrSurviveRule.SurviveRule)); Map testMap = new Map(); testMap.AddCellAtCoordinate(1, 1); testMap.AddCellAtCoordinate(2, 1); testMap.AddCellAtCoordinate(3, 1); testMap.AddCellAtCoordinate(3, 2); GameController myController = new GameController(testMap, testRuleCollection); Assert.IsFalse(myController.ProgressState()); }
public void ThereCanBeMultipleRulesInACollection() { RuleCollection ruleList = new RuleCollection(); SingleRule testRule = new SingleRule(7, SpawnOrSurviveRule.SpawnRule); SingleRule testRule2 = new SingleRule(8, SpawnOrSurviveRule.SpawnRule); SingleRule testRule3 = new SingleRule(8, SpawnOrSurviveRule.SurviveRule); SingleRule testRule4 = new SingleRule(7, SpawnOrSurviveRule.SpawnRule); ruleList.Add(testRule); ruleList.Add(testRule2); ruleList.Add(testRule3); ruleList.Add(testRule4); Assert.AreEqual(3, ruleList.Count); }
public async Task InsertRules(List <RuleModel> rules, string connectionString) { string parameterName = "rules"; RuleCollection ruleCollection = new RuleCollection(); foreach (var rule in rules) { ruleCollection.Add(rule); } await _db.InsertWithUDT("dbo.spInsertRules", parameterName, ruleCollection, connectionString); }
public void CombinedRulesWork() { RuleCollection testRuleCollection = new RuleCollection(); testRuleCollection.Add(new SingleRule(3, SpawnOrSurviveRule.SpawnRule)); testRuleCollection.Add(new SingleRule(3, SpawnOrSurviveRule.SurviveRule)); testRuleCollection.Add(new SingleRule(2, SpawnOrSurviveRule.SurviveRule)); Map testMap = new Map(); testMap.AddCellAtCoordinate(1, 0); testMap.AddCellAtCoordinate(2, 0); testMap.AddCellAtCoordinate(3, 0); GameController myController = new GameController(testMap, testRuleCollection); bool success = myController.ProgressState(); Assert.IsTrue(success); Assert.AreEqual(3, myController.Map.LivingCells.Count); }
public void IfNoSurviveRuleIsMetCellIsRemoveded() { RuleCollection testRuleCollection = new RuleCollection(); testRuleCollection.Add(new SingleRule(1, SpawnOrSurviveRule.SurviveRule)); testRuleCollection.Add(new SingleRule(2, SpawnOrSurviveRule.SurviveRule)); Map testMap = new Map(); testMap.AddCellAtCoordinate(1, 1); testMap.AddCellAtCoordinate(2, 1); testMap.AddCellAtCoordinate(3, 1); testMap.AddCellAtCoordinate(3, 2); GameController myController = new GameController(testMap, testRuleCollection); myController.ProgressState(); Assert.AreEqual(3, myController.Map.LivingCells.Count); }
private void OK_Click(object sender, RoutedEventArgs e) { RuleCollection newRules = (RuleCollection)(dataGridExamples.ItemsSource); foreach (var rule in newRules) { oldRules.Add(rule); } this.DialogResult = true; this.Close(); }
/// <summary> /// Searches through the full rules collection for any Rule objects which contain the search term in their title or their text. /// </summary> /// <param name="searchTerm"></param> private void SearchRules(string searchTerm) { searchedRuleset = new RuleCollection(); foreach (RuleRef r in fullRuleset) { if (r.Title.ToUpper().Contains(searchTerm.ToUpper()) || r.Details.ToUpper().Contains(searchTerm.ToUpper())) { searchedRuleset.Add(r); } } PopulateRulesList(searchedRuleset); }
internal void ProcessRuleChange(SingleRule newRule, bool added) { if (added && !rules.Contains(newRule)) { rules.Add(newRule); } else if (!added && rules.Contains(newRule)) { rules.Remove(newRule); } gridController.ActiveRules = rules; }
private void ReverseTransliteration_Click(object sender, RoutedEventArgs e) { repository.SwapSourceAndDestination(); Transliterator reverseTransliterator = new Transliterator(repository, repository.srcLanguage.Code, repository.dstLanguage.Code); RuleCollection ruleCollection = (RuleCollection)(dataGridRules.ItemsSource); RuleCollection newRuleCollection = new RuleCollection(); var rules = repository.ListRules(true); foreach (var rule in rules) { if (rule.Destination.Length == 0) { continue; } string newSource = rule.Destination, newDestination = rule.Source; if (newDestination.StartsWith("|")) { newSource = "|" + newSource; newDestination = newDestination.Substring(1); } if (newDestination.EndsWith("|")) { newSource = newSource + "|"; newDestination = newDestination.Substring(0, newDestination.Length - 1); } if (!ruleCollection.All(r => newSource != r.Source)) { continue; } newRuleCollection.Add(new TransliterationRule(newSource, newDestination, reverseTransliterator.Transliterate(rule.Examples) )); } // Show the dialog RuleCollection oldRules = (RuleCollection)(dataGridRules.ItemsSource); var reverseTransliterationWindow = new ReverseTransliteration(newRuleCollection, oldRules); reverseTransliterationWindow.ShowDialog(); repository.SwapSourceAndDestination(); }
public void OnlyRuleTest() { UnityContainer container = new UnityContainer(); container.RegisterType <IEngine <TestModel>, Engine <TestModel> >(); IRuleCollection <TestModel> coll = new RuleCollection <TestModel>(); container.RegisterType <IResultsFormatter, NoopFormatter>(); coll.Add(new Add()); coll.Add(new Subtract()); container.RegisterInstance(coll); var engine = container.Resolve <IEngine <TestModel> >(); var model = new TestModel() { A = 2, B = 4 }; var results = engine.Execute(model, null, new List <Type>() { typeof(Subtract) }); Assert.AreEqual(1, results.Count); // only one rule should run Assert.AreEqual(4, model.Result); }
public void OriginalMapIsUnchangedAfterProgressing() { RuleCollection testRuleCollection = new RuleCollection(); testRuleCollection.Add(new SingleRule(1, SpawnOrSurviveRule.SpawnRule)); Map testMap = new Map(); testMap.AddCellAtCoordinate(1, 1); testMap.AddCellAtCoordinate(3, 1); GameController myController = new GameController(testMap, testRuleCollection); myController.ProgressState(); Assert.AreEqual(2, testMap.LivingCells.Count); }
/// <summary> /// /// </summary> /// <param name="filename"></param> /// <param name="langage"></param> public void LoadFromXML(string filename, string langage) { rules = new RuleCollection(); XmlDocument doc = new XmlDocument(); try { doc.Load(filename); XmlNode root = doc.ChildNodes[1]; XmlNode lngNode; for (int i = 0; i < root.ChildNodes.Count; i++) { if (root.ChildNodes[i].Attributes["name"].Value == langage) { lngNode = root.ChildNodes[i]; this.isCaseSensitive = bool.Parse(lngNode.Attributes["casesensitive"].Value); XmlNode rulesNode = lngNode.FirstChild; for (int j = 0; j < rulesNode.ChildNodes.Count; j++) { //rulesNode = rulesNode.ChildNodes[j]; /*Console.WriteLine("{0} : {1}", rulesNode.ChildNodes[j].Attributes["expression"].Value, * rulesNode.ChildNodes[j].Attributes["type"].Value);*/ rules.Add( rulesNode.ChildNodes[j].Attributes["expression"].Value, rulesNode.ChildNodes[j].Attributes["type"].Value, this.isCaseSensitive); } } } doc = null; } catch (Exception ex) { Console.WriteLine(ex.Message); return; } }
public void AddRule(LogRule rule) { _rules.Add(rule); }