Ejemplo n.º 1
0
        public async Task TestNode2RuleDispatch()
        {
            var source = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Source", Dispatcher,
                                                                    NodeInstanceCache, DriverNodesStore);

            var target = await DispatcherHelperUtils.CreateLogicMock("Target", Dispatcher, null,
                                                                     LogicInterfaceInstanceCache, LogicInstancesStore);

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance()
                {
                    ObjId = target.Context.RuleInstance.RuleInterfaceInstance
                            .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input").ObjId,
                    This2RuleInstance = target.Context.RuleInstance.RuleInterfaceInstance
                                        .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input").This2RuleInstance
                };
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance = source.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(source.Children[0], true);

            await Task.Delay(200);

            Assert.True(target.WriteReceived);
            var value = Dispatcher.GetValue(DispatchableType.NodeInstance, source.Children[0].Id);

            Assert.IsType <bool>(value);
            Assert.True((bool)value);
        }
Ejemplo n.º 2
0
        public async Task TestNode2NodeDispatch()
        {
            var source = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Source", Dispatcher,
                                                                    NodeInstanceCache, DriverNodesStore);

            var target = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Target", Dispatcher,
                                                                    NodeInstanceCache, DriverNodesStore);

            CreateLink(a =>
            {
                a.This2NodeInstance2RulePageInputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance = target.Children[0].DriverContext.NodeInstance.ObjId
                };
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance = source.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(source.Children[0], true);

            await Task.Delay(200);

            Assert.True(((DriverNodeMock)target.Children[0]).WriteReceived);
            var value = Dispatcher.GetValue(DispatchableType.NodeInstance, source.Children[0].Id);

            Assert.IsType <bool>(value);
            Assert.True((bool)value);
        }
Ejemplo n.º 3
0
        public async Task TestLoopNode2Rule()
        {
            var source = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Source", Dispatcher, NodeInstanceCache, DriverNodesStore);

            var target = await DispatcherHelperUtils.CreateLogicMock("Target", Dispatcher, null, LogicInterfaceInstanceCache, LogicInstancesStore);

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = target.Context.RuleInstance.RuleInterfaceInstance.Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input").ObjId
                };
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance = source.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceOutputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = target.Context.RuleInstance.RuleInterfaceInstance
                                        .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Output").ObjId
                };
                a.This2NodeInstance2RulePageInputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance = source.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(source.Children[0], true);
        }
Ejemplo n.º 4
0
        public async Task TestLoopNodes()
        {
            var source = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Source", Dispatcher,
                                                                    NodeInstanceCache, DriverNodesStore);

            var target = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Target", Dispatcher,
                                                                    NodeInstanceCache, DriverNodesStore);

            var target2 = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "Target_Loop_Back", Dispatcher,
                                                                     NodeInstanceCache, DriverNodesStore);

            CreateLink(a =>
            {
                a.This2NodeInstance2RulePageInputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        target.Children[0].DriverContext.NodeInstance.ObjId
                }
                ;
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        source.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            CreateLink(a =>
            {
                a.This2NodeInstance2RulePageInputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        target2.Children[0].DriverContext.NodeInstance.ObjId
                };
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        target.Children[0].DriverContext.NodeInstance.ObjId
                };
            });
            CreateLink(a =>
            {
                a.This2NodeInstance2RulePageInputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        source.Children[0].DriverContext.NodeInstance.ObjId
                };
                a.This2NodeInstance2RulePageOutputNavigation = new NodeInstance2RulePage
                {
                    This2NodeInstance =
                        target2.Children[0].DriverContext.NodeInstance.ObjId
                };
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(source.Children[0], true);
        }
Ejemplo n.º 5
0
        public async Task TestRule2RuleDispatch()
        {
            var source = await DispatcherHelperUtils.CreateLogicMock("Source", Dispatcher, null,
                                                                     LogicInterfaceInstanceCache, LogicInstancesStore);

            var target = await DispatcherHelperUtils.CreateLogicMock("Target", Dispatcher, null,
                                                                     LogicInterfaceInstanceCache, LogicInstancesStore);

            var outputInterface = source.Context.RuleInstance.RuleInterfaceInstance
                                  .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Output");
            var inputInterface = target.Context.RuleInstance.RuleInterfaceInstance
                                 .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input");

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance()
                {
                    This2RuleInstance = inputInterface.ObjId
                };
                a.This2RuleInterfaceInstanceInput            = inputInterface.ObjId;
                a.This2RuleInterfaceInstanceOutputNavigation = new RuleInterfaceInstance()
                {
                    This2RuleInstance = outputInterface.ObjId
                };
                a.This2RuleInterfaceInstanceOutput = outputInterface.ObjId;
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(new RuleInterfaceInstanceDispatchable(outputInterface), true);

            await Task.Delay(200);

            Assert.True(target.WriteReceived);
            var value = Dispatcher.GetValue(DispatchableType.RuleInstance, outputInterface.ObjId);

            Assert.IsType <bool>(value);
            Assert.True((bool)value);
        }
Ejemplo n.º 6
0
        public async Task TestLoopRules()
        {
            var source = await DispatcherHelperUtils.CreateLogicMock("Source", Dispatcher, null, LogicInterfaceInstanceCache, LogicInstancesStore);

            var target = await DispatcherHelperUtils.CreateLogicMock("Target", Dispatcher, null, LogicInterfaceInstanceCache, LogicInstancesStore);

            var target2 = await DispatcherHelperUtils.CreateLogicMock("Target_Loop_Back", Dispatcher, null, LogicInterfaceInstanceCache, LogicInstancesStore);

            var inputInterfaceSource = source.Context.RuleInstance.RuleInterfaceInstance
                                       .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input");
            var outputInterface = source.Context.RuleInstance.RuleInterfaceInstance
                                  .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Output");

            var inputInterface = target.Context.RuleInstance.RuleInterfaceInstance
                                 .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input");
            var outputInterface2 = target.Context.RuleInstance.RuleInterfaceInstance
                                   .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Output");

            var inputInterfaceLoop = target2.Context.RuleInstance.RuleInterfaceInstance
                                     .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Input");
            var outputInterfaceLoop = target2.Context.RuleInstance.RuleInterfaceInstance
                                      .Single(b => b.This2RuleInterfaceTemplateNavigation.Name == "Output");

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = inputInterface.ObjId
                };
                a.This2RuleInterfaceInstanceOutputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = outputInterface.ObjId
                };
            });

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = inputInterfaceLoop.ObjId
                };
                a.This2RuleInterfaceInstanceOutputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = outputInterface2.ObjId
                };
            });

            CreateLink(a =>
            {
                a.This2RuleInterfaceInstanceInputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = inputInterfaceSource.ObjId
                };
                a.This2RuleInterfaceInstanceOutputNavigation = new RuleInterfaceInstance
                {
                    This2RuleInstance = outputInterfaceLoop.ObjId
                };
            });

            RuleEngineDispatcher.Load();

            await Dispatcher.DispatchValue(new RuleInterfaceInstanceDispatchable(outputInterface), true);
        }