示例#1
0
        public EventInterrupter Add(EventDispatchQuery eventDispatchQuery, OnEventInterruptCallback onInterruptPredicate)
        {
            Assert.IsFalse(_interrupterDict.ContainsKey(eventDispatchQuery));

            _interrupterDict.Add(eventDispatchQuery, onInterruptPredicate);
            return(this);
        }
示例#2
0
        public void BasicPasses()
        {
            var viewID = "viewID";
            var model  = new Model()
            {
                Name = "model1", LogicalID = new ModelIDList("lg")
            };
            var viewObj = new EmptyViewObject()
            {
                UseModel    = model,
                UseBindInfo = new ModelViewBinder.BindInfo(viewID, typeof(EmptyViewObject))
            };

            {
                var query = new EventDispatchQuery("#lg", "");
                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsTrue(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }

            {
                var query = new EventDispatchQuery("#lg", viewID);
                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsTrue(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }

            {
                var query = new EventDispatchQuery("#lg", "")
                            .AddIncludedEventType <IOnTestReciever>();

                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsFalse(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }
        }
示例#3
0
        public void UsageModelViewBinderMapPasses()
        {
            #region Construct Enviroment
            EventHandlerTypeManager.Instance.EntryEventHandlerExecuter <ITestEventHandler, int>((reciever, sender, eventData) =>
            {
                reciever.Test(sender, eventData);
            });
            var eventDispatcher = new TestEventDispatcher()
            {
                SendData = 111,
            };

            var modelID            = "Model";
            var interruptTargetID  = "Target";
            var interruptModelName = "Interrupt";

            var interruptedTargetQuery = new EventDispatchQuery(modelID, "");
            var viewBinder             = new ModelViewBinder(modelID, null
                                                             , new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
                                                             .AddControllerInfo(new ControllerInfo(TestEventName.Test, new EventHandlerSelector(ModelRelationShip.Self, "", ""))));
            var interruptBinder = new ModelViewBinder(interruptModelName, null
                                                      , new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
                                                      .AddControllerInfo(new ControllerInfo(TestEventName.Test)
                                                                         .SetInterrupt(true))
                                                      );
            var viewCreator = new DefaultViewInstanceCreator(
                (typeof(EmptyViewObject), new EmptyModelViewParamBinder())
                );
            var binderMap = new ModelViewBinderMap(viewCreator
                                                   , viewBinder
                                                   , interruptBinder)
            {
                UseEventDispatcherMap = new EventDispatcherMap(
                    eventDispatcher
                    ),
                UseEventDispatchStateMap = new EventDispatchStateMap()
                                           .AddState(EventDispatchStateName.interrupt, interruptedTargetQuery),
            };
            var binderInstanceMap = binderMap.CreateBinderInstaceMap();
            var root = new TestModel()
            {
                Name = modelID
            };

            binderInstanceMap.RootModel = root;
            #endregion

            var eventInterrupter = new EventInterrupter();
            eventInterrupter.Add(interruptedTargetQuery,
                                 (_binderInstanceMap, interruptedData) =>
            {
                var interruptModel = new Model()
                {
                    Name = interruptModelName
                };
                return(interruptModel, true);
            }
                                 );

            binderMap.UseEventInterrupter = eventInterrupter;

            Assert.IsNotNull(binderInstanceMap.UseEventDispatchStateMap);
            Assert.IsNotNull(binderInstanceMap.UseEventInterrupter);
            Assert.IsTrue(binderInstanceMap.UseEventDispatchStateMap.DoMatch <ITestEventHandler>(EventDispatchStateName.interrupt, root, null), $"イベントの割り込みテストに使用するモデル({root})が割り込み対象になっていません。EventDispatchStateMapの設定を見直してください");

            eventDispatcher.SendTo(binderInstanceMap);

            Assert.AreSame(root, root.SenderModel);
            Assert.AreEqual(eventDispatcher.SendData, root.RecievedData);

            Debug.Log($"Success to Send First Event!!");

            {//割り込み処理が実行されているか確認
                //
                var errorMessage = "イベントが送信される際に処理の割り込みが実行されていません。";
                Assert.IsTrue(binderInstanceMap.BindInstances.Any(_b => _b.Value.Model.Name == interruptModelName), errorMessage);
                var interruptBinderInstance = binderInstanceMap.BindInstances.Values.First(_b => _b.Model.Name == interruptModelName);

                Assert.IsTrue(interruptBinderInstance.HasEventInterruptedData);
                var interruptedData = interruptBinderInstance.HoldedEventInterruptedData;
                Assert.AreSame(root, interruptedData.SenderModel);
                Assert.AreEqual(eventDispatcher.SendData, interruptedData.SendEventData);
            }
            Debug.Log($"Success to Interrupt Event of RootModel!!");

            {     //割り込みが有効化されたControllerInfoが割り込みデータを元に送信できているか確認
                { //ControllerInfo#IsInterruptModeが正しく動作しているか確認するため、rootのBinderInstanceを削除する
                    root.Name = "hoge";
                    Assert.IsFalse(binderInstanceMap.BindInstances.ContainsKey(root));
                }

                root.Reset();
                eventDispatcher.SendTo(binderInstanceMap);

                Assert.AreSame(root, root.SenderModel);
                Assert.AreEqual(eventDispatcher.SendData, root.RecievedData);
            }
            Debug.Log($"Success to Send Interrupted Event!!");
        }