public void CreateTestExtensionShouldCreateExtensionTypeInstance() { var instance = TestPluginManager.CreateTestExtension <ITestDiscoverer>(typeof(DummyTestDiscoverer)); Assert.IsNotNull(instance); Assert.IsTrue(instance is ITestDiscoverer); }
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 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 AddNullServiceConfiguration_ThrowsArgumentNullException() { using (TestPluginManager pluginManager = new TestPluginManager()) { pluginManager.RegisterServiceConfigurator(null); } }
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 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 CreatePluginManagerAddNoPlugins() { TestLogger testLogger = new TestLogger(); using (TestPluginManager pluginManager = new TestPluginManager(testLogger)) { Assert.AreEqual(pluginManager.PluginsGetLoaded().Count, 1); } Assert.AreEqual(testLogger.Logs[0].LogLevel, LogLevel.PluginLoadSuccess); Assert.AreEqual(testLogger.Logs[1].LogLevel, LogLevel.PluginConfigureError); }
public void CreatePluginValidateRootPath() { TestLogger testLogger = new TestLogger(); using (TestPluginManager pluginManager = new TestPluginManager(testLogger)) { string root = pluginManager.Path(); Assert.IsFalse(String.IsNullOrWhiteSpace(root)); string executingAssemblyPath = Assembly.GetExecutingAssembly().Location; Assert.IsTrue(executingAssemblyPath.StartsWith(root, StringComparison.InvariantCultureIgnoreCase)); } }
public void FindAllILoggerClassTypes() { using (TestPluginManager pluginManager = new TestPluginManager()) { IPluginClassesService pluginServices = new PluginServices(pluginManager) as IPluginClassesService; Assert.IsNotNull(pluginServices); List <Type> classTypes = pluginServices.GetPluginClassTypes <ILogger>(); Assert.AreEqual(classTypes.Count, 1); Assert.AreEqual(classTypes[0].FullName, "PluginManager.Internal.DefaultLogger"); } }
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 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 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 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 AddTwoIServiceConfiguration_ThrowsInvalidOperationException() { using (TestPluginManager pluginManager = new TestPluginManager()) { MockServiceConfigurator serviceConfigurator = new MockServiceConfigurator(); pluginManager.RegisterServiceConfigurator(serviceConfigurator); try { pluginManager.RegisterServiceConfigurator(serviceConfigurator); } catch (InvalidOperationException ioe) { Assert.AreEqual("Only one IServiceConfigurator can be loaded", ioe.Message); throw; } } }
public void TestAddAssembly() { using (TestPluginManager pluginManager = new TestPluginManager()) { IPluginHelperService pluginServices = new PluginServices(pluginManager) as IPluginHelperService; Assert.IsNotNull(pluginServices); Assembly current = Assembly.GetExecutingAssembly(); DynamicLoadResult loadResult = pluginServices.AddAssembly(current); Assert.IsTrue(loadResult == DynamicLoadResult.Success); pluginServices.PluginLoaded(System.IO.Path.GetFileName(current.Location), out int version); Assert.IsTrue(version == 1); } }
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 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; } } }
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 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 CreateTestExtensionShouldThrowIfInstanceCannotBeCreated() { Assert.ThrowsException <MissingMethodException>(() => TestPluginManager.CreateTestExtension <ITestLogger>(typeof(AbstractDummyLogger))); }
public void GetTestExtensionTypeShouldThrowIfTypeNotFound() { Assert.ThrowsException <TypeLoadException>(() => TestPluginManager.GetTestExtensionType("randomassemblyname.random")); }
public void GetTestExtensionTypeShouldReturnExtensionType() { var type = TestPluginManager.GetTestExtensionType(typeof(TestPluginManagerTests).AssemblyQualifiedName); Assert.AreEqual(typeof(TestPluginManagerTests), type); }