public void TestTextCommandDispose() { var testCommand = new TextCommandModel() { Commands = new List<String>() { "DisposeTest" } }; testCommand.Dispose(); Assert.AreEqual(TextCommandParserType.Fuzzy, testCommand.Parser); Assert.AreEqual(Guid.Empty, testCommand.PluginGuid); Assert.IsNull(testCommand.PluginCommand); Assert.IsNull(testCommand.Description); Assert.IsNull(testCommand.Commands); }
public void TestSingleCommandMatching() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); AssertExecutedCommand(ExecuteTextCommand(textCommandController, "Command"), command); }
public void TestCommandNumber() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :number" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); AssertExecutedCommandAgainstNumericValue(ExecuteTextCommand(textCommandController, "Command 10"), command, 10); }
public void TestCommandNumberSentence() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :number :text" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); ICommandResult result = ExecuteTextCommand(textCommandController, "command 20 for something and something"); AssertExecutedCommandAgainstNumericValue(result, command, 20); AssertExecutedCommandAgainstSentencesList(result, command, new List<String>() { "for something and something" }); }
public void TestTextCommandControllerDispose() { var textCommands = new TextCommandController(); var testCommand = new TextCommandModel() { Commands = new List<String>() { "DisposeTest" } }; textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { testCommand }) }); textCommands.Dispose(); Assert.IsNull(textCommands.TextCommands); Assert.IsNull(textCommands.Connection); }
protected static void AssertTemporalCommand(TextCommandController textCommandController, String command, TextCommandModel primaryCommand, TimeSpan? period = null, DateTime? delay = null, FuzzyDateTimePattern interval = null) { ICommandResult args = ExecuteTextCommand(textCommandController, command); AssertExecutedCommandAgainstTemporalValue(args, primaryCommand, period, delay, interval); }
protected static void AssertCommandSentencesList(TextCommandController textCommandController, String command, TextCommandModel primaryCommand, List<String> sentences) { ICommandResult args = ExecuteTextCommand(textCommandController, command); AssertExecutedCommandAgainstSentencesList(args, primaryCommand, sentences); }
public void TestCommandPlayerForText() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :player for :text" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); ICommandResult result = ExecuteTextCommand(textCommandController, "command phogue for some time"); AssertExecutedCommandAgainstSentencesList(result, command, new List<String>() { "some time" }); AssertExecutedCommandAgainstPlayerListMapList(result, command, new List<PlayerModel>() { PlayerPhogue }, new List<MapModel>()); }
public void TestCommandPlayerMap() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :map" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); AssertCommandPlayerListMapList(textCommandController, "Command port valdez", command, new List<PlayerModel>() , new List<MapModel>() { MapPortValdez }); }
public void TestCommandPlayerTextPlayerNumber() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :player :text :player :number" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); ICommandResult result = ExecuteTextCommand(textCommandController, "command phogue something, something, something dark side morpheus 25"); AssertExecutedCommandAgainstSentencesList(result, command, new List<String>() { "something, something, something dark side" }); AssertExecutedCommandAgainstNumericValue(result, command, 25); AssertExecutedCommandAgainstPlayerListMapList(result, command, new List<PlayerModel>() { PlayerPhogue, PlayerMorpheus }, new List<MapModel>()); }
/// <summary> /// Validates the results of an executed player/maps combination command /// </summary> /// <param name="args">The generated event from the already executed command.</param> /// <param name="primaryCommand">The command to check against - the returning primary command must be this</param> /// <param name="players">The list of players that must be in the resulting matched players (nothing more, nothing less)</param> /// <param name="maps">The list of maps that must be in the resulting matched maps (nothing more, nothing less)</param> protected static void AssertExecutedCommandAgainstPlayerListMapList(ICommandResult args, TextCommandModel primaryCommand, ICollection<PlayerModel> players, ICollection<MapModel> maps) { Assert.AreEqual(primaryCommand, args.Now.TextCommands.First(), String.Format("Has not used the '{0}' command", primaryCommand.PluginCommand)); Assert.AreEqual(players.Count, args.Now.TextCommandMatches.First().Players != null ? args.Now.TextCommandMatches.First().Players.Count : 0, "Incorrect numbers of players returned"); Assert.AreEqual(maps.Count, args.Now.TextCommandMatches.First().Maps != null ? args.Now.TextCommandMatches.First().Maps.Count : 0, "Incorrect numbers of maps returned"); foreach (PlayerModel player in players) { Assert.IsTrue(args.Now.TextCommandMatches.First().Players.Contains(player) == true, String.Format("Could not find player '{0}'", player.Name)); } foreach (MapModel map in maps) { Assert.IsTrue(args.Now.TextCommandMatches.First().Maps.Contains(map) == true, String.Format("Could not find map '{0}'", map.Name)); } }
public void TestCommandPlayerPlayer() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :player :player" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); AssertCommandPlayerListMapList(textCommandController, "Command phogue morpheus", command, new List<PlayerModel>() { PlayerPhogue, PlayerMorpheus }, new List<MapModel>()); }
protected static void AssertExecutedCommandAgainstSentencesList(ICommandResult args, TextCommandModel primaryCommand, List<String> sentences) { Assert.AreEqual(primaryCommand, args.Now.TextCommands.First(), String.Format("Has not used the '{0}' command", primaryCommand.PluginCommand)); Assert.AreEqual(sentences.Count, args.Now.TextCommandMatches.First().Quotes != null ? args.Now.TextCommandMatches.First().Quotes.Count : 0, "Incorrect numbers of sentences returned"); foreach (String sentence in sentences) { Assert.IsTrue(args.Now.TextCommandMatches.First().Quotes.Contains(sentence) == true, String.Format("Could not find sentence '{0}'", sentence)); } }
/// <summary> /// Executes a command and validates the results against a simple player and map list. /// </summary> /// <param name="textCommandController"></param> /// <param name="command">The text command to execute</param> /// <param name="primaryCommand">The command to check against - the returning primary command must be this</param> /// <param name="players">The list of players that must be in the resulting matched players (nothing more, nothing less)</param> /// <param name="maps">The list of maps that must be in the resulting matched maps (nothing more, nothing less)</param> protected static void AssertCommandPlayerListMapList(TextCommandController textCommandController, String command, TextCommandModel primaryCommand, ICollection<PlayerModel> players, List<MapModel> maps) { ICommandResult args = ExecuteTextCommand(textCommandController, command); AssertExecutedCommandAgainstPlayerListMapList(args, primaryCommand, players, maps); }
protected static void AssertExecutedCommandAgainstTemporalValue(ICommandResult args, TextCommandModel primaryCommand, TimeSpan? period = null, DateTime? delay = null, FuzzyDateTimePattern interval = null) { Assert.AreEqual(primaryCommand, args.Now.TextCommands.First(), String.Format("Has not used the '{0}' command", primaryCommand.PluginCommand)); TextCommandMatchModel match = args.Now.TextCommandMatches.First(); Assert.IsNotNull(match); if (period.HasValue == true) { Assert.IsNotNull(match.Period); Assert.AreEqual(Math.Ceiling(period.Value.TotalSeconds), Math.Ceiling(match.Period.Value.TotalSeconds)); } else { Assert.IsNull(match.Period); } if (delay.HasValue == true) { Assert.IsNotNull(match.Delay); // Note that the delay is generated then passed through to the test, which then needs // to create a DateTime. We allow a little give here of a second or so for execution times. // If it's longer than that then we should be optimizing anyway. // Whatever is passed into this function is generated after the command has been run. Assert.IsTrue(delay.Value - match.Delay.Value < new TimeSpan(TimeSpan.TicksPerSecond * 1)); // Assert.AreEqual(delay.Value, args.After.TextCommandMatches.First().Delay.Value); } else { Assert.IsNull(match.Delay); } if (interval != null) { Assert.IsNotNull(match.Interval); Assert.AreEqual(interval.ToString(), match.Interval.ToString()); } else { Assert.IsNull(match.Interval); } }
/// <summary> /// Little helper used for basic arithmetic tests /// </summary> /// <param name="textCommandController"></param> /// <param name="command">The text command to execute</param> /// <param name="primaryCommand">The command to check against - the returning primary command must be this</param> /// <param name="value">The value of the arithmetic return. There must be only one value returned.</param> protected static void AssertNumericCommand(TextCommandController textCommandController, String command, TextCommandModel primaryCommand, float value) { ICommandResult args = ExecuteTextCommand(textCommandController, command); AssertExecutedCommandAgainstNumericValue(args, primaryCommand, value); }
/// <summary> /// Validates the results of an executed arithmetic command /// </summary> /// <param name="args">The generated event from the already executed command.</param> /// <param name="primaryCommand">The command to check against - the returning primary command must be this</param> /// <param name="value">The value of the arithmetic return. There must be only one value returned.</param> protected static void AssertExecutedCommandAgainstNumericValue(ICommandResult args, TextCommandModel primaryCommand, float value) { Assert.AreEqual(primaryCommand, args.Now.TextCommands.First(), String.Format("Has not used the '{0}' command", primaryCommand.PluginCommand)); Assert.AreEqual(1, args.Now.TextCommandMatches.First().Numeric.Count, "Not exactly one numeric value returned"); Assert.AreEqual(value, args.Now.TextCommandMatches.First().Numeric.FirstOrDefault()); }
public void TestCommandTextSingleWord() { TextCommandController textCommandController = CreateTextCommandController(); TextCommandModel command = new TextCommandModel() { Commands = new List<string>() { "Command :text" }, Parser = TextCommandParserType.Route, PluginCommand = "Command", Description = "Command" }; textCommandController.TextCommands.Add(command); AssertCommandSentencesList(textCommandController, "Command hello", command, new List<String>() { "hello" }); }
protected static void AssertExecutedCommand(ICommandResult args, TextCommandModel primaryCommand) { Assert.AreEqual(primaryCommand, args.Now.TextCommands.First(), String.Format("Has not used the '{0}' command", primaryCommand.PluginCommand)); }