public void CreatePluginAddSinglePluginConfigureCustomServicesGetPluginClass()
        {
            TestLogger testLogger = new TestLogger();

            using (TestPluginManager pluginManager = new TestPluginManager(testLogger))
            {
                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1);

                pluginManager.PluginLoad("..\\..\\..\\..\\..\\Plugins\\BadEgg.Plugin\\bin\\Debug\\netcoreapp3.1\\BadEgg.Plugin.dll", false);

                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 2);

                pluginManager.AddAssembly(Assembly.GetExecutingAssembly());
                pluginManager.ConfigureServices();

                // using inbuild DI container, create a mock instance
                List <MockPluginHelperClass> mockPluginHelpers = pluginManager.PluginGetClasses <MockPluginHelperClass>();

                Assert.IsNotNull(mockPluginHelpers);

                Assert.AreNotEqual(mockPluginHelpers.Count, 0);
            }

            Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError);
            Assert.AreEqual(testLogger.Logs[2].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[2].Data, "BadEgg.Plugin.dll");
        }
        public void CreatePluginAddSinglePluginConfigureCustomServicesCreateInstanceOf()
        {
            TestLogger testLogger = new TestLogger();

            using (TestPluginManager pluginManager = new TestPluginManager(testLogger))
            {
                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1);

                pluginManager.PluginLoad("..\\..\\..\\..\\..\\Plugins\\BadEgg.Plugin\\bin\\Debug\\netcoreapp3.1\\BadEgg.Plugin.dll", false);

                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 2);

                pluginManager.ConfigureServices();

                // using inbuild DI container, create a mock instance
                MockPluginHelperClass mockPluginHelper = (MockPluginHelperClass)Activator.CreateInstance(
                    typeof(MockPluginHelperClass),
                    pluginManager.GetParameterInstances(typeof(MockPluginHelperClass)));

                Assert.IsNotNull(mockPluginHelper);
            }

            Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError);
            Assert.AreEqual(testLogger.Logs[2].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[2].Data, "BadEgg.Plugin.dll");
        }
        public void FindTestLoggerClassTypeInstancesAddLogAndVerify()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                pluginManager.PluginLoad(Assembly.GetExecutingAssembly(), String.Empty, false);
                IPluginClassesService pluginServices = new PluginServices(pluginManager) as IPluginClassesService;

                Assert.IsNotNull(pluginServices);

                List <ILogger> classTypes = pluginServices.GetPluginClasses <ILogger>();

                Assert.AreEqual(classTypes.Count, 2);

                Assert.AreEqual(classTypes[1].GetType().FullName, "PluginManager.Tests.Mocks.TestLogger");

                TestLogger testLogger = classTypes[1] as TestLogger;

                Assert.IsNotNull(testLogger);

                testLogger.AddToLog(LogLevel.Information, "test");

                Assert.AreEqual(testLogger.Logs[0].Data, "test");
                Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.Information);
            }
        }
        public void FindTestLoggerClassTypeInstances()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                pluginManager.PluginLoad(Assembly.GetExecutingAssembly(), String.Empty, false);
                IPluginClassesService pluginServices = new PluginServices(pluginManager) as IPluginClassesService;

                Assert.IsNotNull(pluginServices);

                List <ILogger> classTypes = pluginServices.GetPluginClasses <ILogger>();

                Assert.AreEqual(classTypes.Count, 2);

                Assert.AreEqual(classTypes[1].GetType().FullName, "PluginManager.Tests.Mocks.TestLogger");
            }
        }
        public void CreatePluginManagerAddSinglePlugin()
        {
            TestLogger testLogger = new TestLogger();

            using (TestPluginManager pluginManager = new TestPluginManager(testLogger))
            {
                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1);

                pluginManager.PluginLoad("..\\..\\..\\..\\..\\Plugins\\BadEgg.Plugin\\bin\\Debug\\netcoreapp3.1\\BadEgg.Plugin.dll", false);

                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 2);
            }

            Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError);
            Assert.AreEqual(testLogger.Logs[2].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[2].Data, "BadEgg.Plugin.dll");
        }
        public void CreatePluginManagerAddSinglePluginGetSettingRangeAttributeClasses()
        {
            TestLogger testLogger = new TestLogger();

            using (TestPluginManager pluginManager = new TestPluginManager(testLogger))
            {
                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1);

                pluginManager.PluginLoad("..\\..\\..\\..\\..\\Plugins\\BadEgg.Plugin\\bin\\Debug\\netcoreapp3.1\\BadEgg.Plugin.dll", false);

                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 2);

                List <Type> list = pluginManager.PluginGetTypesWithAttribute <SettingRangeAttribute>();

                Assert.AreNotEqual(list.Count, 0);
            }

            Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError);
            Assert.AreEqual(testLogger.Logs[2].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[2].Data, "BadEgg.Plugin.dll");
        }
        public void CreatePluginAddSinglePluginensureItIsLoaded()
        {
            TestLogger testLogger = new TestLogger();

            using (TestPluginManager pluginManager = new TestPluginManager(testLogger))
            {
                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1);

                pluginManager.PluginLoad("..\\..\\..\\..\\..\\Plugins\\BadEgg.Plugin\\bin\\Debug\\netcoreapp3.1\\BadEgg.Plugin.dll", false);

                Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 2);

                pluginManager.AddAssembly(Assembly.GetExecutingAssembly());
                pluginManager.ConfigureServices();

                Assert.IsTrue(pluginManager.PluginLoaded("BadEgg.Plugin.dll", out int _, out string _));
            }

            Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError);
            Assert.AreEqual(testLogger.Logs[2].LogLevel, LogLevel.PluginLoadSuccess);
            Assert.AreEqual(testLogger.Logs[2].Data, "BadEgg.Plugin.dll");
        }