// ---------------- Test Helpers ---------------- private void DoFindCommandTest( CommandDefinitionCollection list, string fullCommand, MeetingAction expectedAction, string expectedPrefix, string expectedArgs ) { CommandDefinitionFindResult foundDef = list.Find(fullCommand); // Ensure only one command is returned, or we have duplicates. Assert.IsNotNull(foundDef); Assert.AreEqual(expectedPrefix, foundDef.CommandPrefix); Assert.AreEqual(expectedArgs, foundDef.CommandArgs); Assert.AreEqual(expectedAction, foundDef.FoundDefinition.MeetingAction); // Check dictionaries for sameness. Assert.AreSame( list.MeetingActionToCommandDef[foundDef.FoundDefinition.MeetingAction], foundDef.FoundDefinition ); Regex foundRegex = list.MeetingActionToRegex[foundDef.FoundDefinition.MeetingAction]; Assert.AreSame( list.RegexToCommandDef[foundRegex], foundDef.FoundDefinition ); }
public void TestSetup() { this.logger = new GenericLogger(); this.xmlLoader = new XmlLoader(this.logger); string xmlString; using (Stream s = typeof(CommandDefinitionCollection).Assembly.GetManifestResourceStream("Chaskis.Plugins.MeetBot.Config.SampleCommands.xml")) { using (StreamReader reader = new StreamReader(s)) { xmlString = reader.ReadToEnd(); } } // Replace all occurrances with !command instead of #command. xmlString = xmlString.Replace("<prefix>#", "<prefix>!"); // Load both default and user-defined. User-defined will override the default ones. IList <CommandDefinition> defaultDefs = this.xmlLoader.ParseDefaultFile(); IList <CommandDefinition> userDefs = this.xmlLoader.ParseCommandFileFromString(xmlString); List <CommandDefinition> allDefs = new List <CommandDefinition>(defaultDefs); allDefs.AddRange(userDefs); this.collection = new CommandDefinitionCollection(allDefs); // Ensure our collection validates. Assert.DoesNotThrow(() => collection.InitStage1_ValidateDefinitions()); Assert.DoesNotThrow(() => collection.InitStage2_FilterOutOverrides()); }
public void TestSetup() { this.logger = new GenericLogger(); this.xmlLoader = new XmlLoader(this.logger); IList <CommandDefinition> defs = this.xmlLoader.ParseDefaultFile(); this.collection = new CommandDefinitionCollection(defs); // Ensure our collection validates. Assert.DoesNotThrow(() => collection.InitStage1_ValidateDefinitions()); Assert.DoesNotThrow(() => collection.InitStage2_FilterOutOverrides()); }
// ---------------- Test Helpers ---------------- private void CommandExists( CommandDefinitionCollection list, string prefix, MeetingAction expectedAction, CommandRestriction expectedRestriction ) { IEnumerable <CommandDefinition> defs = list.CommandDefinitions.Where(d => d.Prefixes.Contains(prefix)); // Ensure only one command is returned, or we have duplicates. Assert.AreEqual(1, defs.Count()); // Ensure everything matches what we expect. CommandDefinition def = defs.First(); Assert.AreEqual(expectedAction, def.MeetingAction); Assert.AreEqual(expectedRestriction, def.Restriction); Assert.IsTrue(def.IsDefault); Assert.IsTrue(def.GetPrefixRegex().IsMatch(prefix)); }