コード例 #1
0
        public void TestConfigSaving() {
            // A guid for this connection based on an md5 hash. If none is supplied
            // then the configs directory will have an empty guid directory name in it.
            // I added this here just so you know what's used to name the directory.
            Guid connectionGuid = MD5.Guid("not a zero guid");

            CorePluginController pluginsSaving = new CorePluginController() {
                Connection = new ConnectionController() {
                    ConnectionModel = {
                        ConnectionGuid = connectionGuid
                    }
                }
            }.Execute() as CorePluginController;

            Guid pluginGuid = pluginsSaving.LoadedPlugins.First().PluginGuid;

            // Now shut it down..
            pluginsSaving.Dispose();

            String configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", connectionGuid.ToString(), pluginGuid.ToString(), "Potato.Examples.Plugins.Configs.json");

            // See [execution path]/Configs/477b1278-7b48-f5ae-4f91-f9ba12e204e7/bf3b9c62-050a-4d25-bb2e-0bb48a394eb5/Potato.Examples.Configs.xml
            Assert.IsTrue(File.Exists(configPath));

            File.Delete(configPath);
        }
コード例 #2
0
ファイル: TestActions.cs プロジェクト: EBassie/Potato
        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());
        }
コード例 #3
0
ファイル: TestPlugins.cs プロジェクト: EBassie/Potato
        public void TestPluginsDisposed() {
            var plugins = new CorePluginController().Execute() as CorePluginController;

            // Dispose of the controller
            plugins.Dispose();

            Assert.IsNull(plugins.LoadedPlugins);
            Assert.IsNull(plugins.AppDomainSandbox);
            Assert.IsNull(plugins.PluginFactory);
        }
コード例 #4
0
ファイル: TestDatabase.cs プロジェクト: EBassie/Potato
        public void TestSavingSingleRowFromModel() {
            DatabaseController database = TestDatabase.OpenDatabaseDriver();

            // Create a new plugin controller to load up the test plugin
            CorePluginController plugins = new CorePluginController() {
                BubbleObjects = {
                    database
                }
            };

            plugins.Execute();

            // Enabling the plugin should then load up the migrations and execute them.
            // See Potato.Examples.Database.GenericEvent
            plugins.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.PluginsEnable,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            ICommandResult result = plugins.Tunnel(new Command() {
                Name = "SaveOneUser",
                // 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,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            // Test the command was successful
            Assert.AreEqual(true, result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);

            // Test that data was inserted.
            result = database.Tunnel(
                CommandBuilder.DatabaseQuery(
                new Find()
                .Collection("Potato_Example_Database_Users")
                .Limit(1)
                ).SetOrigin(CommandOrigin.Local)
            );

            Assert.AreEqual(true, result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);

            // UserModel is found in Potato.Examples.Database.UserModel. We reuse it here in the test to keep everything consistent.
            UserModel model = UserModel.FirstFromQuery(result.Now.Queries.FirstOrDefault());

            Assert.AreEqual("Phogue", model.Name);
        }
コード例 #5
0
ファイル: TestActions.cs プロジェクト: EBassie/Potato
        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());
        }
コード例 #6
0
ファイル: TestPluginConfig.cs プロジェクト: EBassie/Potato
        public void TestEnabledPluginSavedToConfig() {
            Guid connectionGuid = Guid.NewGuid();
            Guid onePluginGuid = Guid.NewGuid();
            Guid twoPluginGuid = Guid.NewGuid();

            ICorePluginController plugins = new CorePluginController() {
                Connection = new ConnectionController() {
                    ConnectionModel = new ConnectionModel() {
                        ConnectionGuid = connectionGuid
                    }
                },
                LoadedPlugins = new List<PluginModel>() {
                    new PluginModel() {
                        Name = "One",
                        IsEnabled = false,
                        PluginGuid = onePluginGuid
                    },
                    new PluginModel() {
                        Name = "Two",
                        IsEnabled = true,
                        PluginGuid = twoPluginGuid
                    }
                }
            };

            IConfig config = new Config().Create<CorePluginController>();

            plugins.WriteConfig(config);

            config.Save(this.ConfigFile);

            // Now load up the config and ensure it saved what we wanted it too.

            var loadConfig = new Config();
            loadConfig.Load(this.ConfigFile);

            var commands = loadConfig.RootOf<CorePluginController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            Assert.AreEqual("PluginsEnable", commands[0].Command.Name);
            Assert.AreEqual(connectionGuid, commands[0].Command.Scope.ConnectionGuid);
            Assert.AreEqual(twoPluginGuid, commands[0].Command.Scope.PluginGuid);
        }
コード例 #7
0
ファイル: TestDatabase.cs プロジェクト: EBassie/Potato
        public void TestSavingAndFindingSingleRowFromModel() {
            DatabaseController database = TestDatabase.OpenDatabaseDriver();

            // Create a new plugin controller to load up the test plugin
            CorePluginController plugins = new CorePluginController() {
                BubbleObjects = {
                    database
                }
            };

            plugins.Execute();

            // Enabling the plugin should then load up the migrations and execute them.
            // See Potato.Examples.Database.GenericEvent
            plugins.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.PluginsEnable,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            plugins.Tunnel(new Command() {
                Name = "SaveOneUser",
                // 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,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            ICommandResult result = plugins.Tunnel(new Command() {
                Name = "FindOneUser",
                // 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,
                Scope = {
                    PluginGuid = plugins.LoadedPlugins.First().PluginGuid
                }
            });

            // Test the command was successful
            Assert.AreEqual(true, result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("Phogue", result.Message);
        }