public void TestKickPlayerAction() { // Create a new plugin controller to load up the test plugin CorePluginController plugins = new CorePluginController(); // Now setup a mock handler to accept actions from the plugin MockNetworkLayer layer = new MockNetworkLayer(); plugins.BubbleObjects.Add(layer); plugins.Execute(); // Enable the single plugin that was loaded, otherwise it won't recieve any tunneled // commands. plugins.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.PluginsEnable, Scope = { PluginGuid = plugins.LoadedPlugins.First().PluginGuid } }); ICommandResult result = plugins.Tunnel(new Command() { Name = "KickPlayer", // We're cheating a little bit here and just saying the command came from // "local" as in it was generated by Potato itself. Origin = CommandOrigin.Local }); Assert.AreEqual("KickPlayer.Result.packet: Client Request 100 [0-admin.kickPlayer] [1-Phogue]", result.Now.Content.First()); Assert.AreEqual("KickPlayer.Result.packet: Client Request 101 [0-admin.say] [1-This is a reason to kick this person] [2-player] [3-Phogue]", result.Now.Content.Last()); }
public void TestDeferredKickPlayerAction() { // Create a new plugin controller to load up the test plugin CorePluginController plugins = new CorePluginController(); // Now setup a mock handler to accept actions from the plugin MockNetworkLayer layer = new MockNetworkLayer(); plugins.BubbleObjects.Add(layer); plugins.Execute(); // Enable the single plugin that was loaded, otherwise it won't recieve any tunneled // commands. plugins.Tunnel(new Command() { Origin = CommandOrigin.Local, CommandType = CommandType.PluginsEnable, Scope = { PluginGuid = plugins.LoadedPlugins.First().PluginGuid } }); // Now finally poke the test plugin. ICommandResult result = plugins.Tunnel(new Command() { Name = "DeferredKickPlayer", // We're cheating a little bit here and just saying the command came from // "local" as in it was generated by Potato itself. Origin = CommandOrigin.Local }); // Fake client events from the networking layer. layer.Waiting.Done += (action, requests, responses) => plugins.PluginFactory.ClientEvent(new List<IClientEventArgs>() { new ClientEventArgs() { EventType = ClientEventType.ClientActionDone, ConnectionState = ConnectionState.ConnectionLoggedIn, Now = new ClientEventData() { Packets = responses }, Then = new ClientEventData() { Actions = new List<INetworkAction>() { action }, Packets = requests } } }); // Now fire off the mock responses (you'll see the above anonymous method that fires // a ClientEvent called during this method) layer.MockResponses(); Assert.AreEqual("KickPlayer.Result.packet: Client Request 100 [0-admin.kickPlayer] [1-Phogue]", result.Now.Content.First()); Assert.AreEqual("KickPlayer.Result.packet: Client Request 101 [0-admin.say] [1-This is a reason to kick this person] [2-player] [3-Phogue]", result.Now.Content.Last()); }