/// <summary> /// Start the that needs the service. And then stop the service. Check that the plugin is stopped. /// </summary> public void ServiceReference_Normal_MustExistAndRun_ThenStopService() { Guid id = new Guid("{4E69383E-044D-4786-9077-5F8E5B259793}"); TestBase.CopyPluginToTestDir("ServiceC.dll"); TestBase.CopyPluginToTestDir("ServiceC.Model.dll"); TestBase.CopyPluginToTestDir("PluginNeedsServiceC.dll"); PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); Action afterStart = () => { // Check if the plugin is started, and if the plugin that implement the required service is started too. Assert.IsTrue(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); Assert.IsTrue(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(_implService))); }; CheckStartAnotherStop(null, afterStart, null, afterStart, true, false, id, _implService); // Then we try to stop the plugin (the one that needs the service) _ctx.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(id, Config.ConfigUserAction.Stopped); Assert.That(PluginRunner.Apply()); Assert.IsTrue(!PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); Assert.IsTrue(!PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(_implService))); }
public void RediscoverImplementationOfAService() { Guid serviceC = new Guid("{C24EE3EA-F078-4974-A346-B34208221B35}"); Guid serviceC2 = new Guid("{1EC4980D-17F0-4DDC-86C6-631CDB69A6AD}"); TestBase.CopyPluginToTestDir("ServiceC.Model.dll"); // Service TestBase.CopyPluginToTestDir("ServiceC.dll"); // Implementation PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); RequirementLayer layer = new RequirementLayer("RunnerTest"); layer.ServiceRequirements.AddOrSet("CK.Tests.Plugin.IServiceC, ServiceC.Model", RunningRequirement.MustExistAndRun); PluginRunner.RunnerRequirements.Add(layer); Assert.That(PluginRunner.Apply()); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(serviceC))); TestBase.CopyPluginToTestDir("ServiceC.Bis.dll"); // Second Implementation PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); Assert.That(PluginRunner.IsDirty, Is.False); PluginRunner.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(serviceC, ConfigPluginStatus.Disabled); Assert.That(PluginRunner.IsDirty); Assert.That(PluginRunner.Apply()); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(serviceC2))); }
void CheckStartAnotherStop(Action beforeStart, Action afterStart, Action beforeStop, Action afterStop, bool startSucceed, bool stopSucceed, Guid idToStart, Guid idToStop) { // Set a new user action --> start plugins _ctx.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(idToStart, Config.ConfigUserAction.Started); if (beforeStart != null) { beforeStart(); } // So apply the change Assert.That(PluginRunner.Apply() == startSucceed); if (afterStart != null) { afterStart(); } // Set a new user action --> stop the plugin _ctx.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(idToStop, Config.ConfigUserAction.Stopped); if (beforeStop != null) { beforeStop(); } // So apply the change Assert.IsTrue(PluginRunner.Apply() == stopSucceed); if (afterStop != null) { afterStop(); } }
// Two plugins : 1, that requires 2 as MustExistAndRun // 1 is launched (SetAction("Started")) therefor, 2 is launched automatically // 1 is stopped (SetAction("Started")) 2 stays launched // 2 is stopped SetAction("stopped"). It should stop public void RefPluginLiveAction() { Guid id1 = new Guid("{4E69383E-044D-4786-9077-5F8E5B259793}"); //called 1 in the commentary Guid id2 = new Guid("{C24EE3EA-F078-4974-A346-B34208221B35}"); //called 2 in the commentary TestBase.CopyPluginToTestDir("ServiceC.Model.dll"); TestBase.CopyPluginToTestDir("ServiceC.dll"); TestBase.CopyPluginToTestDir("PluginNeedsServiceC.dll"); PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); PluginRunner.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(id1, ConfigUserAction.Started); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id1)), "Both should be launched as we launch 1 that needs 2"); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id2)), "Both should be launched as we launch 1 that needs 2"); PluginRunner.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(id1, ConfigUserAction.Stopped); Assert.That(PluginRunner.IsDirty); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id1)), Is.False, "The plugin should be stopped"); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id2)), Is.True, "The plugin should still be running"); PluginRunner.ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(id2, ConfigUserAction.Stopped); Assert.That(PluginRunner.IsDirty); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id2)), Is.False, "The plugin should now be stopped"); }
public bool RaiseExitApplication(bool hostShouldExit) { var e = new ApplicationExitingEventArgs(this, hostShouldExit); var before = ApplicationExiting; if (before != null) { before(this, e); } if (e.Cancel) { return(false); } _pluginRunner.Disabled = true; _pluginRunner.Apply(); var after = ApplicationExited; if (after != null) { after(this, e); } return(true); }
/// <summary> /// Start a simple plugin With SystemConf set to AutomaticStart /// Change its pluginStatus to Manual /// Apply /// Check that is has not been stopped /// </summary> public void SimplePluginStatusSwitching() { Guid id = new Guid("{EEAEC976-2AFC-4A68-BFAD-68E169677D52}"); TestBase.CopyPluginToTestDir("SimplePlugin.dll"); PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); PluginRunner.ConfigManager.SystemConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.AutomaticStart); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); PluginRunner.ConfigManager.SystemConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.Manual); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); }
/// <summary> /// Start a plugin that has a serviceRef With SystemConf set to AutomaticStart /// Change its pluginStatus to Manual /// Apply /// Check that is has not been stopped /// </summary> public void RefPluginStatusSwitching() { Guid id = new Guid("{4E69383E-044D-4786-9077-5F8E5B259793}"); TestBase.CopyPluginToTestDir("ServiceC.Model.dll"); TestBase.CopyPluginToTestDir("ServiceC.dll"); TestBase.CopyPluginToTestDir("PluginNeedsServiceC.dll"); PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); PluginRunner.ConfigManager.SystemConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.AutomaticStart); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); PluginRunner.ConfigManager.SystemConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.Manual); PluginRunner.Apply(); Assert.That(PluginRunner.IsPluginRunning(PluginRunner.Discoverer.FindPlugin(id))); }
public void UserConfigPluginStatus() { Guid id_plugin1 = new Guid("{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}"); TestBase.CopyPluginToTestDir("ServiceA.dll"); PluginRunner.Discoverer.Discover(TestBase.TestFolderDir, true); ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id_plugin1, ConfigPluginStatus.Disabled); Assert.That(PluginRunner.IsDirty, "Even if the plugin is not running, the disabled configuration is a change."); ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id_plugin1, ConfigPluginStatus.AutomaticStart); Assert.That(PluginRunner.IsDirty); Assert.That(PluginRunner.Apply()); Assert.That(!PluginRunner.IsDirty); ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id_plugin1, ConfigPluginStatus.Disabled); Assert.That(PluginRunner.IsDirty); }
void CheckStartStop(Action beforeStart, Action afterStart, Action beforeStop, Action afterStop, bool startSucceed, bool stopSucceed, params Guid[] idToStart) { // Set a new user action --> start plugins for (int i = 0; i < idToStart.Length; i++) { ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(idToStart[i], ConfigUserAction.Started); } if (beforeStart != null) { beforeStart(); } // So apply the change Assert.That(PluginRunner.Apply() == startSucceed); if (afterStart != null) { afterStart(); } // Set a new user action --> stop the plugin for (int i = 0; i < idToStart.Length; i++) { ConfigManager.UserConfiguration.LiveUserConfiguration.SetAction(idToStart[i], ConfigUserAction.Stopped); } if (beforeStop != null) { beforeStop(); } // So apply the change Assert.IsTrue(PluginRunner.Apply() == stopSucceed); if (afterStop != null) { afterStop(); } }