当前位置: 首页>>代码示例>>C#>>正文


C# MainWindowViewModel.CreateNewService方法代码示例

本文整理汇总了C#中MainWindowViewModel.CreateNewService方法的典型用法代码示例。如果您正苦于以下问题:C# MainWindowViewModel.CreateNewService方法的具体用法?C# MainWindowViewModel.CreateNewService怎么用?C# MainWindowViewModel.CreateNewService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MainWindowViewModel的用法示例。


在下文中一共展示了MainWindowViewModel.CreateNewService方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateViewModelWithGraph001

        internal static MainWindowViewModel CreateViewModelWithGraph001()
        {
            /** Imagine a graph like this:
             *                 +RUNNING-+                              +--------+
             *     +---------->|ServiceA+-------+   *----------------->|ServiceB|
             *     |           +---+----+       |   | Need Running     +---+----+
             *     |               |            |   |                      |
             *     |               |            |   |                      |
             *     |               |            |   |                      |
             *     |               |            |   |                      |
             * +---+-----+     +---+-----+  +RUNNING*-+                +---+-----+
             * |ServiceAx|     |PluginA-1|  |PluginA-2|                |PluginB-1|
             * +----+----+     +---------+  +---------+                +---------+
             *      |
             *      |
             * +----+-----+    +----------------------+
             * |PluginAx-1|    |Plugin.Without.Service|
             * +----------+    +----------------------+
             */
            MainWindowViewModel vm = new MainWindowViewModel();

            Assert.That( vm.LabState.Engine.IsRunning, Is.False );

            // Services
            IServiceInfo serviceA = vm.CreateNewService( "ServiceA" );

            Assert.That( vm.ServiceInfos.Contains( serviceA ) );
            Assert.That( vm.ServiceInfos.Count == 1 );
            Assert.That( vm.LabState.LabServiceInfos.Count == 1 );
            Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceA ).Count() == 1 );

            LabServiceInfo labServiceA = vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceA ).First();

            IServiceInfo serviceB = vm.CreateNewService( "ServiceB" );

            Assert.That( vm.ServiceInfos.Contains( serviceB ) );
            Assert.That( vm.ServiceInfos.Count == 2 );
            Assert.That( vm.LabState.LabServiceInfos.Count == 2 );
            Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceB ).Count() == 1 );

            IServiceInfo serviceAx = vm.CreateNewService( "ServiceAx", serviceA );

            Assert.That( vm.ServiceInfos.Contains( serviceAx ) );
            Assert.That( vm.ServiceInfos.Count == 3 );
            Assert.That( vm.LabState.LabServiceInfos.Count == 3 );
            Assert.That( vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceAx ).Count() == 1 );

            LabServiceInfo labServiceAx = vm.LabState.LabServiceInfos.Where( x => x.ServiceInfo == serviceAx ).First();

            Assert.That( labServiceAx.ServiceInfo.Generalization == labServiceA.ServiceInfo );

            Assert.That( serviceA.Generalization == null );
            Assert.That( serviceB.Generalization == null );
            Assert.That( serviceAx.Generalization == serviceA );

            // Plugins
            IPluginInfo pluginWithoutService = vm.CreateNewPlugin( "Plugin.Without.Service" );

            IPluginInfo pluginA1 = vm.CreateNewPlugin( "Plugin.A1", serviceA );

            IPluginInfo pluginA2 = vm.CreateNewPlugin( "Plugin.A2", serviceA );

            IPluginInfo pluginAx1 = vm.CreateNewPlugin( "Plugin.Ax1", serviceAx );

            IPluginInfo pluginB1 = vm.CreateNewPlugin( "Plugin.B1", serviceB );

            vm.SetPluginDependency( pluginA2, serviceB, DependencyRequirement.Running );

            Assert.That( pluginA2.ServiceReferences.Count == 1 );
            Assert.That( pluginA2.ServiceReferences[0].Reference == serviceB );
            Assert.That( pluginA2.ServiceReferences[0].Requirement == DependencyRequirement.Running );

            Assert.That( serviceA.Implementations.Count == 2 );
            Assert.That( serviceB.Implementations.Count == 1 );
            Assert.That( serviceAx.Implementations.Count == 1 );

            // Set configuration
            var cLayer1 = vm.LabState.Engine.Configuration.Layers.Create( "Test layer" );
            var result = cLayer1.Items.Add( serviceA.ServiceFullName, ConfigurationStatus.Running, "Test reason" );
            Assert.That( result.Success );

            var cLayer2 = vm.LabState.Engine.Configuration.Layers.Create( "Test layer 2" );
            result = cLayer2.Items.Add( pluginA2.PluginFullName, ConfigurationStatus.Running, "Test reason 2" );
            Assert.That( result.Success );

            // Testing tests
            foreach( var si in vm.ServiceInfos )
            {
                EquivalenceExtensions.AssertServiceEquivalence( si, si, true );
            }
            foreach( var pi in vm.PluginInfos )
            {
                EquivalenceExtensions.AssertPluginEquivalence( pi, pi, true );
            }

            EquivalenceExtensions.AssertManagerEquivalence( vm.LabState.Engine.Configuration, vm.LabState.Engine.Configuration );

            return vm;
        }
开发者ID:julien-moreau,项目名称:yodii,代码行数:99,代码来源:MainWindowViewModelTests.cs


注:本文中的MainWindowViewModel.CreateNewService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。