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 InitializeDocumentationLoadTest()
        {
            lock (_documentationLoadPlugin)
            {
                while (_pluginLoaded.HasValue && !_pluginLoaded.Value)
                {
                    System.Threading.Thread.Sleep(30);
                }

                if (_pluginLoaded.HasValue && _pluginLoaded.Value)
                {
                    return;
                }

                if (_pluginLoaded == null)
                {
                    _pluginLoaded = false;
                }

                _documentationLoadPlugin = new TestPluginManager();
                _documentationLoadPlugin.AddAssembly(Assembly.GetExecutingAssembly());
                _documentationLoadPlugin.UsePlugin(typeof(DemoWebsite.Classes.PluginInitialisation));
                _documentationLoadPlugin.UsePlugin(typeof(DocumentationPlugin.PluginInitialisation));
                _documentationLoadPlugin.UsePlugin(typeof(MemoryCache.Plugin.PluginInitialisation));
                _documentationLoadPlugin.UsePlugin(typeof(ProductPlugin.PluginInitialisation));

                _documentationLoadPlugin.ConfigureServices();

                _pluginServices = new pm.PluginServices(_documentationLoadPlugin) as IPluginClassesService;
                TimeSpan docLoadTime   = new TimeSpan(0, 0, 30);
                DateTime startLoadDocs = DateTime.Now;

                while (Shared.Classes.ThreadManager.Exists(SharedPluginFeatures.Constants.DocumentationLoadThread))
                {
                    System.Threading.Thread.Sleep(100);

                    if (DateTime.Now - startLoadDocs > docLoadTime)
                    {
                        break;
                    }
                }

                Assert.IsFalse(Shared.Classes.ThreadManager.Exists(SharedPluginFeatures.Constants.DocumentationLoadThread));

                _documentationService = (IDocumentationService)_documentationLoadPlugin.GetServiceProvider()
                                        .GetService(typeof(IDocumentationService));

                Assert.IsNotNull(_documentationService);

                Assert.IsTrue(_documentationService.GetDocuments().Count > 100);
                _pluginLoaded = true;
            }

            Assert.IsNotNull(_pluginServices);
        }
        public void CreatePluginEnsureISettingsProviderRegistered()
        {
            TestLogger testLogger = new TestLogger();

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

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

                Object serviceType = pluginManager.GetServiceProvider().GetService(typeof(ISettingsProvider));
                Assert.IsNotNull(serviceType);
            }
        }
        public void CreatePluginEnsureINotificationServiceRegistered()
        {
            TestLogger testLogger = new TestLogger();

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

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

                List <INotificationService> list = pluginManager.PluginGetClasses <INotificationService>();
                Assert.AreEqual(list.Count, 1);
            }
        }
        public void CreatePluginLoadSelfFindMockPluginHelper()
        {
            TestLogger testLogger = new TestLogger();

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

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

                List <Type> classes = pluginManager.PluginGetClassTypes <MockPluginHelperClass>();
                Assert.AreEqual(classes.Count, 1);
            }
        }
        public void CreatePluginAddSinglePluginConfigureCustomServices()
        {
            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();
            }

            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");
        }
        public void ServiceConfigurationIsCalled_AfterServicesHaveBeenConfigured_ThrowsInvalidOperationException()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                MockServiceConfigurator serviceConfigurator = new MockServiceConfigurator();

                pluginManager.RegisterServiceConfigurator(serviceConfigurator);

                pluginManager.ConfigureServices();

                Assert.IsTrue(serviceConfigurator.RegisterServicesCalled);

                try
                {
                    pluginManager.RegisterServiceConfigurator(serviceConfigurator);
                }
                catch (InvalidOperationException ioe)
                {
                    Assert.AreEqual("The plugin manager has already configured its services", ioe.Message);
                    throw;
                }
            }
        }