public void EngineUseTest() { IYodiiEngine engine = new YodiiEngine(new YodiiEngineHostMock()); Assert.Throws <ArgumentNullException>(() => engine.SetDiscoveredInfo(null)); DiscoveredInfo discoveredInfo = MockInfoFactory.CreateGraph003(); IYodiiEngineResult result = engine.SetDiscoveredInfo(discoveredInfo); Assert.That(result.Success, Is.True); Assert.That(engine.DiscoveredInfo == discoveredInfo); PluginInfo pluginA1 = discoveredInfo.FindPlugin("PluginA-1"); PluginInfo pluginA2 = discoveredInfo.FindPlugin("PluginA-2"); ServiceInfo serviceA = discoveredInfo.FindService("ServiceA"); result = engine.Start(); Assert.That(result.Success, Is.True); Assert.That(engine.LiveInfo, Is.Not.Null); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).PluginInfo, Is.EqualTo(pluginA1)); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).PluginInfo, Is.EqualTo(pluginA2)); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).ServiceInfo, Is.EqualTo(serviceA)); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).IsRunning, Is.False); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).IsRunning, Is.False); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).IsRunning, Is.False); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped)); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped)); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped)); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).Service, Is.EqualTo(engine.LiveInfo.FindService(serviceA.ServiceFullName))); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).Service, Is.EqualTo(engine.LiveInfo.FindService(serviceA.ServiceFullName))); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).Generalization, Is.Null); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional)); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional)); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional)); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable)); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable)); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable)); Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).CurrentError, Is.Null); Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).CurrentError, Is.Null); Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).DisabledReason, Is.Null); engine.Stop(); }
public static void FullStart(this YodiiEngine @this, Action <YodiiEngine, IYodiiEngineResult> tests, [CallerMemberName] string callerName = null) { IActivityMonitor m = TestHelper.ConsoleMonitor; IYodiiEngineResult result; using (m.OpenInfo().Send("FullStart for {0}.", callerName)) { using (m.OpenInfo().Send("FullStart().")) { result = @this.Start(false, false); result.Trace(m); tests(@this, result); @this.Stop(); } using (m.OpenInfo().Send("FullStart( revertServices ).")) { result = @this.Start(true, false); result.Trace(m); tests(@this, result); @this.Stop(); } using (m.OpenInfo().Send("FullStart( revertPlugins ).")) { result = @this.Start(false, true); result.Trace(m); tests(@this, result); @this.Stop(); } using (m.OpenInfo().Send("FullStart( revertServices, revertPlugins ).")) { result = @this.Start(true, true); result.Trace(m); tests(@this, result); @this.Stop(); } } }
public void EngineUseTest() { IYodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() ); Assert.Throws<ArgumentNullException>( () => engine.SetDiscoveredInfo( null ) ); DiscoveredInfo discoveredInfo = MockInfoFactory.CreateGraph003(); IYodiiEngineResult result = engine.SetDiscoveredInfo( discoveredInfo ); Assert.That( result.Success, Is.True ); Assert.That( engine.DiscoveredInfo == discoveredInfo ); PluginInfo pluginA1 = discoveredInfo.FindPlugin( "PluginA-1" ); PluginInfo pluginA2 = discoveredInfo.FindPlugin( "PluginA-2" ); ServiceInfo serviceA = discoveredInfo.FindService( "ServiceA" ); result = engine.Start(); Assert.That( result.Success, Is.True ); Assert.That( engine.LiveInfo, Is.Not.Null ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).PluginInfo, Is.EqualTo( pluginA1 ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).PluginInfo, Is.EqualTo( pluginA2 ) ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).ServiceInfo, Is.EqualTo( serviceA ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).IsRunning, Is.False ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).IsRunning, Is.False ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).IsRunning, Is.False ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).Service, Is.EqualTo( engine.LiveInfo.FindService( serviceA.ServiceFullName ) ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).Service, Is.EqualTo( engine.LiveInfo.FindService( serviceA.ServiceFullName ) ) ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).Generalization, Is.Null ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) ); Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).CurrentError, Is.Null ); Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).CurrentError, Is.Null ); Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).DisabledReason, Is.Null ); engine.Stop(); }
public void ConfigChanged() { /** * +--------+ * |ServiceA+ ------+ * | | | * +---+----+ | * | | * | | * | | * | +---+---*-+ * +---+-----+ |PluginA-2| * |PluginA-1| | | * | | +---------+ * +---------+ */ DiscoveredInfo info = MockInfoFactory.CreateGraph003(); YodiiEngine engine = new YodiiEngine(new YodiiEngineHostMock()); engine.SetDiscoveredInfo(info); engine.Start(); ILiveServiceInfo sA = engine.LiveInfo.FindService("ServiceA"); ILivePluginInfo p1 = engine.LiveInfo.FindPlugin("PluginA-1"); ILivePluginInfo p2 = engine.LiveInfo.FindPlugin("PluginA-2"); Assert.That(sA != null && p1 != null && p2 != null); Assert.That(p1.Capability.CanStart && p2.Capability.CanStart && sA.Capability.CanStart, Is.True); Assert.That(p1.Capability.CanStartWithFullStart && p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True); Assert.That(p1.Capability.CanStartWithStartRecommended && p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True); Assert.That(p1.Capability.CanStartWithStopOptionalAndRunnable && p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True); Assert.That(p1.Capability.CanStartWithFullStop && p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True); HashSet <string> propertyChanged = new HashSet <string>(); p1.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(p1)); Assert.That(propertyChanged.Add("p1." + e.PropertyName)); }; p1.Capability.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(p1.Capability)); Assert.That(propertyChanged.Add("p1.Capablity." + e.PropertyName)); }; p2.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(p2)); Assert.That(propertyChanged.Add("p2." + e.PropertyName)); }; p2.Capability.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(p2.Capability)); Assert.That(propertyChanged.Add("p2.Capablity." + e.PropertyName)); }; sA.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(sA)); Assert.That(propertyChanged.Add("sA." + e.PropertyName)); }; sA.Capability.PropertyChanged += (s, e) => { Assert.That(s, Is.SameAs(sA.Capability)); Assert.That(propertyChanged.Add("sA.Capablity." + e.PropertyName)); }; IConfigurationLayer config = engine.Configuration.Layers.Create("Default"); config.Items.Add(p1.FullName, ConfigurationStatus.Disabled); Assert.That(p1.Capability.CanStart && p1.Capability.CanStartWithFullStart && p1.Capability.CanStartWithStartRecommended && p1.Capability.CanStartWithStopOptionalAndRunnable && p1.Capability.CanStartWithFullStop, Is.False); Assert.That(p2.Capability.CanStart && sA.Capability.CanStart, Is.True); Assert.That(p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True); Assert.That(p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True); Assert.That(p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True); Assert.That(p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True); CollectionAssert.AreEquivalent(new string[] { "p1.Capablity.CanStart", "p1.Capablity.CanStartWithFullStart", "p1.Capablity.CanStartWithStartRecommended", "p1.Capablity.CanStartWithStopOptionalAndRunnable", "p1.Capablity.CanStartWithFullStop", "p1.DisabledReason", "p1.RunningStatus", "p1.ConfigOriginalStatus", "p1.WantedConfigSolvedStatus", "p1.FinalConfigSolvedStatus" }, propertyChanged); propertyChanged.Clear(); config.Items.Add(p1.FullName, ConfigurationStatus.Optional); CollectionAssert.AreEquivalent(new string[] { "p1.Capablity.CanStart", "p1.Capablity.CanStartWithFullStart", "p1.Capablity.CanStartWithStartRecommended", "p1.Capablity.CanStartWithStopOptionalAndRunnable", "p1.Capablity.CanStartWithFullStop", "p1.DisabledReason", "p1.RunningStatus", "p1.ConfigOriginalStatus", "p1.WantedConfigSolvedStatus", "p1.FinalConfigSolvedStatus" }, propertyChanged); }
public void ConfigChanged() { /** * +--------+ * |ServiceA+ ------+ * | | | * +---+----+ | * | | * | | * | | * | +---+---*-+ * +---+-----+ |PluginA-2| * |PluginA-1| | | * | | +---------+ * +---------+ */ DiscoveredInfo info = MockInfoFactory.CreateGraph003(); YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() ); engine.SetDiscoveredInfo( info ); engine.Start(); ILiveServiceInfo sA = engine.LiveInfo.FindService( "ServiceA" ); ILivePluginInfo p1 = engine.LiveInfo.FindPlugin( "PluginA-1" ); ILivePluginInfo p2 = engine.LiveInfo.FindPlugin( "PluginA-2" ); Assert.That( sA != null && p1 != null && p2 != null ); Assert.That( p1.Capability.CanStart && p2.Capability.CanStart && sA.Capability.CanStart, Is.True ); Assert.That( p1.Capability.CanStartWithFullStart && p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True ); Assert.That( p1.Capability.CanStartWithStartRecommended && p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True ); Assert.That( p1.Capability.CanStartWithStopOptionalAndRunnable && p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True ); Assert.That( p1.Capability.CanStartWithFullStop && p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True ); HashSet<string> propertyChanged = new HashSet<string>(); p1.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( p1 ) ); Assert.That( propertyChanged.Add( "p1."+e.PropertyName ) ); }; p1.Capability.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( p1.Capability ) ); Assert.That( propertyChanged.Add( "p1.Capablity."+e.PropertyName ) ); }; p2.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( p2 ) ); Assert.That( propertyChanged.Add( "p2."+e.PropertyName ) ); }; p2.Capability.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( p2.Capability ) ); Assert.That( propertyChanged.Add( "p2.Capablity."+e.PropertyName ) ); }; sA.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( sA ) ); Assert.That( propertyChanged.Add( "sA."+e.PropertyName ) ); }; sA.Capability.PropertyChanged += ( s, e ) => { Assert.That( s, Is.SameAs( sA.Capability ) ); Assert.That( propertyChanged.Add( "sA.Capablity."+e.PropertyName ) ); }; IConfigurationLayer config = engine.Configuration.Layers.Create( "Default" ); config.Items.Add( p1.FullName, ConfigurationStatus.Disabled ); Assert.That( p1.Capability.CanStart && p1.Capability.CanStartWithFullStart && p1.Capability.CanStartWithStartRecommended && p1.Capability.CanStartWithStopOptionalAndRunnable && p1.Capability.CanStartWithFullStop, Is.False ); Assert.That( p2.Capability.CanStart && sA.Capability.CanStart, Is.True ); Assert.That( p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True ); Assert.That( p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True ); Assert.That( p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True ); Assert.That( p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True ); CollectionAssert.AreEquivalent( new string[]{ "p1.Capablity.CanStart", "p1.Capablity.CanStartWithFullStart", "p1.Capablity.CanStartWithStartRecommended", "p1.Capablity.CanStartWithStopOptionalAndRunnable", "p1.Capablity.CanStartWithFullStop", "p1.DisabledReason", "p1.RunningStatus", "p1.ConfigOriginalStatus", "p1.WantedConfigSolvedStatus", "p1.FinalConfigSolvedStatus" }, propertyChanged ); propertyChanged.Clear(); config.Items.Add( p1.FullName, ConfigurationStatus.Optional ); CollectionAssert.AreEquivalent( new string[]{ "p1.Capablity.CanStart", "p1.Capablity.CanStartWithFullStart", "p1.Capablity.CanStartWithStartRecommended", "p1.Capablity.CanStartWithStopOptionalAndRunnable", "p1.Capablity.CanStartWithFullStop", "p1.DisabledReason", "p1.RunningStatus", "p1.ConfigOriginalStatus", "p1.WantedConfigSolvedStatus", "p1.FinalConfigSolvedStatus" }, propertyChanged ); }
public void SetDiscoverdInfo() { #region graph /** * +--------+ +--------+ * +---------->|ServiceA+-------+ *----------------->|ServiceB| * | |Running | | | Need ? |Running | * | +---+----+ | | +---+----+ * | | | | | * | | | | | * | | | | | * +---+-----+ | +---+---*-+ | * |ServiceAx| +---+-----+ |PluginA-2| +---+-----+ * |Optional | |PluginA-1| |Optional | |PluginB-1| * +----+----+ |Optional | +---------+ |Optional | * | +---------+ +---------+ * | * +----+-----+ * |PluginAx-1| * |Running | * +----------+ */ #endregion DiscoveredInfo info = MockInfoFactory.CreateGraph001(); info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Optional ); YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() ); engine.SetDiscoveredInfo( info ); IConfigurationLayer cl = engine.Configuration.Layers.Create(); cl.Items.Add( "ServiceB", ConfigurationStatus.Running ); cl.Items.Add( "ServiceA", ConfigurationStatus.Running ); cl.Items.Add( "PluginAx-1", ConfigurationStatus.Running ); IYodiiEngineResult res = engine.Start(); res.CheckSuccess(); info = MockInfoFactory.CreateGraph001(); info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.OptionalRecommended ); res = engine.SetDiscoveredInfo( info ); res.CheckSuccess(); info = MockInfoFactory.CreateGraph001(); info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Runnable ); res = engine.SetDiscoveredInfo( info ); res.CheckSuccess(); info = MockInfoFactory.CreateGraph001(); info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.RunnableRecommended ); res = engine.SetDiscoveredInfo( info ); res.CheckSuccess(); info = MockInfoFactory.CreateGraph001(); info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Running ); res = engine.SetDiscoveredInfo( info ); res.CheckSuccess(); }