Example #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);
        }
Example #2
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);
        }
Example #3
0
        public IEnumerable <PluginTileComponent> LoadTiles(Assembly assembly, List <Tuple <string, Type> > tileKeys)
        {
            var tileTypes = assembly.GetTypes().Where(type => type.BaseType == typeof(PluginTileComponent)).ToList();

            foreach (Type tileType in tileTypes)
            {
                var tileKeys2 = tileKeys.Where(e => e.Item2 == tileType).ToList();

                foreach (Tuple <string, Type> tileKey in tileKeys2)
                {
                    tileKeys.Remove(tileKey);

                    Console.WriteLine($"Loaded tile: {tileKey.Item2.Name} {tileKey.Item1}");

                    yield return(_pluginResolver.LoadPluginTileComponent(tileType, tileKey.Item1));
                }
            }
        }
Example #4
0
        public void LoadPluginTileComponentTest()
        {
            //Arrange
            PluginResolver pluginResolver = new PluginResolver();

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

            //Act
            pluginResolver.LoadPluginTileComponent(typeof(TestTileComponent), "TestTileKey");

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

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

            //make sure the tile component is not null
            Assert.NotNull(plugin.PluginTiles["TestTileKey"].Item2);
            //we only load the component so the ITile SHOULD be null
            Assert.Null(plugin.PluginTiles["TestTileKey"].Item1);
            Assert.Equal("TestTileKey", plugin.PluginTiles["TestTileKey"].Item2.TileKey);
            Assert.Equal("TestKey", plugin.PluginTiles["TestTileKey"].Item2.PluginKey);
        }