示例#1
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"));
        }
示例#2
0
        private void LoadPluginTiles(Type pluginType, AppDashPlugin pluginInstance)
        {
            var pluginTileTypes = pluginType.Assembly.GetTypes().Where(type =>
                                                                       (type.BaseType?.BaseType?.IsGenericType ?? false) &&
                                                                       type.BaseType?.BaseType?.GetGenericTypeDefinition() == typeof(PluginTile <,>) &&
                                                                       type.BaseType?.GenericTypeArguments[0] == pluginType &&
                                                                       type.GetCustomAttribute <FactoryTileAttribute>() == null);

            foreach (Type tileType in pluginTileTypes)
            {
                string tileKey = GetTileKey(tileType) ?? InsertTileKey(tileType);

                _pluginResolver.LoadPluginTile(pluginType, tileType, tileKey);
            }

            var tileFactoryTypes = pluginType.Assembly.GetTypes().Where(type =>
                                                                        type.GetInterfaces().FirstOrDefault(i =>
                                                                                                            i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ITileFactory <>))
                                                                        ?.GenericTypeArguments[0] == pluginType);

            foreach (Type tileFactoryType in tileFactoryTypes)
            {
                var tileFactory = Activator.CreateInstance(tileFactoryType);

                var method = tileFactoryType.GetMethod("GetTiles");

                var tiles = ((IEnumerable <ITile>)method.Invoke(tileFactory, new[] { pluginInstance })).ToList();

                for (int i = 0; i < tiles.Count; i++)
                {
                    var tileType = tiles[i].GetType();

                    string tileKey = GetTileKey(tileType, tileFactoryType.FullName, i) ?? InsertTileKey(tileType, tileFactoryType.FullName, i);

                    _pluginResolver.LoadPluginTile(pluginType, tiles[i], tileKey);
                }
            }
        }
示例#3
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);
        }