Пример #1
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);
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #5
0
        public async Task TryGetValues()
        {
            var driverMock = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName", DispatcherMock.Instance);

            await DispatcherMock.Instance.DispatchValue(driverMock, true);

            var values = DispatcherMock.Instance.GetValues(DispatchableType.NodeInstance);

            Assert.True(values.ContainsKey(driverMock.Id));
        }
Пример #6
0
        public async Task WriteDirect()
        {
            var driverMock = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName", DispatcherMock.Instance);

            var driverMock2 = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName2", DispatcherMock.Instance);

            await driverMock.WriteValue(driverMock2, true);

            Assert.True(driverMock.WriteReceived);
        }
Пример #7
0
        public async Task TryGetValue()
        {
            var driverMock = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName", DispatcherMock.Instance);

            await DispatcherMock.Instance.DispatchValue(driverMock, true);

            var value = DispatcherMock.Instance.GetValue(DispatchableType.NodeInstance, driverMock.Id);

            Assert.IsType <bool>(value);
            Assert.True((bool)value);
        }
Пример #8
0
        public async Task TestDispatcherClear()
        {
            var driverMock2 = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName2", DispatcherMock.Instance);

            await DispatcherMock.Instance.RegisterDispatch(DispatchableType.NodeInstance, DispatchableMock.Instance.Id, (a, b) =>
            {
                ((DriverNodeMock)driverMock2.Children[0]).WriteValue(a, b);
            });

            await DispatcherMock.Instance.ClearRegistrations();

            await DispatcherMock.Instance.DispatchValue(DispatchableMock.Instance, true);



            Assert.False(((DriverNodeMock)driverMock2.Children[0]).WriteReceived);
        }
Пример #9
0
        public async Task WriteDispatcher()
        {
            var driverMock = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName", DispatcherMock.Instance);

            var driverMock2 = await DispatcherHelperUtils.CreateNodeMock(Guid.NewGuid(), "MockName2", DispatcherMock.Instance);

            await DispatcherMock.Instance.RegisterDispatch(DispatchableType.NodeInstance, driverMock.Id, (a, b) =>
            {
                ((DriverNodeMock)driverMock2.Children[0]).WriteValue(a, b);
            });

            await DispatcherMock.Instance.DispatchValue(driverMock, true);

            await Task.Delay(200);

            Assert.True(((DriverNodeMock)driverMock2.Children[0]).WriteReceived);
        }