public void TestTextCommandRegister() { var textCommands = new TextCommandController(); ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = Guid.NewGuid(), PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); Assert.IsTrue(result.Success); Assert.AreEqual(CommandResultType.Success, result.CommandResultType); Assert.AreEqual(1, textCommands.TextCommands.Count); Assert.AreEqual("RegisterTest", textCommands.TextCommands.First().Commands.First()); }
public void TestTextCommandParsingExecute() { var textCommands = new TextCommandController() { //Languages = languages, Connection = new ConnectionController() { Protocol = new SandboxProtocolController() { SandboxedProtocol = new MockProtocol() { Additional = "", Password = "" } } }.Execute() as ConnectionController }; textCommands.Execute(); textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = Guid.NewGuid(), PluginCommand = "Command1", Commands = new List<String>() { "ExecuteTest" } } } } } } }); Assert.AreEqual(1, textCommands.TextCommands.Count); Assert.AreEqual("ExecuteTest", textCommands.TextCommands.First().Commands.First()); ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsExecute, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "ExecuteTest stuff" }) }); Assert.IsTrue(result.Success); Assert.AreEqual(CommandResultType.Success, result.CommandResultType); }
public void TestTextCommandRegisterDuplication() { var textCommands = new TextCommandController(); var guid = Guid.NewGuid(); textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = guid, PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = guid, PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.AlreadyExists, result.CommandResultType); Assert.AreEqual(1, textCommands.TextCommands.Count); }
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); }
public void TestTextCommandParsingExecuteInsufficientPermissions() { var textCommands = new TextCommandController() { Shared = { Security = new SecurityController().Execute() as SecurityController } }; ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Remote, Authentication = { Username = "******" }, CommandType = CommandType.TextCommandsExecute, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "!test something something something dark side" }) }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType); }
public void TestTextCommandParsingExecuteUsePreferredLanguage() { var security = (SecurityController)new SecurityController().Execute(); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAddGroup, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "TestGroup" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupAddAccount, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "TestGroup", "Phogue" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAccountAddPlayer, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "Phogue", CommonProtocolType.DiceBattlefield3, "EA_63A9F96745B22DFB509C558FC8B5C50F" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAccountSetPreferredLanguageCode, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "Phogue", "de-DE" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupSetPermission, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "TestGroup", CommandType.TextCommandsExecute, 100 }) }); var textCommands = new TextCommandController() { Shared = { Security = security }, //Languages = languages, Connection = new ConnectionController() { Protocol = new SandboxProtocolController() { SandboxedProtocol = new MockProtocol() { Additional = "", Password = "" } } }.Execute() as ConnectionController }; textCommands.Execute(); textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = Guid.NewGuid(), PluginCommand = "Command1", Commands = new List<String>() { "ExecuteTest" } } } } } } }); Assert.AreEqual(1, textCommands.TextCommands.Count); Assert.AreEqual("ExecuteTest", textCommands.TextCommands.First().Commands.First()); ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Plugin, Authentication = { Username = "******" }, CommandType = CommandType.TextCommandsExecute, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "ExecuteTest stuff" }) }); Assert.IsTrue(result.Success); Assert.AreEqual(CommandResultType.Success, result.CommandResultType); }
public void TestTextCommandUnregisterDoesNotExist() { var textCommands = new TextCommandController(); ICommandResult result = textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsUnregister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = Guid.NewGuid(), PluginCommand = "Command1" } } } } } }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.DoesNotExists, result.CommandResultType); }
public void TestTextCommandUnregisterInsufficientPermission() { var textCommands = new TextCommandController(); var guid = Guid.NewGuid(); textCommands.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = guid, PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); // Test that the initial command was entered before we attempt to remove it. Assert.AreEqual(1, textCommands.TextCommands.Count); Assert.AreEqual("RegisterTest", textCommands.TextCommands.First().Commands.First()); ICommandResult result = textCommands.Tunnel(new Command() { Authentication = { Username = "******" }, Origin = CommandOrigin.Remote, CommandType = CommandType.TextCommandsUnregister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = guid, PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType); }
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); }
public void TestTextCommandRegisterInsufficientPermission() { var textCommands = new TextCommandController(); ICommandResult result = textCommands.Tunnel(new Command() { Authentication = { Username = "******" }, Origin = CommandOrigin.Remote, CommandType = CommandType.TextCommandsRegister, Parameters = new List<ICommandParameter>() { new CommandParameter() { Data = { TextCommands = new List<TextCommandModel>() { new TextCommandModel() { PluginGuid = Guid.NewGuid(), PluginCommand = "Command1", Commands = new List<String>() { "RegisterTest" } } } } } } }); Assert.IsFalse(result.Success); Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType); }
/// <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> /// 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 AssertCommandSentencesList(TextCommandController textCommandController, String command, TextCommandModel primaryCommand, List<String> sentences) { ICommandResult args = ExecuteTextCommand(textCommandController, command); AssertExecutedCommandAgainstSentencesList(args, primaryCommand, sentences); }
/// <summary> /// Executes a command as the username "Phogue" by default /// </summary> /// <param name="textCommandController"></param> /// <param name="command">The text based command to execute.</param> /// <param name="username">A username to execute the command as.</param> /// <returns>The event generated when executing the text command.</returns> protected static ICommandResult ExecuteTextCommand(TextCommandController textCommandController, String command, String username = "******") { ICommandResult result = textCommandController.TextCommandsExecute(new Command() { Authentication = { Username = "******" }, Origin = CommandOrigin.Local }, new Dictionary<String, ICommandParameter>() { {"text", new CommandParameter() { Data = { Content = new List<string>() { command } } }} }); return result; }
protected TextCommandController CreateTextCommandController() { var security = (SecurityController)new SecurityController().Execute(); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAddGroup, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityGroupAddAccount, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "GroupName", "Phogue" }) }); security.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.SecurityAccountAddPlayer, Parameters = TestHelpers.ObjectListToContentList(new List<Object>() { "Phogue", CommonProtocolType.DiceBattlefield3, "EA_63A9F96745B22DFB509C558FC8B5C50F" }) }); var textCommandController = new TextCommandController() { Shared = { Security = security }, //Languages = languages, Connection = new ConnectionController() { Protocol = new SandboxProtocolController() { SandboxedProtocol = new MockProtocol() { Additional = "", Password = "" } }, ConnectionModel = { ProtocolType = new ProtocolType() { Name = CommonProtocolType.DiceBattlefield3, Provider = "Myrcon", Type = CommonProtocolType.DiceBattlefield3 } } } }; textCommandController.Execute(); textCommandController.TextCommands.AddRange(new List<TextCommandModel>() { TextCommandKick, TextCommandChangeMap, TextCommandCalculate, TextCommandTest }); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerPhogue.Uid, PlayerPhogue); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerImisnew2.Uid, PlayerImisnew2); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerPhilK.Uid, PlayerPhilK); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerMorpheus.Uid, PlayerMorpheus); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerIke.Uid, PlayerIke); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerPapaCharlie9.Uid, PlayerPapaCharlie9); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerEBassie.Uid, PlayerEBassie); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerZaeed.Uid, PlayerZaeed); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerPhogueIsAButterfly.Uid, PlayerPhogueIsAButterfly); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerSayaNishino.Uid, PlayerSayaNishino); textCommandController.Connection.ProtocolState.Players.TryAdd(PlayerMrDiacritic.Uid, PlayerMrDiacritic); textCommandController.Connection.ProtocolState.Items = new ConcurrentDictionary<String, ItemModel>(textCommandController.Connection.ProtocolState.Players.Values.SelectMany(player => player.Inventory.Now.Items).ToDictionary(i => i.Name, i => i)); textCommandController.Connection.ProtocolState.MapPool.TryAdd(String.Format("{0}/{1}", MapPortValdez.GameMode.Name, MapPortValdez.Name), MapPortValdez); textCommandController.Connection.ProtocolState.MapPool.TryAdd(String.Format("{0}/{1}", MapValparaiso.GameMode.Name, MapValparaiso.Name), MapValparaiso); textCommandController.Connection.ProtocolState.MapPool.TryAdd(String.Format("{0}/{1}", MapPanamaCanal.GameMode.Name, MapPanamaCanal.Name), MapPanamaCanal); return textCommandController; }