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 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 FindAllProvidersIncludingDocumentationPluginProvider()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                pluginManager.AddAssembly(Assembly.GetExecutingAssembly());
                IPluginClassesService pluginServices = new pm.PluginServices(pluginManager) as IPluginClassesService;

                Assert.IsNotNull(pluginServices);

                List <Type> classTypes = pluginServices.GetPluginClassTypes <ISearchKeywordProvider>();

                Assert.AreEqual(2, classTypes.Count);

                Assert.AreEqual("AspNetCore.PluginManager.Tests.Search.Mocks.MockKeywordSearchProviderA", classTypes[0].FullName);

                pluginManager.AddAssembly(typeof(DocumentationPlugin.PluginInitialisation).Assembly);

                classTypes = pluginServices.GetPluginClassTypes <ISearchKeywordProvider>();

                Assert.AreEqual(3, classTypes.Count);

                Assert.AreEqual("DocumentationPlugin.Classes.KeywordSearchProvider", classTypes[classTypes.Count - 1].FullName);
            }
        }
        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 KeywordSearchFindAllProviders()
        {
            using (TestPluginManager pluginManager = new TestPluginManager())
            {
                pluginManager.AddAssembly(Assembly.GetExecutingAssembly());
                IPluginClassesService pluginServices = new pm.PluginServices(pluginManager) as IPluginClassesService;

                Assert.IsNotNull(pluginServices);

                List <Type> classTypes = pluginServices.GetPluginClassTypes <ISearchKeywordProvider>();

                Assert.AreEqual(2, classTypes.Count);

                Assert.AreEqual("AspNetCore.PluginManager.Tests.Search.Mocks.MockKeywordSearchProviderA", classTypes[0].FullName);
            }
        }
        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");
        }