Ejemplo n.º 1
0
        public void SetPluginTileComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginTileComponent(typeof(TestTileComponent), "TestTileKey");

            var oldComponent = pluginResolver.GetPluginTileComponent("TestKey", "TestTileKey");

            oldComponent.Data           = new PluginData();
            oldComponent.PluginSettings = new PluginData();

            var newComponent = new TestTileComponent();

            //Act
            pluginResolver.SetPluginTileComponent("TestTileKey", newComponent);

            //Assert
            Assert.NotEqual(oldComponent, pluginResolver.GetPluginTileComponent("TestKey", "TestTileKey"));
            Assert.Equal(newComponent, pluginResolver.GetPluginTileComponent("TestKey", "TestTileKey"));
            Assert.Equal("TestKey", newComponent.PluginKey);
            Assert.Equal("TestTileKey", newComponent.TileKey);
            Assert.NotNull(newComponent.Data);
            Assert.NotNull(newComponent.PluginSettings);
        }
Ejemplo n.º 2
0
        public void LoadPlugins(Assembly assembly, Dictionary <string, string> pluginKeys)
        {
            var pluginTypes = assembly.GetTypes().Where(type => type.BaseType == typeof(AppDashPlugin)).ToList();

            foreach (Type pluginType in pluginTypes)
            {
                var pluginKey = pluginKeys.FirstOrDefault(e => e.Value == pluginType.Name).Key;

                var plugin = _pluginResolver.AddPlugin(pluginType, pluginKey);

                Console.WriteLine($"{plugin.PluginInstance.Name} set key to {pluginKey}");
            }
        }
Ejemplo n.º 3
0
        public void GetSettingsTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginSettings(typeof(TestPlugin.TestPlugin));

            //Act
            var settings = pluginResolver.GetSettings("TestKey");

            //Assert
            Assert.NotNull(settings);
        }
Ejemplo n.º 4
0
        public void GetSettingComponentsTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginSettingsComponent(typeof(TestSettingsComponent), null);

            //Act
            var settingsComponents = pluginResolver.GetSettingComponents().ToList();

            //Assert
            Assert.NotNull(settingsComponents);
            Assert.Single(settingsComponents);
        }
Ejemplo n.º 5
0
        public void GetMainPageTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginPageComponent(typeof(TestPageComponent));
            pluginResolver.LoadPluginPageComponent(typeof(MainTestPageComponent));

            //Act
            var mainPage = pluginResolver.GetMainPage(typeof(TestPlugin.TestPlugin));

            //Assert
            Assert.NotNull(mainPage);
            Assert.Equal(typeof(MainTestPageComponent), mainPage.GetType());
        }
Ejemplo n.º 6
0
        public void LoadPluginSettingsComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginSettingsComponent(typeof(TestSettingsComponent), null);

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.NotNull(plugin.PluginSettingsComponent);
            Assert.Equal(typeof(TestSettingsComponent), plugin.PluginSettingsComponent.GetType());
        }
Ejemplo n.º 7
0
        private void LoadAppDashPlugins(Assembly assembly)
        {
            var pluginTypes = assembly.GetTypes().Where(type => type.BaseType == typeof(AppDashPlugin)).ToList();

            foreach (Type pluginType in pluginTypes)
            {
                string pluginKey = GetPluginKey(pluginType) ?? InsertPluginKey(pluginType);

                var plugin = _pluginResolver.AddPlugin(pluginType, pluginKey);

                LoadPluginPages(pluginType);
                LoadPluginTiles(pluginType, plugin.PluginInstance);
                LoadPluginSettings(pluginType);
                LoadPluginControllers(pluginType);
            }
        }
Ejemplo n.º 8
0
        public void GetPluginTileComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginTileComponent(typeof(TestTileComponent), "TestTileKey");

            //Act
            var tileComponent = pluginResolver.GetPluginTileComponent("TestKey", "TestTileKey");

            //Assert
            Assert.NotNull(tileComponent);
            Assert.Equal(typeof(TestTileComponent), tileComponent.GetType());
            Assert.Equal("TestTileKey", tileComponent.TileKey);
            Assert.Equal("TestKey", tileComponent.PluginKey);
        }
Ejemplo n.º 9
0
        public void GetPageComponentsTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginPageComponent(typeof(TestPageComponent));
            pluginResolver.LoadPluginPageComponent(typeof(MainTestPageComponent));

            //Act
            var pageComponents = pluginResolver.GetPageComponents().ToList();

            //Assert
            Assert.NotNull(pageComponents);
            Assert.Equal(2, pageComponents.Count);
            Assert.Equal("TestKey", pageComponents[0].PluginKey);
            Assert.Equal("TestKey", pageComponents[1].PluginKey);
            Assert.True(pageComponents[1].IsMainPage);
        }
Ejemplo n.º 10
0
        public void GetPluginPagesTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginPages(typeof(TestPlugin.TestPlugin));

            //Act
            var pages = pluginResolver.GetPluginPages("TestKey").ToList();

            //Assert
            Assert.Equal(2, pages.Count);
            Assert.Equal(2, pages.Count(page => page.PluginKey == "TestKey"));

            //make sure the right amount of pages are in the list
            Assert.Single(pages.Where(tile => tile.GetType() == typeof(TestPage)));
            Assert.Single(pages.Where(tile => tile.GetType() == typeof(MainTestPage)));
        }
Ejemplo n.º 11
0
        public void SetPluginSettingsComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginSettingsComponent(typeof(TestSettingsComponent), null);

            var oldComponent = pluginResolver.GetSettingComponent("TestKey");

            var newComponent = new TestSettingsComponent();

            //Act
            pluginResolver.SetPluginSettingsComponent(newComponent);

            //Assert
            Assert.NotEqual(oldComponent, pluginResolver.GetSettingComponent("TestKey"));
            Assert.Equal("TestKey", newComponent.PluginKey);
        }
Ejemplo n.º 12
0
        public void GetPluginTilesTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");
            pluginResolver.LoadPluginTile(typeof(TestPlugin.TestPlugin), typeof(TestTile), "TestTileKey");
            pluginResolver.LoadPluginTile(typeof(TestPlugin.TestPlugin), typeof(TestTile2), "TestTile2Key");

            //Act
            var tiles = pluginResolver.GetPluginTiles("TestKey").ToList();

            //Assert
            Assert.Equal(2, tiles.Count);
            Assert.Equal(1, tiles.Count(tile => tile.TileKey == "TestTileKey"));
            Assert.Equal(1, tiles.Count(tile => tile.TileKey == "TestTile2Key"));

            //make sure the tiles are not null
            Assert.NotNull(tiles.First(tile => tile.TileKey == "TestTileKey"));
            Assert.NotNull(tiles.First(tile => tile.TileKey == "TestTileKey"));
        }
Ejemplo n.º 13
0
        public void LoadPluginPagesTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginPages(typeof(TestPlugin.TestPlugin));

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Equal(2, plugin.PluginPages.Count);

            //make sure the page instance is not null
            Assert.NotNull(plugin.PluginPages.First().Value.Item1);
            //we only load the IPage so the component SHOULD be null
            Assert.Null(plugin.PluginPages.First().Value.Item2);
            Assert.Equal("TestKey", plugin.PluginPages.First().Value.Item1.PluginKey);
        }
Ejemplo n.º 14
0
        public void LoadPluginPageComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginPageComponent(typeof(TestPageComponent));

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Single(plugin.PluginPages);
            Assert.True(plugin.PluginPages.ContainsKey("/test"));

            //make sure the page component is not null
            Assert.NotNull(plugin.PluginPages["/test"].Item2);
            //we only load the component so the IPage SHOULD be null
            Assert.Null(plugin.PluginPages["/test"].Item1);
            Assert.Equal("TestKey", plugin.PluginPages["/test"].Item2.PluginKey);
        }
Ejemplo n.º 15
0
        public void LoadPluginTileTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            pluginResolver.LoadPluginTile(typeof(TestPlugin.TestPlugin), typeof(TestTile), "TestTileKey");

            //Assert
            var plugin = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));

            Assert.Single(plugin.PluginTiles);
            Assert.True(plugin.PluginTiles.ContainsKey("TestTileKey"));

            //make sure the tile instance is not null
            Assert.NotNull(plugin.PluginTiles["TestTileKey"].Item1);
            //we only load the ITile so the component SHOULD be null
            Assert.Null(plugin.PluginTiles["TestTileKey"].Item2);
            Assert.Equal("TestTileKey", plugin.PluginTiles["TestTileKey"].Item1.TileKey);
            Assert.Equal("TestKey", plugin.PluginTiles["TestTileKey"].Item1.PluginKey);
        }
Ejemplo n.º 16
0
        public void GetPluginTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Act
            var plugin      = pluginResolver.GetPlugin(typeof(TestPlugin.TestPlugin));
            var pluginAgain = pluginResolver.GetPlugin("TestKey");

            //Assert
            Assert.Equal(plugin, pluginAgain);

            //make sure the plugin and PluginInstance is not null
            Assert.NotNull(plugin);
            Assert.NotNull(plugin.PluginInstance);
            //make sure the plugin has the right key
            Assert.Equal("TestKey", plugin.PluginInstance.Key);
            Assert.Equal("TestKey", pluginAgain.PluginInstance.Key);
            Assert.Equal("TestKey", plugin.PluginKey);
            Assert.Equal("TestKey", pluginAgain.PluginKey);
        }
Ejemplo n.º 17
0
        public void AddPluginTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

            //Act
            var plugin = pluginResolver.AddPlugin(typeof(TestPlugin.TestPlugin), "TestKey");

            //Assert

            //make sure the plugin and PluginInstance is not null
            Assert.NotNull(plugin);
            Assert.NotNull(plugin.PluginInstance);
            //make sure the plugin has the right key
            Assert.Equal("TestKey", plugin.PluginInstance.Key);
            Assert.Equal("TestKey", plugin.PluginKey);

            Assert.Empty(plugin.PluginControllers);
            Assert.Empty(plugin.PluginPages);
            Assert.Empty(plugin.PluginTiles);
            Assert.Null(plugin.PluginSettings);
            Assert.Null(plugin.PluginSettingsComponent);
            Assert.Equal(typeof(TestPlugin.TestPlugin), plugin.PluginType);
        }